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 BristolSU\Module\AssignRoles\Support\PositionSettingRetrieval; |
||||
| 7 | use BristolSU\Support\Authentication\Contracts\Authentication; |
||||
| 8 | use BristolSU\Support\Logic\Contracts\LogicRepository; |
||||
| 9 | use BristolSU\Support\Logic\Facade\LogicTester; |
||||
| 10 | use Illuminate\Contracts\Validation\Rule; |
||||
| 11 | |||||
| 12 | class PositionCanBeUsed implements Rule |
||||
|
0 ignored issues
–
show
|
|||||
| 13 | { |
||||
| 14 | |||||
| 15 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | * @var PositionSettingRetrieval |
||||
| 17 | */ |
||||
| 18 | private $positionSettingRetrieval; |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | * @var Role |
||||
| 21 | */ |
||||
| 22 | private $roleRepository; |
||||
|
0 ignored issues
–
show
|
|||||
| 23 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 24 | * @var Authentication |
||||
| 25 | */ |
||||
| 26 | private $authentication; |
||||
|
0 ignored issues
–
show
|
|||||
| 27 | |||||
| 28 | 11 | public function __construct(PositionSettingRetrieval $positionSettingRetrieval, Role $roleRepository, Authentication $authentication) |
|||
|
0 ignored issues
–
show
|
|||||
| 29 | { |
||||
| 30 | 11 | $this->positionSettingRetrieval = $positionSettingRetrieval; |
|||
| 31 | 11 | $this->roleRepository = $roleRepository; |
|||
| 32 | 11 | $this->authentication = $authentication; |
|||
| 33 | 11 | } |
|||
| 34 | |||||
| 35 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 36 | * @inheritDoc |
||||
| 37 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 38 | 10 | public function passes($attribute, $value) |
|||
| 39 | { |
||||
| 40 | try { |
||||
| 41 | 10 | $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...
|
|||||
| 42 | } catch (\Exception $e) { |
||||
| 43 | return false; |
||||
| 44 | } |
||||
| 45 | 10 | if(in_array($value, $settings['only_one_role'])) { |
|||
|
0 ignored issues
–
show
|
|||||
| 46 | 3 | $roles = $this->roleRepository->allThroughGroup($this->group()); |
|||
|
0 ignored issues
–
show
It seems like
$this->group() can also be of type null; however, parameter $group of BristolSU\ControlDB\Cont...Role::allThroughGroup() 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...
|
|||||
| 47 | |||||
| 48 | return $roles->filter(function(\BristolSU\ControlDB\Contracts\Models\Role $role) use ($value) { |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | 1 | return $role->positionId() === (int) $value; |
|||
| 50 | 3 | })->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...
|
|||||
| 51 | } |
||||
| 52 | 7 | return true; |
|||
| 53 | } |
||||
| 54 | |||||
| 55 | 10 | protected function group() |
|||
|
0 ignored issues
–
show
|
|||||
| 56 | { |
||||
| 57 | 10 | return $this->authentication->getGroup(); |
|||
| 58 | } |
||||
| 59 | |||||
| 60 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 61 | * @inheritDoc |
||||
| 62 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 63 | 1 | public function message() |
|||
| 64 | { |
||||
| 65 | 1 | return 'The position has already been used in another role'; |
|||
| 66 | } |
||||
| 67 | } |