Fix a bunch of phpstan errors.

This commit is contained in:
James Cole
2026-03-08 17:08:51 +01:00
parent 9950f79a6b
commit 84ea19d14c
25 changed files with 41 additions and 91 deletions
+2 -8
View File
@@ -33,13 +33,6 @@ parameters:
- Illuminate\Database\Eloquent\Model
reportUnmatchedIgnoredErrors: true
ignoreErrors:
# these are actually interesting but not right now:
- identifier: varTag.nativeType
- identifier: property.onlyWritten
- identifier: parameter.phpDocType
- identifier: property.dynamicName
- identifier: property.unusedType
- identifier: staticMethod.deprecated
# ignore everything but things that BREAK
- identifier: property.deprecated
- identifier: method.deprecated
@@ -50,8 +43,9 @@ parameters:
- identifier: return.type
- identifier: assign.propertyType
- identifier: return.unusedType
- identifier: return.phpDocType
# all errors below I will (probably) never fix.
- identifier: property.unusedType # one false positive
- identifier: varTag.nativeType # dont even know what im supposed to fix.
- identifier: method.notFound # way too many false positives
- identifier: catch.neverThrown # plenty of errors that are thrown undocumented
- identifier: staticMethod.dynamicName # dont care
+3
View File
@@ -171,6 +171,9 @@ abstract class Controller extends BaseController
return $manager->createData($resource)->toArray();
}
/**
* @deprecated
*/
#[Deprecated(message: <<<'TXT'
use Request classes
Method to grab all parameters from the URL
@@ -83,7 +83,6 @@ final class StoreController extends Controller
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($bill, $transformer, 'bills');
@@ -28,6 +28,7 @@ use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
@@ -82,7 +83,7 @@ class ConvertsDatesToUTC extends Command
return;
}
$this->friendlyInfo(sprintf('Converting field "%s" of model "%s" to UTC.', $field, $shortModel));
$items->each(static function ($item) use ($field, $timezoneField): void {
$items->each(static function (Model $item) use ($field, $timezoneField): void {
$date = Carbon::parse($item->{$field}, $item->{$timezoneField});
$date->setTimezone('UTC');
$item->{$field} = $date->format('Y-m-d H:i:s');
@@ -70,9 +70,6 @@ final class UserController extends Controller
$this->externalIdentity = 'web' !== config('firefly.authentication_guard');
}
/**
* @return Application|Factory|Redirector|RedirectResponse|View
*/
public function delete(User $user): Factory|\Illuminate\Contracts\View\View|Redirector|RedirectResponse
{
if ($this->externalIdentity) {
@@ -181,12 +181,6 @@ final class LoginController extends Controller
/**
* Show the application's login form.
*
* @return Application|Factory|Redirector|RedirectResponse|View
*
* @throws FireflyException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function showLoginForm(Request $request): Factory|Redirector|RedirectResponse|View
{
@@ -75,14 +75,6 @@ final class RegisterController extends Controller
}
}
/**
* Handle a registration request for the application.
*
* @return Application|Redirector|RedirectResponse
*
* @throws FireflyException
* @throws ValidationException
*/
public function register(Request $request): Redirector|RedirectResponse
{
$allowRegistration = $this->allowedToRegister();
@@ -78,7 +78,6 @@ final class EditController extends Controller
/**
* Update a piggy bank.
*
* @return Application|Redirector|RedirectResponse
*/
public function update(ObjectGroupFormRequest $request, ObjectGroup $objectGroup): Redirector|RedirectResponse
{
@@ -342,7 +342,6 @@ final class ProfileController extends Controller
}
/**
* @return Application|Redirector|RedirectResponse
*
* @throws AuthenticationException
*/
@@ -34,9 +34,6 @@ use Illuminate\Support\Facades\Log;
*/
final class CronController
{
/**
* @return Application|Response|ResponseFactory
*/
public function cron(): Response|ResponseFactory
{
Log::error('The cron endpoint has moved to GET /api/v1/cron/[token]');
@@ -47,8 +47,7 @@ use Illuminate\View\View;
*/
final class BulkController extends Controller
{
/** @var JournalRepositoryInterface Journals and transactions overview */
private $repository;
private JournalRepositoryInterface $repository;
/**
* BulkController constructor.
@@ -91,8 +90,6 @@ final class BulkController extends Controller
/**
* Update all journals.
*
* @return Application|Redirector|RedirectResponse
*/
public function update(BulkEditJournalRequest $request): Redirector|RedirectResponse
{
@@ -85,11 +85,6 @@ final class MassController extends Controller
return view('transactions.mass.delete', ['journals' => $journals, 'subTitle' => $subTitle]);
}
/**
* Do the mass delete.
*
* @return Application|Redirector|RedirectResponse
*/
public function destroy(MassDeleteJournalRequest $request): Redirector | RedirectResponse
{
Log::debug(sprintf('Now in %s', __METHOD__));
@@ -56,11 +56,6 @@ final class DeleteController extends Controller
});
}
/**
* Delete account screen.
*
* @return Application|Factory|View
*/
public function index(Webhook $webhook): Factory|View
{
if (false === FireflyConfig::get('allow_webhooks', config('firefly.allow_webhooks'))->data) {
@@ -54,12 +54,6 @@ final class EditController extends Controller
return $next($request);
});
}
/**
* Delete account screen.
*
* @return Application|Factory|View
*/
public function index(Webhook $webhook): Factory|View
{
if (false === FireflyConfig::get('allow_webhooks', config('firefly.allow_webhooks'))->data) {
@@ -55,11 +55,6 @@ final class ShowController extends Controller
});
}
/**
* Delete account screen.
*
* @return Application|Factory|View
*/
public function index(Webhook $webhook): Factory|View
{
if (false === FireflyConfig::get('allow_webhooks', config('firefly.allow_webhooks'))->data) {
+2
View File
@@ -33,6 +33,7 @@ use FireflyIII\Models\Category;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
/**
@@ -81,6 +82,7 @@ class BelongsUser implements ValidationRule
$objects = $class::where('user_id', '=', auth()->user()->id)->get();
}
$count = 0;
/** @var Model $object */
foreach ($objects as $object) {
$objectValue = trim((string) $object->{$field});
Log::debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
+2
View File
@@ -34,6 +34,7 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
/**
@@ -94,6 +95,7 @@ class BelongsUserGroup implements ValidationRule
$objects = $class::where('user_group_id', '=', $this->userGroup->id)->get();
}
$count = 0;
/** @var Model $object */
foreach ($objects as $object) {
$objectValue = trim((string) $object->{$field});
Log::debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
+1
View File
@@ -70,6 +70,7 @@ class IsAllowedGroupAction implements ValidationRule
private function validateUserGroup(): void
{
Log::debug('This method is not yet in use', $this->acceptedRoles);
try {
throw new FireflyException('Here we are');
} catch (FireflyException $e) {
@@ -52,9 +52,6 @@ class CategoryUpdateService
}
}
/**
* @param mixed $user
*/
public function setUser(User $user): void
{
$this->user = $user;
@@ -633,6 +633,9 @@ class JournalUpdateService
*/
private function updateField(string $fieldName): void
{
if(null === $this->transactionJournal) {
return;
}
if (array_key_exists($fieldName, $this->data) && '' !== (string) $this->data[$fieldName]) {
$value = $this->data[$fieldName];
@@ -665,15 +668,7 @@ class JournalUpdateService
}
$factory->updateOrCreate($set);
}
event(
new TransactionGroupRequestsAuditLogEntry(
$this->transactionJournal->user,
$this->transactionJournal,
sprintf('update_%s', $fieldName),
$this->transactionJournal->{$fieldName},
$value
)
);
event(new TransactionGroupRequestsAuditLogEntry($this->transactionJournal->user, $this->transactionJournal, sprintf('update_%s', $fieldName), $this->transactionJournal->{$fieldName}, $value));
$this->transactionJournal->{$fieldName} = $value;
Log::debug(sprintf('Updated %s', $fieldName));
+12 -11
View File
@@ -59,6 +59,7 @@ use FireflyIII\Support\Request\ConvertsDataTypes;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use League\Csv\AbstractCsv;
use League\Csv\CannotInsertRecord;
use League\Csv\Exception;
use League\Csv\Writer;
@@ -88,7 +89,7 @@ class ExportDataGenerator
private bool $exportTransactions = false;
private Carbon $start;
private User $user;
private UserGroup $userGroup;
//private UserGroup $userGroup;
public function __construct()
{
@@ -222,7 +223,7 @@ class ExportDataGenerator
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
// $this->userGroup = $userGroup;
}
/**
@@ -283,7 +284,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -352,7 +353,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -411,7 +412,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -456,7 +457,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -536,7 +537,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -703,7 +704,7 @@ class ExportDataGenerator
}
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -850,7 +851,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -906,7 +907,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -1102,7 +1103,7 @@ class ExportDataGenerator
}
// load the CSV document from a string
$csv = Writer::createFromString();
$csv = AbstractCsv::fromString();
// insert the header
try {
@@ -105,10 +105,10 @@ class AvailableBudgetCalculator
$this->user = $user;
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->abRepository->setUser($user);
$this->blRepository->setUser($user);
$this->abRepository->setUser($this->user);
$this->blRepository->setUser($this->user);
$viewRange = Preferences::getForUser($user, 'viewRange', '1M')->data;
$viewRange = Preferences::getForUser($this->user, 'viewRange', '1M')->data;
$viewRange = !is_string($viewRange) ? '1M' : $viewRange;
$this->viewRange = $this->correctViewRange($viewRange);
}
+1 -1
View File
@@ -71,7 +71,7 @@ class OperatorQuerySearch implements SearchInterface
private array $excludeTags = [];
private array $includeAnyTags = [];
// added to fix #8632
private array $includeTags = [];
// private array $includeTags = [];
// added to fix #11473
private array $includeAllTags = [];
private array $invalidOperators = [];
+7
View File
@@ -35,12 +35,19 @@ abstract class AbstractTransformer extends TransformerAbstract
{
protected ParameterBag $parameters;
/**
* @deprecated
*/
#[Deprecated]
final public function getParameters(): ParameterBag
{
return $this->parameters;
}
/**
* @deprecated
*/
#[Deprecated]
final public function setParameters(ParameterBag $parameters): void
{
+1 -7
View File
@@ -499,13 +499,7 @@ class FireflyValidator extends Validator
return true;
}
/**
* @param mixed $attribute
* @param mixed $value
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
public function validateSecurePassword($attribute, ?string $value): bool
public function validateSecurePassword(mixed $attribute, ?string $value): bool
{
$value = (string) $value;
$verify = false;