Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
UserAngelType
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 getPivotAttributes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 angelType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 confirmUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIsConfirmedAttribute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Models;
6
7use Engelsystem\Models\User\User;
8use Engelsystem\Models\User\UsesUserModel;
9use Illuminate\Database\Eloquent\Builder;
10use Illuminate\Database\Eloquent\Factories\HasFactory;
11use Illuminate\Database\Eloquent\Relations\BelongsTo;
12use Illuminate\Database\Eloquent\Relations\Pivot;
13use Illuminate\Database\Query\Builder as QueryBuilder;
14
15/**
16 * @mixin Builder
17 *
18 * @property int            $id
19 * @property int            $angel_type_id
20 * @property int|null       $confirm_user_id
21 * @property bool           $supporter
22 *
23 * @property-read AngelType $angelType
24 * @property-read User|null $confirmUser
25 * @property-read bool      $isConfirmed
26 *
27 * @method static QueryBuilder|UserAngelType[] whereId($value)
28 * @method static QueryBuilder|UserAngelType[] whereAngelTypeId($value)
29 * @method static QueryBuilder|UserAngelType[] whereConfirmUserId($value)
30 * @method static QueryBuilder|UserAngelType[] whereSupporter($value)
31 */
32class UserAngelType extends Pivot
33{
34    use HasFactory;
35    use UsesUserModel;
36
37    /** @var bool Increment the IDs */
38    public $incrementing = true; // phpcs:ignore
39
40    /** @var bool Disable timestamps */
41    public $timestamps = false; // phpcs:ignore
42
43    /** @var array<string, null|bool> default attributes */
44    protected $attributes = [ // phpcs:ignore
45        'confirm_user_id' => null,
46        'supporter'       => false,
47    ];
48
49    /** @var array<string> */
50    protected $fillable = [ // phpcs:ignore
51        'user_id',
52        'angel_type_id',
53        'confirm_user_id',
54        'supporter',
55    ];
56
57    /** @var array<string> */
58    protected $casts = [ // phpcs:ignore
59        'user_id'         => 'integer',
60        'angel_type_id'   => 'integer',
61        'confirm_user_id' => 'integer',
62        'supporter'       => 'boolean',
63    ];
64
65    /**
66     * Returns a list of attributes that can be requested for this pivot table
67     *
68     * @return string[]
69     */
70    public static function getPivotAttributes(): array
71    {
72        return ['id', 'confirm_user_id', 'supporter'];
73    }
74
75    public function angelType(): BelongsTo
76    {
77        return $this->belongsTo(AngelType::class);
78    }
79
80    public function confirmUser(): BelongsTo
81    {
82        return $this->belongsTo(User::class, 'confirm_user_id');
83    }
84
85    public function getIsConfirmedAttribute(): bool
86    {
87        return !$this->angelType->restricted || $this->confirm_user_id;
88    }
89}