Guild   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A pools() 0 3 1
A locale() 0 4 1
A categories() 0 3 1
A newFactory() 0 3 1
A charges() 0 3 1
A user() 0 3 1
A members() 0 3 1
A sessions() 0 4 1
A invites() 0 7 1
A default_fund() 0 4 1
A rounds() 0 3 1
A funds() 0 3 1
1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Database\Factories\GuildFactory;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Casts\Attribute;
8
use Illuminate\Database\Eloquent\Factories\Factory;
9
use Illuminate\Database\Eloquent\Factories\HasFactory;
10
11
class Guild extends Base
12
{
13
    use HasFactory;
14
    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\Guild: $property, $content
Loading history...
15
16
    /**
17
     * True if the guild is accessed as guest.
18
     *
19
     * @var bool
20
     */
21
    public $isGuest = false;
22
23
    /**
24
     * The attributes that are mass assignable.
25
     *
26
     * @var array
27
     */
28
    protected $fillable = [
29
        'name',
30
        'shortname',
31
        'biography',
32
        'email',
33
        'phone',
34
        'address',
35
        'city',
36
        'website',
37
        'country_code',
38
        'currency_code',
39
    ];
40
41
    /**
42
     * @return Attribute
43
     */
44
    protected function locale(): Attribute
45
    {
46
        return Attribute::make(
47
            get: fn() => $this->user->locale,
0 ignored issues
show
Bug introduced by
The property locale does not seem to exist on Siak\Tontine\Model\User. 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...
48
        );
49
    }
50
51
    /**
52
     * Create a new factory instance for the model.
53
     *
54
     * @return Factory
55
     */
56
    protected static function newFactory()
57
    {
58
        return GuildFactory::new();
59
    }
60
61
    public function user()
62
    {
63
        return $this->belongsTo(User::class);
64
    }
65
66
    public function members()
67
    {
68
        return $this->hasMany(MemberDef::class);
69
    }
70
71
    public function rounds()
72
    {
73
        return $this->hasMany(Round::class);
74
    }
75
76
    public function sessions()
77
    {
78
        return $this->hasManyThrough(Session::class, Round::class)
79
            ->select('sessions.*');
80
    }
81
82
    public function pools()
83
    {
84
        return $this->hasMany(PoolDef::class);
85
    }
86
87
    public function funds()
88
    {
89
        return $this->hasMany(FundDef::class);
90
    }
91
92
    /**
93
     * Get the default savings fund.
94
     */
95
    public function default_fund()
96
    {
97
        return $this->hasOne(FundDef::class)
98
            ->ofMany(['id' => 'max'], fn(Builder $query) => $query->auto());
99
    }
100
101
    public function charges()
102
    {
103
        return $this->hasMany(ChargeDef::class);
104
    }
105
106
    public function categories()
107
    {
108
        return $this->hasMany(Category::class);
109
    }
110
111
    public function invites()
112
    {
113
        return $this->belongsToMany(GuestInvite::class,
114
            'guest_options', 'guild_id', 'invite_id')
115
            ->as('options')
116
            ->withPivot('access')
117
            ->using(GuestOptions::class);
118
    }
119
}
120