Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Question
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 answerer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 unanswered
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 answered
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Models;
6
7use Carbon\Carbon;
8use Engelsystem\Models\User\User;
9use Engelsystem\Models\User\UsesUserModel;
10use Illuminate\Database\Eloquent\Builder;
11use Illuminate\Database\Eloquent\Factories\HasFactory;
12use Illuminate\Database\Eloquent\Relations\BelongsTo;
13use Illuminate\Database\Query\Builder as QueryBuilder;
14
15/**
16 * @property int         $id
17 * @property string      $text
18 * @property string|null $answer
19 * @property int|null    $answerer_id
20 * @property Carbon|null $answered_at
21 * @property Carbon|null $created_at
22 * @property Carbon|null $updated_at
23 *
24 * @property-read User|null $answerer
25 *
26 * @method static Builder|Question whereAnswer($value)
27 * @method static Builder|Question whereAnswererId($value)
28 * @method static Builder|Question whereId($value)
29 * @method static Builder|Question whereQuestion($value)
30 */
31class Question extends BaseModel
32{
33    use HasFactory;
34    use UsesUserModel;
35
36    /** @var bool Enable timestamps */
37    public $timestamps = true; // phpcs:ignore
38
39    /** @var array<string, null> default attributes */
40    protected $attributes = [ // phpcs:ignore
41        'answer'      => null,
42        'answerer_id' => null,
43        'answered_at' => null,
44    ];
45
46    /** @var array<string> */
47    protected $fillable = [ // phpcs:ignore
48        'user_id',
49        'text',
50        'answerer_id',
51        'answer',
52        'answered_at',
53    ];
54
55    /** @var array<string, string> */
56    protected $casts = [ // phpcs:ignore
57        'user_id'     => 'integer',
58        'answerer_id' => 'integer',
59        'answered_at' => 'datetime',
60    ];
61
62    public function answerer(): BelongsTo
63    {
64        return $this->belongsTo(User::class, 'answerer_id');
65    }
66
67    public static function unanswered(): Builder
68    {
69        return static::whereAnswererId(null);
70    }
71
72    public static function answered(): Builder | QueryBuilder
73    {
74        return static::whereNotNull('answerer_id');
75    }
76}