Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix up to level 3
James Colec0cc89610239
diff --git a/.ci/phpmd/phpmd.xml b/.ci/phpmd/phpmd.xmlindex be299fb568..38146de2ba 100644--- a/.ci/phpmd/phpmd.xml+++ b/.ci/phpmd/phpmd.xml@@ -19,12 +19,12 @@~ along with this program. If not, see <https://www.gnu.org/licenses/>.-->-<ruleset name="pcsg-generated-ruleset"- xmlns="http://pmd.sf.net/ruleset/1.0.0"- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"- xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"- xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">- <description>Bla bla</description>+<ruleset name="Firefly III ruleset"+ xmlns="http://pmd.sf.net/ruleset/1.0.0"+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"+ xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">+ <description>Firefly III ruleset</description><!--Commando vanuit firefly directory:@@ -37,8 +37,7 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r</rule><!-- clean code -->- <rule ref="rulesets/codesize.xml" />- <rule ref="rulesets/design.xml" />+ <rule ref="rulesets/design.xml/" /><rule ref="rulesets/naming.xml" /><rule ref="rulesets/unusedcode.xml" />@@ -51,7 +50,7 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r<rule ref="rulesets/codesize.xml/NPathComplexity"><properties><!-- TODO we want to be at a value of 128. But we start high, and drop the bar slowly. -->- <property name="minimum" value="2048"/>+ <property name="minimum" value="99000"/></properties></rule><rule ref="rulesets/codesize.xml/ExcessiveMethodLength">diff --git a/.ci/phpstan.neon b/.ci/phpstan.neonindex 2f266733a7..199e3e3962 100644--- a/.ci/phpstan.neon+++ b/.ci/phpstan.neon@@ -1,9 +1,11 @@parameters:universalObjectCratesClasses:- Illuminate\Database\Eloquent\Model+ # TODO: slowly remove these parameters and fix the issues found.reportUnmatchedIgnoredErrors: falsecheckGenericClassInNonGenericObjectType: false # remove this rule when all other issues are solved.ignoreErrors:+ # TODO: slowly remove these exceptions and fix the issues found.- '#Dynamic call to static method#' # all the Laravel ORM things depend on this.- '#Control structures using switch should not be used.#' # switch is fine insome cases.- '#with no value type specified in iterable type array#' # remove this rule when all other issues are solved.@@ -53,5 +55,6 @@ parameters:- ../bootstrap/app.php# The level 8 is the highest level. original was 5- level: 2+ # TODO: slowly up the level and fix the issues found.+ level: 3diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.phpindex 50d02138a3..a4b91118b5 100644--- a/app/Exceptions/GracefulNotFoundHandler.php+++ b/app/Exceptions/GracefulNotFoundHandler.php@@ -30,12 +30,8 @@ use FireflyIII\Models\TransactionGroup;use FireflyIII\Models\TransactionJournal;use FireflyIII\Models\TransactionType;use FireflyIII\User;-use Illuminate\Contracts\Foundation\Application;use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;-use Illuminate\Http\JsonResponse;-use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;-use Illuminate\Routing\Redirector;use Symfony\Component\HttpFoundation\Response;use Throwable;@@ -50,10 +46,10 @@ class GracefulNotFoundHandler extends ExceptionHandler* @param Request $request* @param Throwable $e*- * @return Application|JsonResponse|\Illuminate\Http\Response|Redirector|RedirectResponse|Response+ * @return Response* @throws Throwable*/- public function render($request, Throwable $e)+ public function render($request, Throwable $e): Response{$route = $request->route();if (null === $route) {@@ -140,7 +136,7 @@ class GracefulNotFoundHandler extends ExceptionHandler* @return Response* @throws Throwable*/- private function handleAccount(Request $request, Throwable $exception)+ private function handleAccount(Request $request, Throwable $exception): Response{app('log')->debug('404 page is probably a deleted account. Redirect to overview of account types.');/** @var User $user */diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 62acf1b180..73539aa520 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -31,6 +31,7 @@ use Illuminate\Auth\AuthenticationException;use Illuminate\Contracts\Foundation\Application;use Illuminate\Database\QueryException;use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;+use Illuminate\Http\JsonResponse;use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;use Illuminate\Routing\Redirector;@@ -40,6 +41,7 @@ use Illuminate\Validation\ValidationException as LaravelValidationException;use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthException;use League\OAuth2\Server\Exception\OAuthServerException;use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;+use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;use Symfony\Component\HttpKernel\Exception\HttpException;use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;@@ -75,10 +77,10 @@ class Handler extends ExceptionHandler* @param Request $request* @param Throwable $e*- * @return mixed+ * @return Response* @throws Throwable*/- public function render($request, Throwable $e)+ public function render($request, Throwable $e): Response{$expectsJson = $request->expectsJson();// if the user requests anything /api/, assume the user wants to see JSON.@@ -246,9 +248,9 @@ class Handler extends ExceptionHandler* @param Request $request* @param LaravelValidationException $exception*- * @return Application|RedirectResponse|Redirector+ * @return JsonResponse| RedirectResponse |\Illuminate\Http\Response*/- protected function invalid($request, LaravelValidationException $exception): Application | RedirectResponse | Redirector+ protected function invalid($request, LaravelValidationException $exception): JsonResponse| RedirectResponse |\Illuminate\Http\Response{// protect against open redirect when submitting invalid forms.$previous = app('steam')->getSafePreviousUrl();diff --git a/app/Models/CurrencyExchangeRate.php b/app/Models/CurrencyExchangeRate.phpindex cdb4e062b7..3faf5a835d 100644--- a/app/Models/CurrencyExchangeRate.php+++ b/app/Models/CurrencyExchangeRate.php@@ -72,7 +72,6 @@ class CurrencyExchangeRate extends Model{use SoftDeletes;- /** @var array Convert these fields to other data types */protected $casts= ['created_at' => 'datetime',diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.phpindex a783d1c37b..6d9f6cbfca 100644--- a/app/Models/PiggyBank.php+++ b/app/Models/PiggyBank.php@@ -86,11 +86,6 @@ class PiggyBank extends Model{use SoftDeletes;- /**- * The attributes that should be cast to native types.- *- * @var array- */protected $casts= ['created_at' => 'datetime',diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.phpindex c2c87177bb..590acd3cd6 100644--- a/app/Providers/AuthServiceProvider.php+++ b/app/Providers/AuthServiceProvider.php@@ -34,11 +34,6 @@ use Laravel\Passport\Passport;*/class AuthServiceProvider extends ServiceProvider{- /**- * The policy mappings for the application.- *- * @var array- */protected $policies= [// 'FireflyIII\Model' => 'FireflyIII\Policies\ModelPolicy',diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.phpindex 0d93ba7b23..8df7fe412a 100644--- a/app/Providers/EventServiceProvider.php+++ b/app/Providers/EventServiceProvider.php@@ -91,11 +91,6 @@ use Laravel\Passport\Events\AccessTokenCreated;*/class EventServiceProvider extends ServiceProvider{- /**- * The event listener mappings for the application.- *- * @var array- */protected $listen= [// is a User related event.diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.phpindex 2950640f53..1524994b3d 100644--- a/app/Providers/RouteServiceProvider.php+++ b/app/Providers/RouteServiceProvider.php@@ -31,19 +31,7 @@ use Illuminate\Support\Facades\Route;*/class RouteServiceProvider extends ServiceProvider{- /**- * The path to the "home" route for your application.- *- * @var string- */public const HOME = '/';- /**- * This namespace is applied to your controller routes.- *- * In addition, it is set as the URL generator's root namespace.- *- * @var string- */protected $namespace = '';/**diff --git a/app/Repositories/UserGroups/Currency/CurrencyRepository.php b/app/Repositories/UserGroups/Currency/CurrencyRepository.phpindex 8e89532f60..1af2ea506c 100644--- a/app/Repositories/UserGroups/Currency/CurrencyRepository.php+++ b/app/Repositories/UserGroups/Currency/CurrencyRepository.php@@ -193,9 +193,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface}/**- * Get the user group's currencies.- *- * @return Collection+ * @inheritDoc*/public function get(): Collection{diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.phpindex 441d8766de..ceec5aa750 100644--- a/app/Support/Authentication/RemoteUserGuard.php+++ b/app/Support/Authentication/RemoteUserGuard.php@@ -40,10 +40,8 @@ use Psr\Container\NotFoundExceptionInterface;class RemoteUserGuard implements Guard{protected Application $application;- /** @var UserProvider */- protected $provider;- /** @var User|null */- protected $user;+ protected UserProvider $provider;+ protected User|null $user;/*** Create a new authentication guard.@@ -159,10 +157,10 @@ class RemoteUserGuard implements Guard/*** @inheritDoc*/- public function id(): ?User+ public function id(): int|string|null{app('log')->debug(sprintf('Now at %s', __METHOD__));- return $this->user;+ return $this->user?->id;}/**diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.phpindex 6cf083aa93..52d9a01aa8 100644--- a/app/Support/Twig/General.php+++ b/app/Support/Twig/General.php@@ -40,7 +40,7 @@ use Twig\TwigFunction;class General extends AbstractExtension{/**- * @return array+ * @inheritDoc*/public function getFilters(): array{@@ -114,7 +114,7 @@ class General extends AbstractExtensionreturn 'fa-file-o';case 'application/pdf':return 'fa-file-pdf-o';- /* image */+ /* image */case 'image/png':case 'image/jpeg':case 'image/svg+xml':@@ -122,7 +122,7 @@ class General extends AbstractExtensioncase 'image/heic-sequence':case 'application/vnd.oasis.opendocument.image':return 'fa-file-image-o';- /* MS word */+ /* MS word */case 'application/msword':case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':@@ -137,7 +137,7 @@ class General extends AbstractExtensioncase 'application/vnd.oasis.opendocument.text-web':case 'application/vnd.oasis.opendocument.text-master':return 'fa-file-word-o';- /* MS excel */+ /* MS excel */case 'application/vnd.ms-excel':case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':case 'application/vnd.openxmlformats-officedocument.spreadsheetml.template':@@ -147,7 +147,7 @@ class General extends AbstractExtensioncase 'application/vnd.oasis.opendocument.spreadsheet':case 'application/vnd.oasis.opendocument.spreadsheet-template':return 'fa-file-excel-o';- /* MS powerpoint */+ /* MS powerpoint */case 'application/vnd.ms-powerpoint':case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':case 'application/vnd.openxmlformats-officedocument.presentationml.template':@@ -158,7 +158,7 @@ class General extends AbstractExtensioncase 'application/vnd.oasis.opendocument.presentation':case 'application/vnd.oasis.opendocument.presentation-template':return 'fa-file-powerpoint-o';- /* calc */+ /* calc */case 'application/vnd.sun.xml.draw':case 'application/vnd.sun.xml.draw.template':case 'application/vnd.stardivision.draw':diff --git a/app/Support/Twig/Rule.php b/app/Support/Twig/Rule.phpindex adc616b129..44ecd420cd 100644--- a/app/Support/Twig/Rule.php+++ b/app/Support/Twig/Rule.php@@ -33,7 +33,7 @@ use Twig\TwigFunction;class Rule extends AbstractExtension{/**- * @return array+ * @inheritDoc*/public function getFunctions(): array{diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.phpindex 38e3005eb5..14761dfb79 100644--- a/app/Support/Twig/TransactionGroupTwig.php+++ b/app/Support/Twig/TransactionGroupTwig.php@@ -38,8 +38,7 @@ use Twig\TwigFunction;class TransactionGroupTwig extends AbstractExtension{/**- * @return array- *+ * @inheritDoc*/public function getFunctions(): array{diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.phpindex 11b420f0be..806d065b72 100644--- a/app/Support/Twig/Translation.php+++ b/app/Support/Twig/Translation.php@@ -33,7 +33,7 @@ use Twig\TwigFunction;class Translation extends AbstractExtension{/**- * @return array+ * @inheritDoc*/public function getFilters(): array{diff --git a/app/Transformers/BudgetLimitTransformer.php b/app/Transformers/BudgetLimitTransformer.phpindex f4d9ea6532..a3c8dffad7 100644--- a/app/Transformers/BudgetLimitTransformer.php+++ b/app/Transformers/BudgetLimitTransformer.php@@ -33,7 +33,6 @@ use League\Fractal\Resource\Item;*/class BudgetLimitTransformer extends AbstractTransformer{- /** @var string[] */protected array $availableIncludes= ['budget',diff --git a/app/Transformers/V2/BudgetLimitTransformer.php b/app/Transformers/V2/BudgetLimitTransformer.phpindex 0b46b0fcae..deaca5f37d 100644--- a/app/Transformers/V2/BudgetLimitTransformer.php+++ b/app/Transformers/V2/BudgetLimitTransformer.php@@ -32,7 +32,6 @@ use League\Fractal\Resource\Item;*/class BudgetLimitTransformer extends AbstractTransformer{- /** @var string[] */protected array $availableIncludes= ['budget',diff --git a/app/User.php b/app/User.phpindex 424e61114f..9a3098d003 100644--- a/app/User.php+++ b/app/User.php@@ -176,34 +176,14 @@ class User extends Authenticatableuse HasApiTokens;use Notifiable;- /**- * The attributes that should be cast to native types.- *- * @var array- */protected $casts= ['created_at' => 'datetime','updated_at' => 'datetime','blocked' => 'boolean',];- /**- * The attributes that are mass assignable.- *- * @var array- */protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];- /**- * The attributes excluded from the model's JSON form.- *- * @var array- */protected $hidden = ['password', 'remember_token'];- /**- * The database table used by the model.- *- * @var string- */protected $table = 'users';/**