1 | <?php |
||||
2 | |||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
3 | |||||
4 | namespace BristolSU\ControlDB\Traits; |
||||
5 | |||||
6 | |||||
7 | use BristolSU\ControlDB\Contracts\Models\DataUser; |
||||
8 | use BristolSU\ControlDB\Contracts\Models\Role; |
||||
9 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\UserUserTag; |
||||
10 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup; |
||||
11 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; |
||||
12 | use BristolSU\ControlDB\Contracts\Repositories\User; |
||||
13 | use BristolSU\ControlDB\Models\Group; |
||||
14 | use BristolSU\ControlDB\Models\Tags\UserTag; |
||||
15 | use Illuminate\Support\Collection; |
||||
16 | |||||
17 | /** |
||||
18 | * Implements common methods using repositories required by the user model interface |
||||
19 | */ |
||||
0 ignored issues
–
show
|
|||||
20 | trait UserTrait |
||||
21 | { |
||||
22 | |||||
23 | /** |
||||
24 | * Get the attributes for this user |
||||
25 | * |
||||
26 | * @return DataUser |
||||
27 | */ |
||||
28 | 15 | public function data(): DataUser { |
|||
0 ignored issues
–
show
|
|||||
29 | 15 | return app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->getById($this->dataProviderId()); |
|||
0 ignored issues
–
show
It seems like
dataProviderId() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
30 | } |
||||
31 | |||||
32 | /** |
||||
33 | * Set the ID of the data provider |
||||
34 | * |
||||
35 | * @param int $dataProviderId |
||||
0 ignored issues
–
show
|
|||||
36 | */ |
||||
0 ignored issues
–
show
|
|||||
37 | 2 | public function setDataProviderId(int $dataProviderId): void |
|||
38 | { |
||||
39 | 2 | app(User::class)->update($this->id(), $dataProviderId); |
|||
0 ignored issues
–
show
It seems like
id() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
40 | 2 | } |
|||
41 | |||||
42 | /** |
||||
43 | * Tags the user is tagged with |
||||
44 | * |
||||
45 | * @return Collection |
||||
46 | */ |
||||
47 | 2 | public function tags(): Collection |
|||
48 | { |
||||
49 | 2 | return app(UserUserTag::class)->getTagsThroughUser($this); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...g::getTagsThroughUser() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
50 | } |
||||
51 | |||||
52 | /** |
||||
53 | * Roles the user owns |
||||
54 | * |
||||
55 | * @return Collection |
||||
56 | */ |
||||
57 | 2 | public function roles(): Collection |
|||
58 | { |
||||
59 | 2 | return app(UserRole::class)->getRolesThroughUser($this); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...::getRolesThroughUser() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
60 | } |
||||
61 | |||||
62 | /** |
||||
63 | * Groups the user is a member of |
||||
64 | * |
||||
65 | * @return Collection |
||||
66 | */ |
||||
67 | 2 | public function groups(): Collection |
|||
68 | { |
||||
69 | 2 | return app(UserGroup::class)->getGroupsThroughUser($this); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...:getGroupsThroughUser() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
70 | } |
||||
71 | |||||
72 | /** |
||||
73 | * Add a tag to the user |
||||
74 | * |
||||
75 | * @param \BristolSU\ControlDB\Contracts\Models\Tags\UserTag $userTag |
||||
0 ignored issues
–
show
|
|||||
76 | */ |
||||
0 ignored issues
–
show
|
|||||
77 | 6 | public function addTag(\BristolSU\ControlDB\Contracts\Models\Tags\UserTag $userTag): void |
|||
78 | { |
||||
79 | 6 | app(UserUserTag::class)->addTagToUser($userTag, $this); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...UserTag::addTagToUser() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
80 | 6 | } |
|||
81 | |||||
82 | /** |
||||
83 | * Remove a tag from the user |
||||
84 | * |
||||
85 | * @param \BristolSU\ControlDB\Contracts\Models\Tags\UserTag $userTag |
||||
0 ignored issues
–
show
|
|||||
86 | */ |
||||
0 ignored issues
–
show
|
|||||
87 | 2 | public function removeTag(\BristolSU\ControlDB\Contracts\Models\Tags\UserTag $userTag): void |
|||
88 | { |
||||
89 | 2 | app(UserUserTag::class)->removeTagFromUser($userTag, $this); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...ag::removeTagFromUser() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
90 | 2 | } |
|||
91 | |||||
92 | /** |
||||
93 | * Add a role to the user |
||||
94 | * |
||||
95 | * @param Role $role |
||||
0 ignored issues
–
show
|
|||||
96 | */ |
||||
0 ignored issues
–
show
|
|||||
97 | 5 | public function addRole(Role $role): void |
|||
98 | { |
||||
99 | 5 | app(UserRole::class)->addUserToRole($this, $role); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...erRole::addUserToRole() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
100 | 5 | } |
|||
101 | |||||
102 | /** |
||||
103 | * Remove a role from the user |
||||
104 | * |
||||
105 | * @param Role $role |
||||
0 ignored issues
–
show
|
|||||
106 | */ |
||||
0 ignored issues
–
show
|
|||||
107 | 2 | public function removeRole(Role $role): void |
|||
108 | { |
||||
109 | 2 | app(UserRole::class)->removeUserFromRole($this, $role); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...e::removeUserFromRole() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
110 | 2 | } |
|||
111 | |||||
112 | /** |
||||
113 | * Add a group to the user |
||||
114 | * |
||||
115 | * @param \BristolSU\ControlDB\Contracts\Models\Group $group |
||||
0 ignored issues
–
show
|
|||||
116 | */ |
||||
0 ignored issues
–
show
|
|||||
117 | 5 | public function addGroup(\BristolSU\ControlDB\Contracts\Models\Group $group): void |
|||
118 | { |
||||
119 | 5 | app(UserGroup::class)->addUserToGroup($this, $group); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...Group::addUserToGroup() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
120 | 5 | } |
|||
121 | |||||
122 | /** |
||||
123 | * Remove a group from the user |
||||
124 | * |
||||
125 | * @param \BristolSU\ControlDB\Contracts\Models\Group $group |
||||
0 ignored issues
–
show
|
|||||
126 | */ |
||||
0 ignored issues
–
show
|
|||||
127 | 2 | public function removeGroup(\BristolSU\ControlDB\Contracts\Models\Group $group): void |
|||
128 | { |
||||
129 | 2 | app(UserGroup::class)->removeUserFromGroup($this, $group); |
|||
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\UserTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\User expected by parameter $user of BristolSU\ControlDB\Cont...::removeUserFromGroup() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
130 | 2 | } |
|||
131 | |||||
132 | |||||
133 | } |