Fix various phpstan issues.

This commit is contained in:
James Cole
2025-09-07 10:59:07 +02:00
parent 75dfdcc220
commit 39cf0533d9
15 changed files with 44 additions and 58 deletions

View File

@@ -11,8 +11,6 @@ parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
# TODO: slowly remove these exceptions and fix the issues found.
- '#Dynamic call to static method#' # all the Laravel ORM things depend on this.
- identifier: varTag.nativeType
- identifier: varTag.type
-
identifier: larastan.noEnvCallsOutsideOfConfig
@@ -24,11 +22,11 @@ parameters:
- '#expects view-string\|null, string given#'
# phpstan can't handle this so we ignore them.
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#' # is custom scope
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#' # is custom scope
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#' # is to allow soft delete
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#' # is a custom scope
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#' # is to allow soft delete
# The level 8 is the highest level. original was 5
# 7 is more than enough, higher just leaves NULL things.

View File

@@ -157,7 +157,6 @@ abstract class Controller extends BaseController
/** @var User $user */
$user = auth()->user();
/** @var Preference $pageSize */
$pageSize = (int)app('preferences')->getForUser($user, 'listPageSize', 50)->data;
$bag->set($integer, $pageSize);
}

View File

@@ -66,7 +66,7 @@ class RemovesDatabaseDecryption extends Command
* @var string $table
* @var array $fields
*/
foreach ($tables as $table => $fields) {
foreach ($tables as $table => $fields) { // @phpstan-ignore-line
$this->decryptTable($table, $fields);
}

View File

@@ -170,7 +170,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
/** @var null|Account $account */
$account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId);
$account = $user->accounts()->withTrashed()->with(['accountType'])->find($accountId);
if (null === $account) {
app('log')->error(sprintf('Could not find account %d, so give big fat error.', $accountId));

View File

@@ -129,7 +129,7 @@ class UserEventHandler
$groupTitle = $user->email;
$index = 1;
/** @var UserGroup $group */
/** @var UserGroup|null $group */
$group = null;
// create a new group.

View File

@@ -412,7 +412,7 @@ class ProfileController extends Controller
// found user.which email address to return to?
$set = app('preferences')->beginsWith($user, 'previous_email_');
/** @var string $match */
/** @var string|null $match */
$match = null;
foreach ($set as $entry) {
$hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $entry->data));

View File

@@ -117,7 +117,7 @@ class BulkController extends Controller
// run rules on changed journals:
/** @var TransactionJournal $journal */
foreach ($collection as $journal) {
foreach ($collection as $journal) { // @phpstan-ignore-line
event(new UpdatedTransactionGroup($journal->transactionGroup, true, true, false));
}

View File

@@ -138,7 +138,7 @@ class RecurrenceFormRequest extends FormRequest
* @var int $index
* @var array $transaction
*/
foreach ($return['transactions'] as $index => $transaction) {
foreach ($return['transactions'] as $index => $transaction) { // @phpstan-ignore-line
$categoryName = $transaction['category_name'] ?? null;
if (null !== $categoryName) {
$category = $factory->findOrCreate(null, $categoryName);

View File

@@ -137,13 +137,10 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
if (!$existingGroup instanceof UserGroup) {
$exists = false;
/** @var null|UserGroup $existingGroup */
/** @var UserGroup $existingGroup */
$existingGroup = $this->store(['user' => $user, 'title' => $groupName]);
}
if (null !== $existingGroup) {
// group already exists
$groupName = sprintf('%s-%s', $user->email, substr(sha1(random_int(1000, 9999) . microtime()), 0, 4));
}
++$loop;
}
@@ -267,8 +264,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
// group has multiple members. How many are owner, except the user we're editing now?
$ownerCount = $userGroup->groupMemberships()
->where('user_role_id', $owner->id)
->where('user_id', '!=', $user->id)->count()
;
->where('user_id', '!=', $user->id)->count();
// if there are no other owners and the current users does not get or keep the owner role, refuse.
if (
0 === $ownerCount

View File

@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Form;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\MessageBag;
use Throwable;
@@ -146,15 +145,6 @@ trait FormSupport
protected function getDate(): Carbon
{
/** @var Carbon $date */
$date = null;
try {
$date = today(config('app.timezone'));
} catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error($e->getMessage());
}
return $date;
return today(config('app.timezone'));
}
}

View File

@@ -43,7 +43,7 @@ trait CleansChartData
$return = [];
/**
* @var mixed $index
* @var int $index
* @var array $array
*/
foreach ($data as $index => $array) {

View File

@@ -102,6 +102,9 @@ trait ConvertsDataTypes
{
// assume this all works, because the validator would have caught any errors.
$parameter = (string)request()->query->get($field);
if('' === $parameter) {
return [];
}
$parts = explode(',', $parameter);
$sortParameters = [];
foreach ($parts as $part) {

View File

@@ -317,7 +317,7 @@ class SearchRuleEngine implements RuleEngineInterface
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
/** @var Rule $rule */
foreach ($this->rules as $rule) {
foreach ($this->rules as $rule) { // @phpstan-ignore-line
$result = $this->fireRule($rule);
if (true === $result && true === $rule->stop_processing) {
Log::debug(sprintf('Rule #%d has triggered and executed, but calls to stop processing. Since not in the context of a group, do not stop.', $rule->id));
@@ -335,7 +335,7 @@ class SearchRuleEngine implements RuleEngineInterface
// fire each group:
/** @var RuleGroup $group */
foreach ($this->groups as $group) {
foreach ($this->groups as $group) { // @phpstan-ignore-line
$this->fireGroup($group);
}
}

View File

@@ -36,7 +36,7 @@ class TransactionTypeSeeder extends Seeder
public function run(): void
{
/** @var TransactionTypeEnum $type */
foreach (TransactionTypeEnum::cases() as $type) {
foreach (TransactionTypeEnum::cases() as $type) { // @phpstan-ignore-line
if (null === TransactionType::where('type', $type->value)->first()) {
try {
TransactionType::create(['type' => $type->value]);

View File

@@ -40,7 +40,7 @@ class UserRoleSeeder extends Seeder
public function run(): void
{
/** @var UserRoleEnum $role */
foreach (UserRoleEnum::cases() as $role) {
foreach (UserRoleEnum::cases() as $role) { // @phpstan-ignore-line
if (null === UserRole::where('title', $role->value)->first()) {
try {
UserRole::create(['title' => $role->value]);