From 8c5f1143397bfddd8188ecf40f9f9ab697f407a3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 6 Nov 2024 19:22:28 +0100 Subject: [PATCH] Add enums to types. --- app/Models/AccountType.php | 8 ++++++++ app/Models/AutoBudget.php | 9 +++++++++ app/Models/RecurrenceRepetition.php | 9 +++++++++ app/Models/TransactionType.php | 10 ++++++++++ app/Models/Webhook.php | 15 ++++++++++++--- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 81cfbdc197..49fccbd0d8 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Models; +use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -61,4 +62,11 @@ class AccountType extends Model { return $this->hasMany(Account::class); } + + protected function casts(): array + { + return [ + 'type' => AccountTypeEnum::class, + ]; + } } diff --git a/app/Models/AutoBudget.php b/app/Models/AutoBudget.php index a61eaa6a1f..be76370f1a 100644 --- a/app/Models/AutoBudget.php +++ b/app/Models/AutoBudget.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Models; +use FireflyIII\Enums\AccountTypeEnum; +use FireflyIII\Enums\AutoBudgetType; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; @@ -53,6 +55,13 @@ class AutoBudget extends Model return $this->belongsTo(TransactionCurrency::class); } + protected function casts(): array + { + return [ + 'auto_budget_type' => AutoBudgetType::class, + ]; + } + protected function amount(): Attribute { return Attribute::make( diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index e669ed02a3..3815d8aff2 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace FireflyIII\Models; +use FireflyIII\Enums\AccountTypeEnum; +use FireflyIII\Enums\RecurrenceRepetitionWeekend; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; @@ -58,6 +60,13 @@ class RecurrenceRepetition extends Model /** @var string The table to store the data in */ protected $table = 'recurrences_repetitions'; + protected function casts(): array + { + return [ + 'weekend' => RecurrenceRepetitionWeekend::class, + ]; + } + public function recurrence(): BelongsTo { return $this->belongsTo(Recurrence::class); diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index 5f9b5f7111..7b7eb1ac3d 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Models; +use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -53,6 +54,15 @@ class TransactionType extends Model ]; protected $fillable = ['type']; + + protected function casts(): array + { + return [ + 'type' => TransactionTypeEnum::class, + ]; + } + + /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index 11bceb0f04..ecddb731e1 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -53,6 +53,15 @@ class Webhook extends Model ]; protected $fillable = ['active', 'trigger', 'response', 'delivery', 'user_id', 'user_group_id', 'url', 'title', 'secret']; + protected function casts(): array + { + return [ + 'delivery' => WebhookDelivery::class, + 'response' => WebhookResponse::class, + 'trigger' => WebhookTrigger::class, + ]; + } + public static function getDeliveries(): array { $array = []; @@ -130,13 +139,13 @@ class Webhook extends Model public static function routeBinder(string $value): self { if (auth()->check()) { - $webhookId = (int)$value; + $webhookId = (int) $value; /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); /** @var null|Webhook $webhook */ - $webhook = $user->webhooks()->find($webhookId); + $webhook = $user->webhooks()->find($webhookId); if (null !== $webhook) { return $webhook; }