Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
State
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
11 / 11
15
100.00% covered (success)
100.00%
1 / 1
 forceActiveBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getForceActiveAttribute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 scopeWhereForceActive
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 forceFoodBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getForceFoodAttribute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 scopeWhereForceFood
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 gotGoodieBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getGotGoodieAttribute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 scopeWhereGotGoodie
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getArrivedAttribute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 scopeWhereArrived
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Models\User;
6
7use Carbon\Carbon;
8use Illuminate\Database\Eloquent\Builder;
9use Illuminate\Database\Eloquent\Factories\HasFactory;
10use Illuminate\Database\Eloquent\Relations\BelongsTo;
11use Illuminate\Database\Query\Builder as QueryBuilder;
12
13/**
14 * @property-read bool   $arrived
15 * @property Carbon|null $arrival_date
16 * @property string|null $user_info
17 * @property bool        $active
18 * @property-read bool   $force_active
19 * @property int|null    $force_active_by
20 * @property-read bool   $force_food
21 * @property int|null    $force_food_by
22 * @property-read bool   $got_goodie
23 * @property int|null    $got_goodie_by
24 * @property int         $got_voucher
25 *
26 * @method static QueryBuilder|State[] whereArrived($value)
27 * @method static QueryBuilder|State[] whereArrivalDate($value)
28 * @method static QueryBuilder|State[] whereUserInfo($value)
29 * @method static QueryBuilder|State[] whereActive($value)
30 * @method static QueryBuilder|State[] whereForceActive($value)
31 * @method static QueryBuilder|State[] whereForceActiveBy($value)
32 * @method static QueryBuilder|State[] whereForceFood($value)
33 * @method static QueryBuilder|State[] whereForceFoodBy($value)
34 * @method static QueryBuilder|State[] whereGotGoodie($value)
35 * @method static QueryBuilder|State[] whereGotGoodieBy($value)
36 * @method static QueryBuilder|State[] whereGotVoucher($value)
37 */
38class State extends HasUserModel
39{
40    use HasFactory;
41
42    /** @var string The table associated with the model */
43    protected $table = 'users_state'; // phpcs:ignore
44
45    /** @var array<string, bool|int|null> Default attributes */
46    protected $attributes = [ // phpcs:ignore
47        'arrival_date' => null,
48        'user_info'    => null,
49        'active'       => false,
50        'force_active_by' => null,
51        'force_food_by' => null,
52        'got_goodie_by'   => null,
53        'got_voucher'  => 0,
54    ];
55
56    /** @var array<string, string> */
57    protected $casts = [ // phpcs:ignore
58        'user_id'      => 'integer',
59        'arrival_date' => 'datetime',
60        'active'       => 'boolean',
61        'force_active_by' => 'integer',
62        'force_food_by'   => 'integer',
63        'got_goodie_by'   => 'integer',
64        'got_voucher'  => 'integer',
65    ];
66
67    /**
68     * The attributes that are mass assignable.
69     *
70     * @var array<string>
71     */
72    protected $fillable = [ // phpcs:ignore
73        'user_id',
74        'arrival_date',
75        'user_info',
76        'active',
77        'force_active_by',
78        'force_food_by',
79        'got_goodie_by',
80        'got_voucher',
81    ];
82
83    public function forceActiveBy(): BelongsTo
84    {
85        return $this->belongsTo(User::class, 'force_active_by');
86    }
87
88    /**
89     * Accessor: for forced_active property
90     * Derived from forced_active_by being not null
91     */
92    public function getForceActiveAttribute(): bool
93    {
94        return $this->force_active_by !== null;
95    }
96
97    /**
98     * provide WhereForceActive query scope
99     */
100    public static function scopeWhereForceActive(Builder $query, bool $value): Builder
101    {
102        return $value
103            ? $query->whereNotNull('force_active_by')
104            : $query->whereNull('force_active_by');
105    }
106
107    public function forceFoodBy(): BelongsTo
108    {
109        return $this->belongsTo(User::class, 'force_food_by');
110    }
111
112    /**
113     * Accessor: for forced_food property
114     * Derived from forced_food_by being not null
115     */
116    public function getForceFoodAttribute(): bool
117    {
118        return $this->force_food_by !== null;
119    }
120
121    /**
122     * provide WhereForceFood query scope
123     */
124    public static function scopeWhereForceFood(Builder $query, bool $value): Builder
125    {
126        return $value
127            ? $query->whereNotNull('force_food_by')
128            : $query->whereNull('force_food_by');
129    }
130
131    public function gotGoodieBy(): BelongsTo
132    {
133        return $this->belongsTo(User::class, 'got_goodie_by');
134    }
135
136    /**
137     * Accessor: for got_goodie property
138     * Derived from got_goodie_by being not null
139     */
140    public function getGotGoodieAttribute(): bool
141    {
142        return $this->got_goodie_by !== null;
143    }
144
145    /**
146     * provide WhereGotGoodie query scope
147     */
148    public static function scopeWhereGotGoodie(Builder $query, bool $value): Builder
149    {
150        return $value
151            ? $query->whereNotNull('got_goodie_by')
152            : $query->whereNull('got_goodie_by');
153    }
154
155    /**
156     * Accessor: for arrived property
157     * Derived from arrival_date being not null
158     */
159    public function getArrivedAttribute(): bool
160    {
161        return $this->arrival_date !== null;
162    }
163
164    /**
165     * provide WhereArrived query scope
166     */
167    public static function scopeWhereArrived(Builder $query, bool $value): Builder
168    {
169        return $value
170            ? $query->whereNotNull('arrival_date')
171            : $query->whereNull('arrival_date');
172    }
173}