People   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 7
eloc 21
c 3
b 2
f 0
dl 0
loc 96
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A newEloquentBuilder() 0 3 1
A address() 0 3 1
A age() 0 4 1
A query() 0 3 1
A getNameFullAttribute() 0 3 1
A getNameLastFirstAttribute() 0 3 1
A newFactory() 0 3 1
1
<?php
2
3
namespace Sfneal\Testing\Models;
4
5
use Database\Factories\PeopleFactory;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Casts\Attribute;
8
use Illuminate\Database\Eloquent\Factories\HasFactory;
9
use Illuminate\Database\Eloquent\Relations\MorphOne;
10
use Sfneal\Address\Models\Address;
11
use Sfneal\Builders\QueryBuilder;
12
use Sfneal\Models\Model;
13
14
class People extends Model
15
{
16
    use HasFactory;
17
18
    /**
19
     * The attributes that should be mutated to dates.
20
     *
21
     * @var array
22
     */
23
    protected $dates = ['deleted_at', 'updated_at', 'created_at'];
24
25
    protected $table = 'people';
26
    protected $primaryKey = 'person_id';
27
28
    protected $fillable = [
29
        'person_id',
30
        'name_first',
31
        'name_last',
32
        'email',
33
        'age',
34
    ];
35
36
    protected $appends = [
37
        'name_full',
38
    ];
39
40
    /**
41
     * Model Factory.
42
     *
43
     * @return PeopleFactory
44
     */
45
    protected static function newFactory(): PeopleFactory
46
    {
47
        return new PeopleFactory();
48
    }
49
50
    /**
51
     * Query Builder.
52
     *
53
     * @param  $query
54
     * @return QueryBuilder
55
     */
56
    public function newEloquentBuilder($query)
57
    {
58
        return new QueryBuilder($query);
59
    }
60
61
    /**
62
     * Query Builder method for improved type hinting.
63
     *
64
     * @return QueryBuilder|Builder
65
     */
66
    public static function query()
67
    {
68
        return parent::query();
69
    }
70
71
    /**
72
     * User's address.
73
     *
74
     * @return MorphOne
75
     */
76
    public function address()
77
    {
78
        return $this->morphOne(Address::class, 'addressable');
79
    }
80
81
    /**
82
     * Retrieve the 'name_full' attribute.
83
     *
84
     * @return string
85
     */
86
    public function getNameFullAttribute(): string
87
    {
88
        return $this->attributes['name_first'].' '.$this->attributes['name_last'];
89
    }
90
91
    /**
92
     * Retrieve the 'name_last_first' attribute.
93
     *
94
     * @return string
95
     */
96
    public function getNameLastFirstAttribute(): string
97
    {
98
        return $this->attributes['name_last'].', '.$this->attributes['name_first'];
99
    }
100
101
    /**
102
     * Retrieve the 'age' attribute.
103
     *
104
     * @return Attribute
105
     */
106
    public function age(): Attribute
107
    {
108
        return Attribute::make(
109
            get: fn ($value) => intval($value)
110
        );
111
    }
112
}
113