Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -41,36 +41,37 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\Recurrence
*
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property int $user_id
* @property int $transaction_type_id
* @property string $title
* @property string $description
* @property Carbon|null $first_date
* @property Carbon|null $repeat_until
* @property Carbon|null $latest_date
* @property int|string $repetitions
* @property bool $apply_rules
* @property bool $active
* @property-read Collection|Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read Collection|Note[] $notes
* @property-read int|null $notes_count
* @property-read Collection|RecurrenceMeta[] $recurrenceMeta
* @property-read int|null $recurrence_meta_count
* @property-read Collection|RecurrenceRepetition[] $recurrenceRepetitions
* @property-read int|null $recurrence_repetitions_count
* @property-read Collection|RecurrenceTransaction[] $recurrenceTransactions
* @property-read int|null $recurrence_transactions_count
* @property-read TransactionCurrency $transactionCurrency
* @property-read TransactionType $transactionType
* @property-read User $user
* @property int $id
* @property null|Carbon $created_at
* @property null|Carbon $updated_at
* @property null|Carbon $deleted_at
* @property int $user_id
* @property int $transaction_type_id
* @property string $title
* @property string $description
* @property null|Carbon $first_date
* @property null|Carbon $repeat_until
* @property null|Carbon $latest_date
* @property int|string $repetitions
* @property bool $apply_rules
* @property bool $active
* @property Attachment[]|Collection $attachments
* @property null|int $attachments_count
* @property Collection|Note[] $notes
* @property null|int $notes_count
* @property Collection|RecurrenceMeta[] $recurrenceMeta
* @property null|int $recurrence_meta_count
* @property Collection|RecurrenceRepetition[] $recurrenceRepetitions
* @property null|int $recurrence_repetitions_count
* @property Collection|RecurrenceTransaction[] $recurrenceTransactions
* @property null|int $recurrence_transactions_count
* @property TransactionCurrency $transactionCurrency
* @property TransactionType $transactionType
* @property User $user
*
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence newQuery()
* @method static Builder|Recurrence onlyTrashed()
* @method static Builder|Recurrence onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence query()
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereApplyRules($value)
@@ -86,10 +87,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereTransactionTypeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUserId($value)
* @method static Builder|Recurrence withTrashed()
* @method static Builder|Recurrence withoutTrashed()
* @property int $user_group_id
* @method static Builder|Recurrence withTrashed()
* @method static Builder|Recurrence withoutTrashed()
*
* @property int $user_group_id
*
* @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUserGroupId($value)
*
* @mixin Eloquent
*/
class Recurrence extends Model
@@ -98,7 +102,6 @@ class Recurrence extends Model
use ReturnsIntegerUserIdTrait;
use SoftDeletes;
protected $casts
= [
'created_at' => 'datetime',
@@ -117,43 +120,38 @@ class Recurrence extends Model
protected $fillable
= ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active'];
/** @var string The table to store the data in */
protected $table = 'recurrences';
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
* @param string $value
*
* @return Recurrence
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$recurrenceId = (int)$value;
/** @var User $user */
$user = auth()->user();
/** @var Recurrence|null $recurrence */
/** @var null|Recurrence $recurrence */
$recurrence = $user->recurrences()->find($recurrenceId);
if (null !== $recurrence) {
return $recurrence;
}
}
throw new NotFoundHttpException();
}
/**
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
@@ -167,53 +165,35 @@ class Recurrence extends Model
return $this->morphMany(Note::class, 'noteable');
}
/**
* @return HasMany
*/
public function recurrenceMeta(): HasMany
{
return $this->hasMany(RecurrenceMeta::class);
}
/**
* @return HasMany
*/
public function recurrenceRepetitions(): HasMany
{
return $this->hasMany(RecurrenceRepetition::class);
}
/**
* @return HasMany
*/
public function recurrenceTransactions(): HasMany
{
return $this->hasMany(RecurrenceTransaction::class);
}
/**
* @return BelongsTo
*/
public function transactionCurrency(): BelongsTo
{
return $this->belongsTo(TransactionCurrency::class);
}
/**
* @return BelongsTo
*/
public function transactionType(): BelongsTo
{
return $this->belongsTo(TransactionType::class);
}
/**
* @return Attribute
*/
protected function transactionTypeId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
get: static fn ($value) => (int)$value,
);
}
}