1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\Module\AssignRoles\Rules; |
||
4 | |||
5 | use BristolSU\ControlDB\Contracts\Models\Role; |
||
6 | use BristolSU\ControlDB\Contracts\Repositories\User; |
||
7 | use Illuminate\Contracts\Validation\Rule; |
||
8 | |||
9 | class UserBelongsToRole implements Rule |
||
0 ignored issues
–
show
|
|||
10 | { |
||
11 | |||
12 | /** |
||
0 ignored issues
–
show
|
|||
13 | * @var Role |
||
14 | */ |
||
15 | private $role; |
||
0 ignored issues
–
show
|
|||
16 | /** |
||
0 ignored issues
–
show
|
|||
17 | * @var User |
||
18 | */ |
||
19 | private $userRepository; |
||
0 ignored issues
–
show
|
|||
20 | /** |
||
0 ignored issues
–
show
|
|||
21 | * @var int |
||
22 | */ |
||
23 | private $roleId; |
||
0 ignored issues
–
show
|
|||
24 | |||
25 | 6 | public function __construct(int $roleId, User $userRepository) |
|
0 ignored issues
–
show
|
|||
26 | { |
||
27 | 6 | $this->roleId = $roleId; |
|
28 | 6 | $this->userRepository = $userRepository; |
|
29 | 6 | $this->roleId = $roleId; |
|
30 | 6 | } |
|
31 | |||
32 | /** |
||
0 ignored issues
–
show
|
|||
33 | * @inheritDoc |
||
34 | */ |
||
0 ignored issues
–
show
|
|||
35 | 6 | public function passes($attribute, $value) |
|
36 | { |
||
37 | return $this->userRepository->getById($value)->roles()->filter(function(Role $role) { |
||
0 ignored issues
–
show
|
|||
38 | 5 | return $role->id() === $this->roleId; |
|
39 | 6 | })->count() > 0; |
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
40 | } |
||
41 | |||
42 | /** |
||
0 ignored issues
–
show
|
|||
43 | * @inheritDoc |
||
44 | */ |
||
0 ignored issues
–
show
|
|||
45 | 1 | public function message() |
|
46 | { |
||
47 | 1 | return 'The user does not belong to the role'; |
|
48 | } |
||
49 | } |