Fix up to level 3

This commit is contained in:
James Cole
2023-11-05 10:16:53 +01:00
parent 2d5790c417
commit c0cc896102
18 changed files with 35 additions and 90 deletions

View File

@@ -19,12 +19,12 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>. ~ along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<ruleset name="pcsg-generated-ruleset" <ruleset name="Firefly III ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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: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"> xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Bla bla</description> <description>Firefly III ruleset</description>
<!-- <!--
Commando vanuit firefly directory: Commando vanuit firefly directory:
@@ -37,8 +37,7 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r
</rule> </rule>
<!-- clean code --> <!-- 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/naming.xml" />
<rule ref="rulesets/unusedcode.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"> <rule ref="rulesets/codesize.xml/NPathComplexity">
<properties> <properties>
<!-- TODO we want to be at a value of 128. But we start high, and drop the bar slowly. --> <!-- 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> </properties>
</rule> </rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"> <rule ref="rulesets/codesize.xml/ExcessiveMethodLength">

View File

@@ -1,9 +1,11 @@
parameters: parameters:
universalObjectCratesClasses: universalObjectCratesClasses:
- Illuminate\Database\Eloquent\Model - Illuminate\Database\Eloquent\Model
# TODO: slowly remove these parameters and fix the issues found.
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false # remove this rule when all other issues are solved. checkGenericClassInNonGenericObjectType: false # remove this rule when all other issues are solved.
ignoreErrors: ignoreErrors:
# TODO: slowly remove these exceptions and fix the issues found.
- '#Dynamic call to static method#' # all the Laravel ORM things depend on this. - '#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. - '#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. - '#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 - ../bootstrap/app.php
# The level 8 is the highest level. original was 5 # The level 8 is the highest level. original was 5
level: 2 # TODO: slowly up the level and fix the issues found.
level: 3

View File

