Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| State | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| getArrivedAttribute | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scopeWhereArrived | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Engelsystem\Models\User; |
| 6 | |
| 7 | use Carbon\Carbon; |
| 8 | use Illuminate\Database\Eloquent\Builder; |
| 9 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 10 | use Illuminate\Database\Query\Builder as QueryBuilder; |
| 11 | |
| 12 | /** |
| 13 | * @property-read bool $arrived |
| 14 | * @property Carbon|null $arrival_date |
| 15 | * @property string|null $user_info |
| 16 | * @property bool $active |
| 17 | * @property bool $force_active |
| 18 | * @property bool $force_food |
| 19 | * @property bool $got_goodie |
| 20 | * @property int $got_voucher |
| 21 | * |
| 22 | * @method static QueryBuilder|State[] whereArrived($value) |
| 23 | * @method static QueryBuilder|State[] whereArrivalDate($value) |
| 24 | * @method static QueryBuilder|State[] whereUserInfo($value) |
| 25 | * @method static QueryBuilder|State[] whereActive($value) |
| 26 | * @method static QueryBuilder|State[] whereForceActive($value) |
| 27 | * @method static QueryBuilder|State[] whereForceFood($value) |
| 28 | * @method static QueryBuilder|State[] whereGotGoodie($value) |
| 29 | * @method static QueryBuilder|State[] whereGotVoucher($value) |
| 30 | */ |
| 31 | class State extends HasUserModel |
| 32 | { |
| 33 | use HasFactory; |
| 34 | |
| 35 | /** @var string The table associated with the model */ |
| 36 | protected $table = 'users_state'; // phpcs:ignore |
| 37 | |
| 38 | /** @var array<string, bool|int|null> Default attributes */ |
| 39 | protected $attributes = [ // phpcs:ignore |
| 40 | 'arrival_date' => null, |
| 41 | 'user_info' => null, |
| 42 | 'active' => false, |
| 43 | 'force_active' => false, |
| 44 | 'force_food' => false, |
| 45 | 'got_goodie' => false, |
| 46 | 'got_voucher' => 0, |
| 47 | ]; |
| 48 | |
| 49 | /** @var array<string, string> */ |
| 50 | protected $casts = [ // phpcs:ignore |
| 51 | 'user_id' => 'integer', |
| 52 | 'arrival_date' => 'datetime', |
| 53 | 'active' => 'boolean', |
| 54 | 'force_active' => 'boolean', |
| 55 | 'force_food' => 'boolean', |
| 56 | 'got_goodie' => 'boolean', |
| 57 | 'got_voucher' => 'integer', |
| 58 | ]; |
| 59 | |
| 60 | /** |
| 61 | * The attributes that are mass assignable. |
| 62 | * |
| 63 | * @var array<string> |
| 64 | */ |
| 65 | protected $fillable = [ // phpcs:ignore |
| 66 | 'user_id', |
| 67 | 'arrival_date', |
| 68 | 'user_info', |
| 69 | 'active', |
| 70 | 'force_active', |
| 71 | 'force_food', |
| 72 | 'got_goodie', |
| 73 | 'got_voucher', |
| 74 | ]; |
| 75 | |
| 76 | /** |
| 77 | * Accessor: for arrived property |
| 78 | * Derived from arrival_date being not null |
| 79 | */ |
| 80 | public function getArrivedAttribute(): bool |
| 81 | { |
| 82 | return $this->arrival_date !== null; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * provide WhereArrived query scope |
| 87 | */ |
| 88 | public static function scopeWhereArrived(Builder $query, bool $value): Builder |
| 89 | { |
| 90 | return $value |
| 91 | ? $query->whereNotNull('arrival_date') |
| 92 | : $query->whereNull('arrival_date'); |
| 93 | } |
| 94 | } |