bristol-su /
control
| 1 | <?php |
||||||||
| 2 | |||||||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||||||
| 3 | |||||||||
| 4 | namespace BristolSU\ControlDB\Traits; |
||||||||
| 5 | |||||||||
| 6 | |||||||||
| 7 | use BristolSU\ControlDB\Contracts\Models\DataRole as DataRoleModel; |
||||||||
| 8 | use BristolSU\ControlDB\Contracts\Models\User; |
||||||||
| 9 | use BristolSU\ControlDB\Contracts\Repositories\DataRole as DataRoleRepository; |
||||||||
| 10 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\RoleRoleTag; |
||||||||
| 11 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; |
||||||||
| 12 | use BristolSU\ControlDB\Contracts\Repositories\Role; |
||||||||
| 13 | use BristolSU\ControlDB\Models\Group; |
||||||||
| 14 | use BristolSU\ControlDB\Models\Position; |
||||||||
| 15 | use Illuminate\Support\Collection; |
||||||||
| 16 | |||||||||
| 17 | /** |
||||||||
| 18 | * Implements common methods using repositories required by the role model interface |
||||||||
| 19 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 20 | trait RoleTrait |
||||||||
| 21 | { |
||||||||
| 22 | |||||||||
| 23 | /** |
||||||||
| 24 | * Get the data attributes of the role |
||||||||
| 25 | * |
||||||||
| 26 | * @return DataRoleModel |
||||||||
| 27 | */ |
||||||||
| 28 | 16 | public function data(): DataRoleModel |
|||||||
| 29 | { |
||||||||
| 30 | 16 | return app(DataRoleRepository::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
Loading history...
|
|||||||||
| 31 | } |
||||||||
| 32 | |||||||||
| 33 | /** |
||||||||
| 34 | * Set the ID of the data provider |
||||||||
| 35 | * |
||||||||
| 36 | * @param int $dataProviderId |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 37 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 38 | 2 | public function setDataProviderId(int $dataProviderId): void |
|||||||
| 39 | { |
||||||||
| 40 | 2 | app(Role::class)->update($this->id(), $this->positionId(), $this->groupId(), $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
Loading history...
The method
groupId() does not exist on BristolSU\ControlDB\Traits\RoleTrait. Did you maybe mean group()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
positionId() does not exist on BristolSU\ControlDB\Traits\RoleTrait. Did you maybe mean position()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||
| 41 | 2 | } |
|||||||
| 42 | |||||||||
| 43 | /** |
||||||||
| 44 | * Set a group ID |
||||||||
| 45 | * |
||||||||
| 46 | * @param int $groupId |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 47 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 48 | 2 | public function setGroupId(int $groupId): void |
|||||||
| 49 | { |
||||||||
| 50 | 2 | app(Role::class)->update($this->id(), $this->positionId(), $groupId, $this->dataProviderId()); |
|||||||
| 51 | 2 | } |
|||||||
| 52 | |||||||||
| 53 | /** |
||||||||
| 54 | * Set a position ID |
||||||||
| 55 | * |
||||||||
| 56 | * @param int $positionId |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 57 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 58 | 2 | public function setPositionId(int $positionId): void |
|||||||
| 59 | { |
||||||||
| 60 | 2 | app(Role::class)->update($this->id(), $positionId, $this->groupId(), $this->dataProviderId()); |
|||||||
| 61 | 2 | } |
|||||||
| 62 | |||||||||
| 63 | /** |
||||||||
| 64 | * Position belonging to the role |
||||||||
| 65 | * |
||||||||
| 66 | * @return Position |
||||||||
| 67 | */ |
||||||||
| 68 | 2 | public function position(): \BristolSU\ControlDB\Contracts\Models\Position |
|||||||
| 69 | { |
||||||||
| 70 | 2 | return app(\BristolSU\ControlDB\Contracts\Repositories\Position::class)->getById($this->positionId()); |
|||||||
| 71 | } |
||||||||
| 72 | |||||||||
| 73 | /** |
||||||||
| 74 | * Group belonging to the role |
||||||||
| 75 | * |
||||||||
| 76 | * @return Group |
||||||||
| 77 | */ |
||||||||
| 78 | 2 | public function group(): \BristolSU\ControlDB\Contracts\Models\Group |
|||||||
| 79 | { |
||||||||
| 80 | 2 | return app(\BristolSU\ControlDB\Contracts\Repositories\Group::class)->getById($this->groupId()); |
|||||||
| 81 | } |
||||||||
| 82 | |||||||||
| 83 | /** |
||||||||
| 84 | * Users who occupy the role |
||||||||
| 85 | * |
||||||||
| 86 | * @return Collection |
||||||||
| 87 | */ |
||||||||
| 88 | 3 | public function users(): Collection |
|||||||
| 89 | { |
||||||||
| 90 | 3 | return app(UserRole::class)->getUsersThroughRole($this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role of BristolSU\ControlDB\Cont...::getUsersThroughRole().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 91 | } |
||||||||
| 92 | |||||||||
| 93 | /** |
||||||||
| 94 | * Tags the role is tagged with |
||||||||
| 95 | * |
||||||||
| 96 | * @return Collection |
||||||||
| 97 | */ |
||||||||
| 98 | 2 | public function tags(): Collection |
|||||||
| 99 | { |
||||||||
| 100 | 2 | return app(RoleRoleTag::class)->getTagsThroughRole($this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role of BristolSU\ControlDB\Cont...g::getTagsThroughRole().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 101 | } |
||||||||
| 102 | |||||||||
| 103 | /** |
||||||||
| 104 | * Add a tag to the role |
||||||||
| 105 | * |
||||||||
| 106 | * @param \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag $roleTag |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 107 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 108 | 6 | public function addTag(\BristolSU\ControlDB\Contracts\Models\Tags\RoleTag $roleTag): void |
|||||||
| 109 | { |
||||||||
| 110 | 6 | app(RoleRoleTag::class)->addTagToRole($roleTag, $this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role of BristolSU\ControlDB\Cont...RoleTag::addTagToRole().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 111 | 6 | } |
|||||||
| 112 | |||||||||
| 113 | /** |
||||||||
| 114 | * Remove a tag from the role |
||||||||
| 115 | * |
||||||||
| 116 | * @param \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag $roleTag |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 117 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 118 | 2 | public function removeTag(\BristolSU\ControlDB\Contracts\Models\Tags\RoleTag $roleTag): void |
|||||||
| 119 | { |
||||||||
| 120 | 2 | app(RoleRoleTag::class)->removeTagFromRole($roleTag, $this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role of BristolSU\ControlDB\Cont...ag::removeTagFromRole().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 121 | 2 | } |
|||||||
| 122 | |||||||||
| 123 | /** |
||||||||
| 124 | * Add a user to the role |
||||||||
| 125 | * |
||||||||
| 126 | * @param User $user |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 127 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 128 | 5 | public function addUser(User $user): void |
|||||||
| 129 | { |
||||||||
| 130 | 5 | app(UserRole::class)->addUserToRole($user, $this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role 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
Loading history...
|
|||||||||
| 131 | 5 | } |
|||||||
| 132 | |||||||||
| 133 | /** |
||||||||
| 134 | * Remove a user from the role |
||||||||
| 135 | * |
||||||||
| 136 | * @param User $user |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 137 | */ |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 138 | 2 | public function removeUser(User $user): void |
|||||||
| 139 | { |
||||||||
| 140 | 2 | app(UserRole::class)->removeUserFromRole($user, $this); |
|||||||
|
0 ignored issues
–
show
$this of type BristolSU\ControlDB\Traits\RoleTrait is incompatible with the type BristolSU\ControlDB\Contracts\Models\Role expected by parameter $role 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
Loading history...
|
|||||||||
| 141 | 2 | } |
|||||||
| 142 | |||||||||
| 143 | } |