PoolDef   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 99
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A remitAuction() 0 4 1
A depositFixed() 0 4 1
A scopeDepositLendable() 0 3 1
A guild() 0 3 1
A pools() 0 3 1
A casts() 0 4 1
A remitPlanned() 0 4 1
A depositLendable() 0 4 1
A scopeActive() 0 3 1
1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Casts\Attribute;
7
8
class PoolDef extends Base
9
{
10
    /**
11
     * Indicates if the model should be timestamped.
12
     *
13
     * @var bool
14
     */
15
    public $timestamps = false;
16
17
    /**
18
     * The attributes that are mass assignable.
19
     *
20
     * @var array
21
     */
22
    protected $fillable = [
23
        'title',
24
        'amount',
25
        'notes',
26
        'properties',
27
        'active',
28
    ];
29
30
    /**
31
     * The model's default values for attributes.
32
     *
33
     * @var array
34
     */
35
    protected $attributes = [
36
        'properties' => '{}',
37
    ];
38
39
    /**
40
     * Get the attributes that should be cast.
41
     *
42
     * @return array<string, string>
43
     */
44
    protected function casts(): array
45
    {
46
        return [
47
            'properties' => 'array',
48
        ];
49
    }
50
51
    public function depositFixed(): Attribute
52
    {
53
        return Attribute::make(
54
            get: fn() => ($this->properties['deposit']['fixed'] ?? true) === true,
55
        );
56
    }
57
58
    public function depositLendable(): Attribute
59
    {
60
        return Attribute::make(
61
            get: fn() => ($this->properties['deposit']['lendable'] ?? false) === true,
62
        );
63
    }
64
65
    public function remitPlanned(): Attribute
66
    {
67
        return Attribute::make(
68
            get: fn() => ($this->properties['remit']['planned'] ?? true) === true,
69
        );
70
    }
71
72
    public function remitAuction(): Attribute
73
    {
74
        return Attribute::make(
75
            get: fn() => ($this->properties['remit']['auction'] ?? false) === true,
76
        );
77
    }
78
79
    public function pools()
80
    {
81
        return $this->hasMany(Pool::class, 'def_id');
82
    }
83
84
    public function guild()
85
    {
86
        return $this->belongsTo(Guild::class);
87
    }
88
89
    /**
90
     * @param  Builder  $query
91
     *
92
     * @return Builder
93
     */
94
    public function scopeActive(Builder $query): Builder
95
    {
96
        return $query->where('active', true);
97
    }
98
99
    /**
100
     * @param  Builder  $query
101
     *
102
     * @return Builder
103
     */
104
    public function scopeDepositLendable(Builder $query): Builder
105
    {
106
        return $query->where('properties->deposit->lendable', true);
107
    }
108
}
109