@@ -30,12 +30,8 @@ use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Throwable; use Throwable;
@@ -50,10 +46,10 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Throwable $e * @param Throwable $e
* *
* @return Application|JsonResponse|\Illuminate\Http\Response|Redirector|RedirectResponse|Response * @return Response
* @throws Throwable * @throws Throwable
*/ */
public function render($request, Throwable $e) public function render($request, Throwable $e): Response
{ {
$route = $request->route(); $route = $request->route();
if (null === $route) { if (null === $route) {
@@ -140,7 +136,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @return Response * @return Response
* @throws Throwable * @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.'); app('log')->debug('404 page is probably a deleted account. Redirect to overview of account types.');
/** @var User $user */ /** @var User $user */

View File

@@ -31,6 +31,7 @@ use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Foundation\Application;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
@@ -40,6 +41,7 @@ use Illuminate\Validation\ValidationException as LaravelValidationException;
use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthException; use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthException;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
@@ -75,10 +77,10 @@ class Handler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Throwable $e * @param Throwable $e
* *
* @return mixed * @return Response
* @throws Throwable * @throws Throwable
*/ */
public function render($request, Throwable $e) public function render($request, Throwable $e): Response
{ {
$expectsJson = $request->expectsJson(); $expectsJson = $request->expectsJson();
// if the user requests anything /api/, assume the user wants to see JSON. // 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 Request $request
* @param LaravelValidationException $exception * @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. // protect against open redirect when submitting invalid forms.
$previous = app('steam')->getSafePreviousUrl(); $previous = app('steam')->getSafePreviousUrl();

View File

@@ -72,7 +72,6 @@ class CurrencyExchangeRate extends Model
{ {
use SoftDeletes; use SoftDeletes;
/** @var array Convert these fields to other data types */
protected $casts protected $casts
= [ = [
'created_at' => 'datetime', 'created_at' => 'datetime',

View File

@@ -86,11 +86,6 @@ class PiggyBank extends Model
{ {
use SoftDeletes; use SoftDeletes;
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts protected $casts
= [ = [
'created_at' => 'datetime', 'created_at' => 'datetime',

View File

@@ -34,11 +34,6 @@ use Laravel\Passport\Passport;
*/ */
class AuthServiceProvider extends ServiceProvider class AuthServiceProvider extends ServiceProvider
{ {
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies protected $policies
= [ = [
// 'FireflyIII\Model' => 'FireflyIII\Policies\ModelPolicy', // 'FireflyIII\Model' => 'FireflyIII\Policies\ModelPolicy',

View File

@@ -91,11 +91,6 @@ use Laravel\Passport\Events\AccessTokenCreated;
*/ */
class EventServiceProvider extends ServiceProvider class EventServiceProvider extends ServiceProvider
{ {
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen protected $listen
= [ = [
// is a User related event. // is a User related event.

View File

@@ -31,19 +31,7 @@ use Illuminate\Support\Facades\Route;
*/ */
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/'; 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 = ''; protected $namespace = '';
/** /**

View File

@@ -193,9 +193,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
} }
/** /**
* Get the user group's currencies. * @inheritDoc
*
* @return Collection
*/ */
public function get(): Collection public function get(): Collection
{ {

View File

@@ -40,10 +40,8 @@ use Psr\Container\NotFoundExceptionInterface;
class RemoteUserGuard implements Guard class RemoteUserGuard implements Guard
{ {
protected Application $application; protected Application $application;
/** @var UserProvider */ protected UserProvider $provider;
protected $provider; protected User|null $user;
/** @var User|null */
protected $user;
/** /**
* Create a new authentication guard. * Create a new authentication guard.
@@ -159,10 +157,10 @@ class RemoteUserGuard implements Guard
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function id(): ?User public function id(): int|string|null
{ {
app('log')->debug(sprintf('Now at %s', __METHOD__)); app('log')->debug(sprintf('Now at %s', __METHOD__));
return $this->user; return $this->user?->id;
} }
/** /**

View File

@@ -40,7 +40,7 @@ use Twig\TwigFunction;
class General extends AbstractExtension class General extends AbstractExtension
{ {
/** /**
* @return array * @inheritDoc
*/ */
public function getFilters(): array public function getFilters(): array
{ {
@@ -114,7 +114,7 @@ class General extends AbstractExtension
return 'fa-file-o'; return 'fa-file-o';
case 'application/pdf': case 'application/pdf':
return 'fa-file-pdf-o'; return 'fa-file-pdf-o';
/* image */ /* image */
case 'image/png': case 'image/png':
case 'image/jpeg': case 'image/jpeg':
case 'image/svg+xml': case 'image/svg+xml':
@@ -122,7 +122,7 @@ class General extends AbstractExtension
case 'image/heic-sequence': case 'image/heic-sequence':
case 'application/vnd.oasis.opendocument.image': case 'application/vnd.oasis.opendocument.image':
return 'fa-file-image-o'; return 'fa-file-image-o';
/* MS word */ /* MS word */
case 'application/msword': case 'application/msword':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 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-web':
case 'application/vnd.oasis.opendocument.text-master': case 'application/vnd.oasis.opendocument.text-master':
return 'fa-file-word-o'; return 'fa-file-word-o';
/* MS excel */ /* MS excel */
case 'application/vnd.ms-excel': case 'application/vnd.ms-excel':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 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':
case 'application/vnd.oasis.opendocument.spreadsheet-template': case 'application/vnd.oasis.opendocument.spreadsheet-template':
return 'fa-file-excel-o'; return 'fa-file-excel-o';
/* MS powerpoint */ /* MS powerpoint */
case 'application/vnd.ms-powerpoint': case 'application/vnd.ms-powerpoint':
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
case 'application/vnd.openxmlformats-officedocument.presentationml.template': 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':
case 'application/vnd.oasis.opendocument.presentation-template': case 'application/vnd.oasis.opendocument.presentation-template':
return 'fa-file-powerpoint-o'; return 'fa-file-powerpoint-o';
/* calc */ /* calc */
case 'application/vnd.sun.xml.draw': case 'application/vnd.sun.xml.draw':
case 'application/vnd.sun.xml.draw.template': case 'application/vnd.sun.xml.draw.template':
case 'application/vnd.stardivision.draw': case 'application/vnd.stardivision.draw':

View File

@@ -33,7 +33,7 @@ use Twig\TwigFunction;
class Rule extends AbstractExtension class Rule extends AbstractExtension
{ {
/** /**
* @return array * @inheritDoc
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {

View File

@@ -38,8 +38,7 @@ use Twig\TwigFunction;
class TransactionGroupTwig extends AbstractExtension class TransactionGroupTwig extends AbstractExtension
{ {
/** /**
* @return array * @inheritDoc
*
*/ */
public function getFunctions(): array public function getFunctions(): array
{ {

View File

@@ -33,7 +33,7 @@ use Twig\TwigFunction;
class Translation extends AbstractExtension class Translation extends AbstractExtension
{ {
/** /**
* @return array * @inheritDoc
*/ */
public function getFilters(): array public function getFilters(): array
{ {

View File

@@ -33,7 +33,6 @@ use League\Fractal\Resource\Item;
*/ */
class BudgetLimitTransformer extends AbstractTransformer class BudgetLimitTransformer extends AbstractTransformer
{ {
/** @var string[] */
protected array $availableIncludes protected array $availableIncludes
= [ = [
'budget', 'budget',

View File

@@ -32,7 +32,6 @@ use League\Fractal\Resource\Item;
*/ */
class BudgetLimitTransformer extends AbstractTransformer class BudgetLimitTransformer extends AbstractTransformer
{ {
/** @var string[] */
protected array $availableIncludes protected array $availableIncludes
= [ = [
'budget', 'budget',

View File

@@ -176,34 +176,14 @@ class User extends Authenticatable
use HasApiTokens; use HasApiTokens;
use Notifiable; use Notifiable;
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts protected $casts
= [ = [
'created_at' => 'datetime', 'created_at' => 'datetime',
'updated_at' => 'datetime', 'updated_at' => 'datetime',
'blocked' => 'boolean', 'blocked' => 'boolean',
]; ];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['email', 'password', 'blocked', 'blocked_code']; protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token']; protected $hidden = ['password', 'remember_token'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users'; protected $table = 'users';
/** /**