UserFriend::getNameAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
/**
6
 * Class UserFriend.
7
 */
8
class UserFriend extends ChocolateyModel
9
{
10
    /**
11
     * Disable Timestamps.
12
     *
13
     * @var bool
14
     */
15
    public $timestamps = false;
16
17
    /**
18
     * The table associated with the model.
19
     *
20
     * @var string
21
     */
22
    protected $table = 'messenger_friendships';
23
24
    /**
25
     * Primary Key of the Table.
26
     *
27
     * @var string
28
     */
29
    protected $primaryKey = 'id';
30
31
    /**
32
     * User Friend Data.
33
     *
34
     * @var User
35
     */
36
    protected $friendData;
37
38
    /**
39
     * The attributes excluded from the model's JSON form.
40
     *
41
     * @var array
42
     */
43
    protected $hidden = ['user_one_id', 'user_two_id', 'relation', 'friends_since'];
44
45
    /**
46
     * The Appender(s) of the Model.
47
     *
48
     * @var array
49
     */
50
    protected $appends = ['figureString', 'motto', 'name', 'uniqueId'];
51
52
    /**
53
     * Get User Friend Figure String.
54
     *
55
     * @return string
56
     */
57
    public function getFigureStringAttribute(): string
58
    {
59
        return $this->getUserFriendData()->figureString;
60
    }
61
62
    /**
63
     * Get User Friend Data.
64
     *
65
     * @return User
66
     */
67
    protected function getUserFriendData(): User
68
    {
69
        return User::find($this->attributes['user_two_id']);
70
    }
71
72
    /**
73
     * Get User Friend Motto.
74
     *
75
     * @return string
76
     */
77
    public function getMottoAttribute(): string
78
    {
79
        return $this->getUserFriendData()->motto;
80
    }
81
82
    /**
83
     * Get User Friend Name.
84
     *
85
     * @return string
86
     */
87
    public function getNameAttribute(): string
88
    {
89
        return $this->getUserFriendData()->name;
90
    }
91
92
    /**
93
     * Get User Friend UniqueId.
94
     *
95
     * @return int
96
     */
97
    public function getUniqueIdAttribute(): int
98
    {
99
        return $this->getUserFriendData()->uniqueId;
100
    }
101
}
102