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\Module\AssignRoles\Support\PositionSettingRetrieval; |
||||
| 6 | use BristolSU\Support\Authentication\Contracts\Authentication; |
||||
| 7 | use Illuminate\Contracts\Validation\Rule; |
||||
| 8 | |||||
| 9 | class PositionIsAllowed implements Rule |
||||
|
0 ignored issues
–
show
|
|||||
| 10 | { |
||||
| 11 | |||||
| 12 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 13 | * @var PositionSettingRetrieval |
||||
| 14 | */ |
||||
| 15 | private $positionSettingRetrieval; |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 17 | * @var Authentication |
||||
| 18 | */ |
||||
| 19 | private $authentication; |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | |||||
| 21 | 11 | public function __construct(PositionSettingRetrieval $positionSettingRetrieval, Authentication $authentication) |
|||
|
0 ignored issues
–
show
|
|||||
| 22 | { |
||||
| 23 | 11 | $this->positionSettingRetrieval = $positionSettingRetrieval; |
|||
| 24 | 11 | $this->authentication = $authentication; |
|||
| 25 | 11 | } |
|||
| 26 | |||||
| 27 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 28 | * @inheritDoc |
||||
| 29 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | 10 | public function passes($attribute, $value) |
|||
| 31 | { |
||||
| 32 | try { |
||||
| 33 | 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...
|
|||||
| 34 | } catch (\Exception $e) { |
||||
| 35 | return false; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | 10 | return in_array($value, $settings['allowed']); |
|||
| 39 | } |
||||
| 40 | |||||
| 41 | 10 | protected function group() |
|||
|
0 ignored issues
–
show
|
|||||
| 42 | { |
||||
| 43 | 10 | return $this->authentication->getGroup(); |
|||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 47 | * @inheritDoc |
||||
| 48 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | 1 | public function message() |
|||
| 50 | { |
||||
| 51 | 1 | return 'The position is not available to use'; |
|||
| 52 | } |
||||
| 53 | } |