From c0cc8961023934ac91368bc70fc88e8a60033450 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 5 Nov 2023 10:16:53 +0100 Subject: [PATCH] Fix up to level 3 --- .ci/phpmd/phpmd.xml | 17 ++++++++-------- .ci/phpstan.neon | 5 ++++- app/Exceptions/GracefulNotFoundHandler.php | 10 +++------- app/Exceptions/Handler.php | 10 ++++++---- app/Models/CurrencyExchangeRate.php | 1 - app/Models/PiggyBank.php | 5 ----- app/Providers/AuthServiceProvider.php | 5 ----- app/Providers/EventServiceProvider.php | 5 ----- app/Providers/RouteServiceProvider.php | 12 ----------- .../Currency/CurrencyRepository.php | 4 +--- .../Authentication/RemoteUserGuard.php | 10 ++++------ app/Support/Twig/General.php | 12 +++++------ app/Support/Twig/Rule.php | 2 +- app/Support/Twig/TransactionGroupTwig.php | 3 +-- app/Support/Twig/Translation.php | 2 +- app/Transformers/BudgetLimitTransformer.php | 1 - .../V2/BudgetLimitTransformer.php | 1 - app/User.php | 20 ------------------- 18 files changed, 35 insertions(+), 90 deletions(-) diff --git a/.ci/phpmd/phpmd.xml b/.ci/phpmd/phpmd.xml index be299fb568..38146de2ba 100644 --- a/.ci/phpmd/phpmd.xml +++ b/.ci/phpmd/phpmd.xml @@ -19,12 +19,12 @@ ~ along with this program. If not, see . --> - - Bla bla + + Firefly III ruleset - - + @@ -51,7 +50,7 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r - + diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon index 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: false checkGenericClassInNonGenericObjectType: 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: 3 diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.php index 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.php index 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.php index 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.php index 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.php index 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.php index 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.php index 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.php index 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.php index 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.php index 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 AbstractExtension return '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 AbstractExtension case '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 AbstractExtension case '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 AbstractExtension case '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 AbstractExtension case '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.php index 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.php index 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.php index 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.php index 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.php index 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.php index 424e61114f..9a3098d003 100644 --- a/app/User.php +++ b/app/User.php @@ -176,34 +176,14 @@ class User extends Authenticatable use 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'; /**