UserProfile::setGroups()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace App\Models;
4
5
/**
6
 * Class UserProfile.
7
 */
8
class UserProfile
9
{
10
    /**
11
     * User Data.
12
     *
13
     * @var User
14
     */
15
    public $user;
16
17
    /**
18
     * User Friends.
19
     *
20
     * @var UserFriend[]|array
21
     */
22
    public $friends = [];
23
24
    /**
25
     * User Badges.
26
     *
27
     * @var UserBadge[]|array
28
     */
29
    public $badges = [];
30
31
    /**
32
     * User Groups.
33
     *
34
     * @var UserGroup[]|array
35
     */
36
    public $groups = [];
37
38
    /**
39
     * User Rooms.
40
     *
41
     * @var Room[]|array
42
     */
43
    public $rooms = [];
44
45
    /**
46
     * UserProfile constructor.
47
     *
48
     * @param User $userData
49
     *
50
     * @return UserProfile
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
51
     */
52
    public function __construct(User $userData)
53
    {
54
        $this->setUser($userData);
55
56
        $this->setFriends();
57
        $this->setBadges();
58
        $this->setGroups();
59
        $this->setRooms();
60
61
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
62
    }
63
64
    /**
65
     * Set User Data.
66
     *
67
     * @param User $userData
68
     */
69
    protected function setUser(User $userData)
70
    {
71
        $this->user = $userData;
72
    }
73
74
    /**
75
     * Set User Friends.
76
     */
77
    protected function setFriends()
78
    {
79
        $this->friends = UserFriend::where('user_one_id', $this->user->uniqueId)->get() ?? [];
80
    }
81
82
    /**
83
     * Set User Badges.
84
     */
85
    protected function setBadges()
86
    {
87
        $this->badges = UserBadge::where('user_id', $this->user->uniqueId)->get() ?? [];
88
    }
89
90
    /**
91
     * Set User Groups.
92
     */
93
    protected function setGroups()
94
    {
95
        $groups = GroupMember::where('user_id', $this->user->uniqueId)->get() ?? [];
96
97
        foreach ($groups as $group) {
98
            $this->groups[] = $group->guild;
99
        }
100
    }
101
102
    /**
103
     * Set User Rooms.
104
     */
105
    public function setRooms()
106
    {
107
        $this->rooms = Room::where('owner_id', $this->user->uniqueId)->where('state', '!=', 'invisible')->get() ?? [];
108
    }
109
}
110