Skip to content

Firefly III: a personal finances manager

Fix phpstan issues by adding properties.

James Cole133449640d56
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index 72dd142e93..df0d4e40d4 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -38,7 +38,6 @@ parameters:
- identifier: method.deprecated
- identifier: cast.useless
- identifier: argument.type
- - identifier: assign.propertyType
# 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.
@@ -54,9 +53,6 @@ parameters:
# - '#expects view-string, string given#'
# - "#Parameter \\#[1-2] \\$num[1-2] of function bc[a-z]+ expects numeric-string, [a-z\\-|&]+ given#"
- identifier: missingType.generics # not interesting enough to fix.
- -
- identifier: larastan.noEnvCallsOutsideOfConfig
- path: ../app/Console/Commands/System/CreatesDatabase.php
- identifier: missingType.iterableValue # not interesting enough to fix.
- identifier: varTag.type # needs a custom extension for every repository, not gonna happen.
# - '#Dynamic call to static method Illuminate#'
diff --git a/app/Api/V1/Requests/AggregateFormRequest.php b/app/Api/V1/Requests/AggregateFormRequest.php
index 67ccea2cbd..6072f24d63 100644
--- a/app/Api/V1/Requests/AggregateFormRequest.php
+++ b/app/Api/V1/Requests/AggregateFormRequest.php
@@ -32,7 +32,7 @@ use RuntimeException;
abstract class AggregateFormRequest extends ApiRequest
{
/**
- * @var ApiRequest[]
+ * @var Request[]
*/
protected array $requests = [];
diff --git a/app/Console/Commands/System/CreatesDatabase.php b/app/Console/Commands/System/CreatesDatabase.php
index 9917ee3b56..9bb5f4a361 100644
--- a/app/Console/Commands/System/CreatesDatabase.php
+++ b/app/Console/Commands/System/CreatesDatabase.php
@@ -54,10 +54,10 @@ class CreatesDatabase extends Command
}
// try to set up a raw connection:
$exists = false;
- $dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4', env('DB_HOST'), env('DB_PORT'));
+ $dsn = sprintf('mysql:host=%s;port=%d;charset=utf8mb4',config('database.connections.mysql.host'), config('database.connections.mysql.port'));
- if ('' !== (string) env('DB_SOCKET')) {
- $dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', env('DB_SOCKET'));
+ if ('' !== (string) config('database.connections.mysql.unix_socket')) {
+ $dsn = sprintf('mysql:unix_socket=%s;charset=utf8mb4', config('database.connections.mysql.unix_socket'));
}
$this->friendlyLine(sprintf('DSN is %s', $dsn));
@@ -69,7 +69,7 @@ class CreatesDatabase extends Command
// when it fails, display error
try {
- $pdo = new PDO($dsn, (string) env('DB_USERNAME'), (string) env('DB_PASSWORD'), $options);
+ $pdo = new PDO($dsn, (string) config('database.connections.mysql.username'), (string) config('database.connections.mysql.password'), $options);
} catch (PDOException $e) {
$this->friendlyError(sprintf('Error when connecting to DB: %s', $e->getMessage()));
@@ -83,19 +83,19 @@ class CreatesDatabase extends Command
// slightly more complex but less error-prone.
foreach ($stmt as $row) {
$name = $row['Database'] ?? false;
- if ($name === env('DB_DATABASE')) {
+ if ($name === config('database.connections.mysql.database')) {
$exists = true;
}
}
if (false === $exists) {
- $this->friendlyError(sprintf('Database "%s" does not exist.', env('DB_DATABASE')));
+ $this->friendlyError(sprintf('Database "%s" does not exist.', config('database.connections.mysql.database')));
// try to create it.
- $pdo->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', env('DB_DATABASE')));
- $this->friendlyInfo(sprintf('Created database "%s"', env('DB_DATABASE')));
+ $pdo->exec(sprintf('CREATE DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;', config('database.connections.mysql.database')));
+ $this->friendlyInfo(sprintf('Created database "%s"', config('database.connections.mysql.database')));
}
if ($exists) {
- $this->friendlyInfo(sprintf('Database "%s" exists.', env('DB_DATABASE')));
+ $this->friendlyInfo(sprintf('Database "%s" exists.', config('database.connections.mysql.database')));
}
return 0;
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 2fb8a9b849..efe411b75f 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -44,6 +44,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @property AccountType $accountType
+ * @property User $user
*/
#[ObservedBy([DeletedAccountObserver::class])]
class Account extends Model
diff --git a/app/Models/AutoBudget.php b/app/Models/AutoBudget.php
index fa97b9691d..a56676b19f 100644
--- a/app/Models/AutoBudget.php
+++ b/app/Models/AutoBudget.php
@@ -32,6 +32,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
+/**
+ * @property TransactionCurrency $transactionCurrency
+ */
#[ObservedBy([AutoBudgetObserver::class])]
class AutoBudget extends Model
{
diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php
index 056e0d5dc0..a497806942 100644
--- a/app/Models/AvailableBudget.php
+++ b/app/Models/AvailableBudget.php
@@ -35,6 +35,10 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+/**
+ * @property User $user
+ * @property TransactionCurrency $transactionCurrency
+ */
#[ObservedBy([AvailableBudgetObserver::class])]
class AvailableBudget extends Model
{
@@ -42,36 +46,37 @@ class AvailableBudget extends Model
use ReturnsIntegerUserIdTrait;
use SoftDeletes;
- protected $fillable = [
- 'user_id',
- 'user_group_id',
- 'transaction_currency_id',
- 'amount',
- 'start_date',
- 'end_date',
- 'start_date_tz',
- 'end_date_tz',
- 'native_amount',
- ];
+ protected $fillable
+ = [
+ 'user_id',
+ 'user_group_id',
+ 'transaction_currency_id',
+ 'amount',
+ 'start_date',
+ 'end_date',
+ 'start_date_tz',
+ 'end_date_tz',
+ 'native_amount',
+ ];
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
* @throws NotFoundHttpException
*/
- public static function routeBinder(self|string $value): self
+ public static function routeBinder(self | string $value): self
{
if ($value instanceof self) {
- $value = (int) $value->id;
+ $value = (int)$value->id;
}
if (auth()->check()) {
- $availableBudgetId = (int) $value;
+ $availableBudgetId = (int)$value;
/** @var User $user */
- $user = auth()->user();
+ $user = auth()->user();
/** @var null|AvailableBudget $availableBudget */
- $availableBudget = $user->availableBudgets()->find($availableBudgetId);
+ $availableBudget = $user->availableBudgets()->find($availableBudgetId);
if (null !== $availableBudget) {
return $availableBudget;
}
@@ -92,7 +97,7 @@ class AvailableBudget extends Model
protected function amount(): Attribute
{
- return Attribute::make(get: static fn ($value): string => (string) $value);
+ return Attribute::make(get: static fn($value): string => (string)$value);
}
protected function casts(): array
@@ -114,21 +119,21 @@ class AvailableBudget extends Model
protected function endDate(): Attribute
{
return Attribute::make(
- get: static fn (string $value): Carbon => Carbon::parse($value),
- set: static fn (Carbon $value): string => $value->format('Y-m-d')
+ get: static fn(string $value): Carbon => Carbon::parse($value),
+ set: static fn(Carbon $value): string => $value->format('Y-m-d')
);
}
protected function startDate(): Attribute
{
return Attribute::make(
- get: static fn (string $value): Carbon => Carbon::parse($value),
- set: static fn (Carbon $value): string => $value->format('Y-m-d')
+ get: static fn(string $value): Carbon => Carbon::parse($value),
+ set: static fn(Carbon $value): string => $value->format('Y-m-d')
);
}
protected function transactionCurrencyId(): Attribute
{
- return Attribute::make(get: static fn ($value): int => (int) $value);
+ return Attribute::make(get: static fn($value): int => (int)$value);
}
}
diff --git a/app/Models/Bill.php b/app/Models/Bill.php
index 6e07a06ca0..e90b3bf62a 100644
--- a/app/Models/Bill.php
+++ b/app/Models/Bill.php
@@ -43,6 +43,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon $date
* @property null|Carbon $end_date
* @property null|Carbon $extension_date
+ * @property User $user
+ * @property TransactionCurrency $transactionCurrency
*/
#[ObservedBy([BillObserver::class])]
class Bill extends Model
diff --git a/app/Models/InvitedUser.php b/app/Models/InvitedUser.php
index bd933a3de4..2228b4d801 100644
--- a/app/Models/InvitedUser.php
+++ b/app/Models/InvitedUser.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Models;
+use Carbon\Carbon;
use FireflyIII\Casts\SeparateTimezoneCaster;
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait;
@@ -32,6 +33,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+/**
+ * @property Carbon $expires
+ */
class InvitedUser extends Model
{
use ReturnsIntegerIdTrait;
diff --git a/app/Models/PeriodStatistic.php b/app/Models/PeriodStatistic.php
index 3431b25a0c..1b94803585 100644
--- a/app/Models/PeriodStatistic.php
+++ b/app/Models/PeriodStatistic.php
@@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
* @property Carbon $start
* @property Carbon $end
+ * @property string $amount
*/
class PeriodStatistic extends Model
{
diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php
index 908bbb9d9e..673a6bc178 100644
--- a/app/Models/PiggyBank.php
+++ b/app/Models/PiggyBank.php
@@ -40,6 +40,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @property null|Carbon $target_date
* @property null|Carbon $start_date
+ * @property TransactionCurrency $transactionCurrency
*/
#[ObservedBy([PiggyBankObserver::class])]
class PiggyBank extends Model
diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php
index 11fa9b39aa..3af93c8887 100644
--- a/app/Models/Recurrence.php
+++ b/app/Models/Recurrence.php
@@ -43,6 +43,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property null|Carbon $first_date
* @property null|Carbon $latest_date
* @property null|Carbon $repeat_until
+ * @property User $user
*/
#[ObservedBy([DeletedRecurrenceObserver::class])]
class Recurrence extends Model
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index 2f887ae958..c80f949daa 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -35,6 +35,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
+/**
+ * @property Account|null $account
+ * @property TransactionCurrency $transactionCurrency
+ * @property TransactionCurrency|null $foreignCurrency
+ * @property string|null $balance_before
+ * @property string|null $balance_after
+ */
#[ObservedBy([TransactionObserver::class])]
class Transaction extends Model
{
diff --git a/app/Models/WebhookMessage.php b/app/Models/WebhookMessage.php
index 44a35bec40..f5adcd3dde 100644
--- a/app/Models/WebhookMessage.php
+++ b/app/Models/WebhookMessage.php
@@ -34,6 +34,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+/**
+ * @property array|string $message
+ */
#[ObservedBy([DeletedWebhookMessageObserver::class])]
class WebhookMessage extends Model
{
diff --git a/app/User.php b/app/User.php
index 0d59c9030f..e9598b7b29 100644
--- a/app/User.php
+++ b/app/User.php
@@ -75,6 +75,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @property UserGroup|null $userGroup
+ * @property bool $blocked
*/
class User extends Authenticatable
{