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\Role; |
||||
| 6 | use BristolSU\ControlDB\Contracts\Repositories\User; |
||||
| 7 | use BristolSU\Module\AssignRoles\Support\PositionSettingRetrieval; |
||||
| 8 | use BristolSU\Support\Authentication\Contracts\Authentication; |
||||
| 9 | use BristolSU\Support\Logic\Contracts\LogicRepository; |
||||
| 10 | use BristolSU\Support\Logic\Facade\LogicTester; |
||||
| 11 | use Illuminate\Contracts\Validation\Rule; |
||||
| 12 | |||||
| 13 | /** |
||||
| 14 | * Is the user available to be assigned? |
||||
| 15 | * |
||||
| 16 | * If the user belongs to a user, which has a position that is 'user only has one user', they will not be available |
||||
| 17 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 18 | class UserIsAvailableToBeAssigned implements Rule |
||||
| 19 | { |
||||
| 20 | |||||
| 21 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 22 | * @var PositionSettingRetrieval |
||||
| 23 | */ |
||||
| 24 | private $positionSettingRetrieval; |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 26 | * @var Authentication |
||||
| 27 | */ |
||||
| 28 | private $authentication; |
||||
|
0 ignored issues
–
show
|
|||||
| 29 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | * @var User |
||||
| 31 | */ |
||||
| 32 | private $userRepository; |
||||
|
0 ignored issues
–
show
|
|||||
| 33 | |||||
| 34 | 7 | public function __construct(Authentication $authentication, PositionSettingRetrieval $positionSettingRetrieval, User $userRepository) |
|||
|
0 ignored issues
–
show
|
|||||
| 35 | { |
||||
| 36 | 7 | $this->positionSettingRetrieval = $positionSettingRetrieval; |
|||
| 37 | 7 | $this->authentication = $authentication; |
|||
| 38 | 7 | $this->userRepository = $userRepository; |
|||
| 39 | 7 | } |
|||
| 40 | |||||
| 41 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 42 | * @inheritDoc |
||||
| 43 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 44 | 7 | public function passes($attribute, $value) |
|||
| 45 | { |
||||
| 46 | try { |
||||
| 47 | 7 | $settings = $this->positionSettingRetrieval->getSettings($this->group()); |
|||
|
0 ignored issues
–
show
It seems like
$this->group() can also be of type null; however, parameter $group of BristolSU\Module\AssignR...etrieval::getSettings() does only seem to accept BristolSU\ControlDB\Contracts\Models\Group, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 48 | } catch (\Exception $e) { |
||||
| 49 | return false; |
||||
| 50 | } |
||||
| 51 | 7 | $user = $this->userRepository->getById($value); |
|||
| 52 | |||||
| 53 | return $user->roles()->filter(function(Role $role) use ($settings, $user) { |
||||
|
0 ignored issues
–
show
|
|||||
| 54 | 1 | return in_array($role->id(), $settings['user_only_has_one_role']); |
|||
| 55 | 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...
|
|||||
| 56 | } |
||||
| 57 | |||||
| 58 | 7 | protected function group() |
|||
|
0 ignored issues
–
show
|
|||||
| 59 | { |
||||
| 60 | 7 | return $this->authentication->getGroup(); |
|||
| 61 | } |
||||
| 62 | |||||
| 63 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 64 | * @inheritDoc |
||||
| 65 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 66 | 1 | public function message() |
|||
| 67 | { |
||||
| 68 | 1 | return 'The user is already in a role'; |
|||
| 69 | } |
||||
| 70 | } |
||||
| 71 |