Passed
Push — main ( 9da855...5626b3 )
by Thierry
12:12 queued 05:12
created

Round   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 35
c 2
b 0
f 0
dl 0
loc 132
rs 10
wmc 16

16 Methods

Rating   Name   Duplication   Size   Complexity  
A pending() 0 4 1
A opened() 0 4 1
A guild() 0 3 1
A end() 0 4 1
A startDate() 0 4 1
A funds() 0 3 1
A closed() 0 4 1
A addDefaultFund() 0 4 1
A start() 0 4 1
A endDate() 0 4 1
A charges() 0 3 1
A members() 0 3 1
A sessions() 0 3 1
A pools() 0 3 1
A bills() 0 3 1
A receivables() 0 3 1
1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Illuminate\Database\Eloquent\Casts\Attribute;
6
7
class Round extends Base
8
{
9
    use Traits\DateFormatter;
10
    use Traits\HasProperty;
0 ignored issues
show
introduced by
The trait Siak\Tontine\Model\Traits\HasProperty requires some properties which are not provided by Siak\Tontine\Model\Round: $property, $content
Loading history...
11
12
    /**
13
     * @const
14
     */
15
    const STATUS_PENDING = 0;
16
17
    /**
18
     * @const
19
     */
20
    const STATUS_OPENED = 1;
21
22
    /**
23
     * @const
24
     */
25
    const STATUS_CLOSED = 2;
26
27
    /**
28
     * Indicates if the model should be timestamped.
29
     *
30
     * @var bool
31
     */
32
    public $timestamps = false;
33
34
    /**
35
     * The attributes that are mass assignable.
36
     *
37
     * @var array
38
     */
39
    protected $fillable = [
40
        'title',
41
        'status',
42
        'notes',
43
    ];
44
45
    public function start(): Attribute
46
    {
47
        return Attribute::make(
48
            get: fn() => $this->sessions()->orderBy('day_date')->first(),
49
        );
50
    }
51
52
    public function startDate(): Attribute
53
    {
54
        return Attribute::make(
55
            get: fn() => $this->start?->day_date ?? null,
0 ignored issues
show
Bug introduced by
The property start does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
        );
57
    }
58
59
    public function end(): Attribute
60
    {
61
        return Attribute::make(
62
            get: fn() => $this->sessions()->orderByDesc('day_date')->first(),
63
        );
64
    }
65
66
    public function endDate(): Attribute
67
    {
68
        return Attribute::make(
69
            get: fn() => $this->end?->day_date ?? null,
0 ignored issues
show
Bug introduced by
The property end does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
        );
71
    }
72
73
    public function pending(): Attribute
74
    {
75
        return Attribute::make(
76
            get: fn() => $this->status === self::STATUS_PENDING,
77
        );
78
    }
79
80
    public function opened(): Attribute
81
    {
82
        return Attribute::make(
83
            get: fn() => $this->status === self::STATUS_OPENED,
84
        );
85
    }
86
87
    public function closed(): Attribute
88
    {
89
        return Attribute::make(
90
            get: fn() => $this->status === self::STATUS_CLOSED,
91
        );
92
    }
93
94
    public function addDefaultFund(): Attribute
95
    {
96
        return Attribute::make(
97
            get: fn() => $this->properties['savings']['fund']['default'] ?? false,
0 ignored issues
show
Bug introduced by
The property properties does not seem to exist on Siak\Tontine\Model\Round. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
98
        );
99
    }
100
101
    public function guild()
102
    {
103
        return $this->belongsTo(Guild::class);
104
    }
105
106
    public function funds()
107
    {
108
        return $this->hasMany(Fund::class);
109
    }
110
111
    public function charges()
112
    {
113
        return $this->hasMany(Charge::class);
114
    }
115
116
    public function members()
117
    {
118
        return $this->hasMany(Member::class);
119
    }
120
121
    public function pools()
122
    {
123
        return $this->hasMany(Pool::class);
124
    }
125
126
    public function sessions()
127
    {
128
        return $this->hasMany(Session::class);
129
    }
130
131
    public function bills()
132
    {
133
        return $this->hasMany(RoundBill::class);
134
    }
135
136
    public function receivables()
137
    {
138
        return $this->hasManyThrough(Receivable::class, Session::class);
139
    }
140
}
141