bristol-su /
assign-roles
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace BristolSU\Module\AssignRoles\Rules; |
||
| 4 | |||
| 5 | use BristolSU\ControlDB\Contracts\Models\Group; |
||
| 6 | use BristolSU\ControlDB\Contracts\Models\User; |
||
| 7 | use BristolSU\ControlDB\Contracts\Repositories\User as UserRepository; |
||
| 8 | use BristolSU\Support\Authentication\Contracts\Authentication; |
||
| 9 | use Illuminate\Contracts\Validation\Rule; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Is the user a member of the group |
||
| 13 | * |
||
| 14 | * @package BristolSU\Module\AssignRoles\Rules |
||
| 15 | */ |
||
|
0 ignored issues
–
show
|
|||
| 16 | class UserBelongsToGroup implements Rule |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
|
0 ignored issues
–
show
|
|||
| 20 | * @var Authentication |
||
| 21 | */ |
||
| 22 | private $authentication; |
||
|
0 ignored issues
–
show
|
|||
| 23 | /** |
||
|
0 ignored issues
–
show
|
|||
| 24 | * @var UserRepository |
||
| 25 | */ |
||
| 26 | private $userRepository; |
||
|
0 ignored issues
–
show
|
|||
| 27 | |||
| 28 | 7 | public function __construct(Authentication $authentication, UserRepository $userRepository) |
|
|
0 ignored issues
–
show
|
|||
| 29 | { |
||
| 30 | 7 | $this->authentication = $authentication; |
|
| 31 | 7 | $this->userRepository = $userRepository; |
|
| 32 | 7 | } |
|
| 33 | |||
| 34 | /** |
||
|
0 ignored issues
–
show
|
|||
| 35 | * @inheritDoc |
||
| 36 | */ |
||
|
0 ignored issues
–
show
|
|||
| 37 | 7 | public function passes($attribute, $value) |
|
| 38 | { |
||
| 39 | 7 | $user = app(UserRepository::class)->getById((int) $value); |
|
|
0 ignored issues
–
show
|
|||
| 40 | 7 | $groupToMatch = $this->group(); |
|
| 41 | return $this->userRepository->getById($value)->groups()->filter(function(Group $group) use ($groupToMatch) { |
||
|
0 ignored issues
–
show
|
|||
| 42 | 6 | return $group->id() === $groupToMatch->id(); |
|
| 43 | 7 | })->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.
Loading history...
|
|||
| 44 | } |
||
| 45 | |||
| 46 | 7 | protected function group() |
|
|
0 ignored issues
–
show
|
|||
| 47 | { |
||
| 48 | 7 | return $this->authentication->getGroup(); |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
|
0 ignored issues
–
show
|
|||
| 52 | * @inheritDoc |
||
| 53 | */ |
||
|
0 ignored issues
–
show
|
|||
| 54 | 1 | public function message() |
|
| 55 | { |
||
| 56 | 1 | return 'The user is not a member of the group'; |
|
| 57 | } |
||
| 58 | } |