Skip to content

Firefly III: a personal finances manager

Fix a bunch of phpstan errors.

James Cole84ea19d14c79
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index f58507e077..aa7b492cc2 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -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
diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php
index 089cd5f60f..8a14a0006a 100644
--- a/app/Api/V1/Controllers/Controller.php
+++ b/app/Api/V1/Controllers/Controller.php
@@ -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
diff --git a/app/Api/V1/Controllers/Models/Bill/StoreController.php b/app/Api/V1/Controllers/Models/Bill/StoreController.php
index ac1e05ff24..c39a1456cb 100644
--- a/app/Api/V1/Controllers/Models/Bill/StoreController.php
+++ b/app/Api/V1/Controllers/Models/Bill/StoreController.php
@@ -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');
diff --git a/app/Console/Commands/Correction/ConvertsDatesToUTC.php b/app/Console/Commands/Correction/ConvertsDatesToUTC.php
index 09a2867284..b3f37c2536 100644
--- a/app/Console/Commands/Correction/ConvertsDatesToUTC.php
+++ b/app/Console/Commands/Correction/ConvertsDatesToUTC.php
@@ -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');
diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php
index 109dacab3c..32d5bc4ae6 100644
--- a/app/Http/Controllers/Admin/UserController.php
+++ b/app/Http/Controllers/Admin/UserController.php
@@ -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) {
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 8cdb92bf1b..7e49032b46 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -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
{
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 86a14f790f..6c52e02385 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -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();
diff --git a/app/Http/Controllers/ObjectGroup/EditController.php b/app/Http/Controllers/ObjectGroup/EditController.php
index 2a254e5b10..4204e90808 100644
--- a/app/Http/Controllers/ObjectGroup/EditController.php
+++ b/app/Http/Controllers/ObjectGroup/EditController.php
@@ -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
{
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index beae651c93..76670a6c2a 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -342,7 +342,6 @@ final class ProfileController extends Controller
}
/**
- * @return Application|Redirector|RedirectResponse
*
* @throws AuthenticationException
*/
diff --git a/app/Http/Controllers/System/CronController.php b/app/Http/Controllers/System/CronController.php
index 5ec33780f7..560b64eb88 100644
--- a/app/Http/Controllers/System/CronController.php
+++ b/app/Http/Controllers/System/CronController.php
@@ -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]');
diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php
index 7387076eb2..029a697533 100644
--- a/app/Http/Controllers/Transaction/BulkController.php
+++ b/app/Http/Controllers/Transaction/BulkController.php
@@ -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
{
diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php
index 76ce590088..eafc6e973e 100644
--- a/app/Http/Controllers/Transaction/MassController.php
+++ b/app/Http/Controllers/Transaction/MassController.php
@@ -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__));
diff --git a/app/Http/Controllers/Webhooks/DeleteController.php b/app/Http/Controllers/Webhooks/DeleteController.php
index d899aafacf..4cb3f31d61 100644
--- a/app/Http/Controllers/Webhooks/DeleteController.php
+++ b/app/Http/Controllers/Webhooks/DeleteController.php
@@ -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) {
diff --git a/app/Http/Controllers/Webhooks/EditController.php b/app/Http/Controllers/Webhooks/EditController.php
index 9f949669dd..a2c0b16202 100644
--- a/app/Http/Controllers/Webhooks/EditController.php
+++ b/app/Http/Controllers/Webhooks/EditController.php
@@ -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) {
diff --git a/app/Http/Controllers/Webhooks/ShowController.php b/app/Http/Controllers/Webhooks/ShowController.php
index 53d45a1794..6deaea3a26 100644
--- a/app/Http/Controllers/Webhooks/ShowController.php
+++ b/app/Http/Controllers/Webhooks/ShowController.php
@@ -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) {
diff --git a/app/Rules/BelongsUser.php b/app/Rules/BelongsUser.php
index 9bbcd8fd6e..5069299d31 100644
--- a/app/Rules/BelongsUser.php
+++ b/app/Rules/BelongsUser.php
@@ -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));
diff --git a/app/Rules/BelongsUserGroup.php b/app/Rules/BelongsUserGroup.php
index ca3215d037..97f43f7c8b 100644
--- a/app/Rules/BelongsUserGroup.php
+++ b/app/Rules/BelongsUserGroup.php
@@ -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));
diff --git a/app/Rules/IsAllowedGroupAction.php b/app/Rules/IsAllowedGroupAction.php
index da6168b7cb..e070b2faa3 100644
--- a/app/Rules/IsAllowedGroupAction.php
+++ b/app/Rules/IsAllowedGroupAction.php
@@ -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) {
diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php
index 7deaadc1be..bad91d4d44 100644
--- a/app/Services/Internal/Update/CategoryUpdateService.php
+++ b/app/Services/Internal/Update/CategoryUpdateService.php
@@ -52,9 +52,6 @@ class CategoryUpdateService
}
}
- /**
- * @param mixed $user
- */
public function setUser(User $user): void
{
$this->user = $user;
diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php
index 4c5eaa9e3b..cd42602d0d 100644
--- a/app/Services/Internal/Update/JournalUpdateService.php
+++ b/app/Services/Internal/Update/JournalUpdateService.php
@@ -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));
diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php
index d66b936d5c..54058e87fd 100644
--- a/app/Support/Export/ExportDataGenerator.php
+++ b/app/Support/Export/ExportDataGenerator.php
@@ -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 {
diff --git a/app/Support/Models/AvailableBudgetCalculator.php b/app/Support/Models/AvailableBudgetCalculator.php
index 246b5f38f5..e3ab281f19 100644
--- a/app/Support/Models/AvailableBudgetCalculator.php
+++ b/app/Support/Models/AvailableBudgetCalculator.php
@@ -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);
}
diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php
index bcc87cc10d..f8d4bd403c 100644
--- a/app/Support/Search/OperatorQuerySearch.php
+++ b/app/Support/Search/OperatorQuerySearch.php
@@ -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 = [];
diff --git a/app/Transformers/AbstractTransformer.php b/app/Transformers/AbstractTransformer.php
index 1be605aaf1..96532797ec 100644
--- a/app/Transformers/AbstractTransformer.php
+++ b/app/Transformers/AbstractTransformer.php
@@ -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
{
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 649217dacf..249ed2d9af 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -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;