Passed
Push — master ( f9e565...1be325 )
by Stephen
02:48
created

People::address()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
use Sfneal\Address\Models\Address;
10
use Sfneal\Builders\QueryBuilder;
11
use Sfneal\Models\Model;
12
13
class People extends Model
14
{
15
    use HasFactory;
16
17
    /**
18
     * The attributes that should be mutated to dates.
19
     *
20
     * @var array
21
     */
22
    protected $dates = ['deleted_at', 'updated_at', 'created_at'];
23
24
    protected $table = 'people';
25
    protected $primaryKey = 'person_id';
26
27
    protected $fillable = [
28
        'person_id',
29
        'name_first',
30
        'name_last',
31
        'email',
32
        'age',
33
    ];
34
35
    /**
36
     * Model Factory.
37
     *
38
     * @return PeopleFactory
39
     */
40
    protected static function newFactory(): PeopleFactory
41
    {
42
        return new PeopleFactory();
43
    }
44
45
    /**
46
     * Query Builder.
47
     *
48
     * @param $query
49
     * @return QueryBuilder
50
     */
51
    public function newEloquentBuilder($query)
52
    {
53
        return new QueryBuilder($query);
54
    }
55
56
    /**
57
     * Query Builder method for improved type hinting.
58
     *
59
     * @return QueryBuilder|Builder
60
     */
61
    public static function query()
62
    {
63
        return parent::query();
64
    }
65
66
    /**
67
     * User's address.
68
     *
69
     * @return MorphOne|Address
70
     */
71
    public function address()
72
    {
73
        return $this->morphOne(Address::class, 'addressable');
74
    }
75
76
    /**
77
     * Retrieve the 'name_full' attribute.
78
     *
79
     * @return string
80
     */
81
    public function getNameFullAttribute(): string
82
    {
83
        return "{$this->name_first} {$this->name_last}";
0 ignored issues
show
Bug introduced by
The property name_last does not seem to exist on Sfneal\Testing\Models\People. 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...
Bug introduced by
The property name_first does not seem to exist on Sfneal\Testing\Models\People. 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...
84
    }
85
86
    /**
87
     * Retrieve the 'name_last_first' attribute.
88
     *
89
     * @return string
90
     */
91
    public function getNameLastFirstAttribute(): string
92
    {
93
        return "{$this->name_last}, {$this->name_first}";
0 ignored issues
show
Bug introduced by
The property name_last does not seem to exist on Sfneal\Testing\Models\People. 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...
Bug introduced by
The property name_first does not seem to exist on Sfneal\Testing\Models\People. 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...
94
    }
95
96
    /**
97
     * Retrieve the 'age' attribute
98
     *
99
     * @param $value
100
     * @return int
101
     */
102
    public function getAgeAttribute($value): int
103
    {
104
        return intval($value);
105
    }
106
}
107