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\Repositories\Role; |
||
| 6 | use Illuminate\Contracts\Validation\Rule; |
||
| 7 | |||
| 8 | class RoleHasNoUsersAssigned implements Rule |
||
|
0 ignored issues
–
show
|
|||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
|
0 ignored issues
–
show
|
|||
| 12 | * @var Role |
||
| 13 | */ |
||
| 14 | private $roleRepository; |
||
|
0 ignored issues
–
show
|
|||
| 15 | |||
| 16 | 4 | public function __construct(Role $roleRepository) |
|
|
0 ignored issues
–
show
|
|||
| 17 | { |
||
| 18 | 4 | $this->roleRepository = $roleRepository; |
|
| 19 | 4 | } |
|
| 20 | |||
| 21 | /** |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @inheritDoc |
||
| 23 | */ |
||
|
0 ignored issues
–
show
|
|||
| 24 | 4 | public function passes($attribute, $value) |
|
| 25 | { |
||
| 26 | 4 | $role = $this->roleRepository->getById($value); |
|
| 27 | 4 | return $role->users()->count() === 0; |
|
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
|
0 ignored issues
–
show
|
|||
| 31 | * @inheritDoc |
||
| 32 | */ |
||
|
0 ignored issues
–
show
|
|||
| 33 | 1 | public function message() |
|
| 34 | { |
||
| 35 | 1 | return 'The role still has users assigned'; |
|
| 36 | } |
||
| 37 | } |