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

@@ -40,28 +40,29 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\Rule
*
* @property int $id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property int $user_id
* @property int $rule_group_id
* @property string $title
* @property string|null $description
* @property int $order
* @property bool $active
* @property bool $stop_processing
* @property bool $strict
* @property-read string $action_value
* @property-read Collection|RuleAction[] $ruleActions
* @property-read int|null $rule_actions_count
* @property-read RuleGroup $ruleGroup
* @property Collection|RuleTrigger[] $ruleTriggers
* @property-read int|null $rule_triggers_count
* @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 $rule_group_id
* @property string $title
* @property null|string $description
* @property int $order
* @property bool $active
* @property bool $stop_processing
* @property bool $strict
* @property string $action_value
* @property Collection|RuleAction[] $ruleActions
* @property null|int $rule_actions_count
* @property RuleGroup $ruleGroup
* @property Collection|RuleTrigger[] $ruleTriggers
* @property null|int $rule_triggers_count
* @property User $user
*
* @method static \Illuminate\Database\Eloquent\Builder|Rule newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Rule newQuery()
* @method static Builder|Rule onlyTrashed()
* @method static Builder|Rule onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Rule query()
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereCreatedAt($value)
@@ -75,11 +76,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereUserId($value)
* @method static Builder|Rule withTrashed()
* @method static Builder|Rule withoutTrashed()
* @property int $user_group_id
* @method static Builder|Rule withTrashed()
* @method static Builder|Rule withoutTrashed()
*
* @property int $user_group_id
*
* @method static \Illuminate\Database\Eloquent\Builder|Rule whereUserGroupId($value)
* @property-read UserGroup|null $userGroup
*
* @property null|UserGroup $userGroup
*
* @mixin Eloquent
*/
class Rule extends Model
@@ -88,7 +93,6 @@ class Rule extends Model
use ReturnsIntegerUserIdTrait;
use SoftDeletes;
protected $casts
= [
'created_at' => 'datetime',
@@ -106,53 +110,41 @@ class Rule extends Model
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
* @param string $value
*
* @return Rule
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$ruleId = (int)$value;
/** @var User $user */
$user = auth()->user();
/** @var Rule|null $rule */
/** @var null|Rule $rule */
$rule = $user->rules()->find($ruleId);
if (null !== $rule) {
return $rule;
}
}
throw new NotFoundHttpException();
}
/**
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return HasMany
*/
public function ruleActions(): HasMany
{
return $this->hasMany(RuleAction::class);
}
/**
* @return BelongsTo
*/
public function ruleGroup(): BelongsTo
{
return $this->belongsTo(RuleGroup::class);
}
/**
* @return HasMany
*/
public function ruleTriggers(): HasMany
{
return $this->hasMany(RuleTrigger::class);
@@ -160,39 +152,28 @@ class Rule extends Model
/**
* @param mixed $value
*
*/
public function setDescriptionAttribute($value): void
{
$this->attributes['description'] = e($value);
}
/**
* @return BelongsTo
*/
public function userGroup(): BelongsTo
{
return $this->belongsTo(UserGroup::class);
}
/**
* @return Attribute
*/
protected function order(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
get: static fn ($value) => (int)$value,
);
}
/**
* @return Attribute
*/
protected function ruleGroupId(): Attribute
{
return Attribute::make(
get: static fn($value) => (int)$value,
get: static fn ($value) => (int)$value,
);
}
}