Conditions | 2 |
Paths | 1 |
Total Lines | 15 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
22 | public static function getScopeRestrictions($subject, string $scope, int $level = null): array |
||
23 | { |
||
24 | $scopes = $subject->roles->flatMap(function ($role) use ($scope, $level) { |
||
25 | if ($level) { |
||
|
|||
26 | $permissions = $role->permissions->where('level', $level); |
||
27 | } else { |
||
28 | $permissions = $role->permissions; |
||
29 | } |
||
30 | |||
31 | return preg_grep("/^${scope}:/", array_column($permissions->toArray(), 'scope')); |
||
32 | })->toArray(); |
||
33 | |||
34 | return array_map(function ($scope) { |
||
35 | return explode(':', $scope)[1]; |
||
36 | }, $scopes); |
||
37 | } |
||
39 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: