Skip to content

Firefly III: a personal finances manager

Fix phpstan issues.

James Cole9ac991edd73a
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index 17114856a7..a7ea28a1f6 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -34,10 +34,6 @@ parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
# these are actually interesting but not right now:
- - identifier: greater.alwaysTrue
- - identifier: function.alreadyNarrowedType
- - identifier: booleanNot.alwaysTrue
- - identifier: property.phpDocType
- identifier: nullCoalesce.offset
- identifier: nullCoalesce.variable
- identifier: larastan.noUnnecessaryCollectionCall
diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php
index 1e992d34be..d47b28be00 100644
--- a/app/Api/V1/Controllers/Controller.php
+++ b/app/Api/V1/Controllers/Controller.php
@@ -62,6 +62,7 @@ abstract class Controller extends BaseController
use DispatchesJobs;
use ValidatesRequests;
use ValidatesUserGroupTrait;
+ protected array $acceptedRoles = [];
protected const string CONTENT_TYPE = 'application/vnd.api+json';
protected const string JSON_CONTENT_TYPE = 'application/json';
diff --git a/app/Api/V1/Requests/AggregateFormRequest.php b/app/Api/V1/Requests/AggregateFormRequest.php
index 5398623a2b..7eec75145a 100644
--- a/app/Api/V1/Requests/AggregateFormRequest.php
+++ b/app/Api/V1/Requests/AggregateFormRequest.php
@@ -36,6 +36,8 @@ abstract class AggregateFormRequest extends ApiRequest
*/
protected array $requests = [];
+ protected array $acceptedRoles = [];
+
#[Override]
public function initialize(
array $query = [],
diff --git a/app/Api/V1/Requests/Models/AvailableBudget/Request.php b/app/Api/V1/Requests/Models/AvailableBudget/Request.php
index e3824e40e6..73f419d8ed 100644
--- a/app/Api/V1/Requests/Models/AvailableBudget/Request.php
+++ b/app/Api/V1/Requests/Models/AvailableBudget/Request.php
@@ -39,6 +39,7 @@ class Request extends FormRequest
{
use ChecksLogin;
use ConvertsDataTypes;
+ protected array $acceptedRoles = [];
/**
* Get all data from the request.
diff --git a/app/Console/Commands/Correction/CorrectsInvertedBudgetLimits.php b/app/Console/Commands/Correction/CorrectsInvertedBudgetLimits.php
index 2574a2891c..aff0cc704a 100644
--- a/app/Console/Commands/Correction/CorrectsInvertedBudgetLimits.php
+++ b/app/Console/Commands/Correction/CorrectsInvertedBudgetLimits.php
@@ -69,10 +69,6 @@ class CorrectsInvertedBudgetLimits extends Command
$budgetLimit->saveQuietly();
}
- if ($set->count() > 0) {
- // FIXME here be a available budget event.
- }
-
if (1 === $set->count()) {
$this->friendlyInfo('Corrected one budget limit to have the right start/end dates.');
diff --git a/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php b/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
index b6b741e58e..92c719a648 100644
--- a/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
+++ b/app/Console/Commands/Upgrade/RemovesDatabaseDecryption.php
@@ -127,7 +127,7 @@ class RemovesDatabaseDecryption extends Command
}
// A separate routine for preferences table:
- if ('preferences' === $table && is_string($value)) {
+ if ('preferences' === $table) {
$this->decryptPreferencesRow($id, $value);
return;
diff --git a/app/Exceptions/IntervalException.php b/app/Exceptions/IntervalException.php
index 68664388a9..85711d8716 100644
--- a/app/Exceptions/IntervalException.php
+++ b/app/Exceptions/IntervalException.php
@@ -36,7 +36,7 @@ final class IntervalException extends Exception
public array $availableIntervals = [];
public Periodicity $periodicity = Periodicity::Monthly;
- /** @var mixed */
+ /** @var string */
protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index 253987eaed..6065955379 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -389,17 +389,13 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
return (string) $budgetLimit->amount;
}
// if budget limit period is inside AB period, it can be added in full.
- if (!$limitPeriod->equals($availableBudgetPeriod) && $availableBudgetPeriod->contains($limitPeriod)) {
+ if ($availableBudgetPeriod->contains($limitPeriod)) {
Log::debug('This budget limit is smaller than the available budget period.');
return (string) $budgetLimit->amount;
}
- if (
- !$limitPeriod->equals($availableBudgetPeriod)
- && !$availableBudgetPeriod->contains($limitPeriod)
- && $availableBudgetPeriod->overlapsWith($limitPeriod)
- ) {
+ if ($availableBudgetPeriod->overlapsWith($limitPeriod)) {
Log::debug('This budget limit is something else entirely!');
$overlap = $availableBudgetPeriod->overlap($limitPeriod);
if ($overlap instanceof Period) {
diff --git a/app/Repositories/UserGroup/UserGroupRepository.php b/app/Repositories/UserGroup/UserGroupRepository.php
index 06f9c47689..8e80a96c89 100644
--- a/app/Repositories/UserGroup/UserGroupRepository.php
+++ b/app/Repositories/UserGroup/UserGroupRepository.php
@@ -255,7 +255,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
// if there are no other owners and the current users does not get or keep the owner role, refuse.
if (
0 === $ownerCount
- && (0 === count($data['roles']) || count($data['roles']) > 0 && !in_array(UserRoleEnum::OWNER->value, $data['roles'], true))
+ && (0 === count($data['roles']) || !in_array(UserRoleEnum::OWNER->value, $data['roles'], true))
) {
Log::debug('User needs to keep owner role in this group, refuse to act');
diff --git a/app/Rules/Account/IsValidAccountTypeList.php b/app/Rules/Account/IsValidAccountTypeList.php
index d2a8d97c51..a565a3a59b 100644
--- a/app/Rules/Account/IsValidAccountTypeList.php
+++ b/app/Rules/Account/IsValidAccountTypeList.php
@@ -41,9 +41,6 @@ class IsValidAccountTypeList implements ValidationRule
if (is_string($value)) {
$values = explode(',', $value);
}
- if (!is_array($values)) {
- $fail('validation.invalid_account_list')->translate();
- }
$keys = array_keys($this->types);
foreach ($values as $entry) {
if (!in_array($entry, $keys, true)) {
diff --git a/app/Rules/TransactionType/IsValidTransactionTypeList.php b/app/Rules/TransactionType/IsValidTransactionTypeList.php
index 1acf81c4d9..8a49bf4c00 100644
--- a/app/Rules/TransactionType/IsValidTransactionTypeList.php
+++ b/app/Rules/TransactionType/IsValidTransactionTypeList.php
@@ -41,9 +41,6 @@ class IsValidTransactionTypeList implements ValidationRule
if (is_string($value)) {
$values = explode(',', $value);
}
- if (!is_array($values)) {
- $fail('validation.invalid_transaction_type_list')->translate();
- }
$keys = array_keys($this->transactionTypes);
foreach ($values as $entry) {
if (!in_array($entry, $keys, true)) {
diff --git a/app/Support/Http/Api/ValidatesUserGroupTrait.php b/app/Support/Http/Api/ValidatesUserGroupTrait.php
index 0a920c3e2f..c494ab4c32 100644
--- a/app/Support/Http/Api/ValidatesUserGroupTrait.php
+++ b/app/Support/Http/Api/ValidatesUserGroupTrait.php
@@ -89,16 +89,15 @@ trait ValidatesUserGroupTrait
throw new AuthorizationException((string) trans('validation.belongs_user_or_user_group'));
}
Log::debug(sprintf('validateUserGroup: validate access of user to group #%d ("%s").', $groupId, $group->title));
- $roles = property_exists($this, 'acceptedRoles') ? $this->acceptedRoles : [];
- if (0 === count($roles)) {
+ if (0 === count($this->acceptedRoles)) {
Log::debug('validateUserGroup: no roles defined, so no access.');
throw new AuthorizationException((string) trans('validation.no_accepted_roles_defined'));
}
- Log::debug(sprintf('validateUserGroup: have %d roles to check.', count($roles)), $roles);
+ Log::debug(sprintf('validateUserGroup: have %d roles to check.', count($this->acceptedRoles)), $this->acceptedRoles);
/** @var UserRoleEnum $role */
- foreach ($roles as $role) {
+ foreach ($this->acceptedRoles as $role) {
if ($user->hasRoleInGroupOrOwner($group, $role)) {
Log::debug(sprintf('validateUserGroup: User has role "%s" in group #%d, return the group.', $role->value, $groupId));
$this->userGroup = $group;
diff --git a/app/Support/Request/ChecksLogin.php b/app/Support/Request/ChecksLogin.php
index 73bc0dfe84..ee37498e3b 100644
--- a/app/Support/Request/ChecksLogin.php
+++ b/app/Support/Request/ChecksLogin.php
@@ -45,8 +45,8 @@ trait ChecksLogin
if (!$check) {
return false;
}
- if (!property_exists($this, 'acceptedRoles')) {
- Log::debug(sprintf('Request class %s has no acceptedRoles array', static::class));
+ if (0 === count($this->acceptedRoles)) {
+ Log::debug(sprintf('Request class %s has 0 entries in acceptedRoles array', static::class));
return true; // check for false already took place.
}
diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php
index 9982564930..a2253e48ae 100644
--- a/app/Support/Request/ConvertsDataTypes.php
+++ b/app/Support/Request/ConvertsDataTypes.php
@@ -205,10 +205,9 @@ trait ConvertsDataTypes
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
- if (method_exists($this, 'validateUserGroup')) {
- $userGroup = $this->validateUserGroup($this);
- $repository->setUserGroup($userGroup);
- }
+ // blindly assume this method exists.
+ $userGroup = $this->validateUserGroup($this);
+ $repository->setUserGroup($userGroup);
// set administration ID
// group ID