Conditions | 9 |
Paths | 5 |
Total Lines | 28 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
26 | public static function getNamesForPermissions(AuthorizationInterface $authorization, array $permissions): array |
||
27 | { |
||
28 | $type = $authorization->getAuthorizationType(); |
||
29 | |||
30 | // special case all permissions are granted |
||
31 | if ( |
||
32 | ($type == AuthorizationInterface::AUTH_TYPE_GLOBAL || $type == AuthorizationInterface::AUTH_TYPE_GRANT) |
||
33 | && $authorization->isEveryPermissionGranted() |
||
34 | ) { |
||
35 | return [ Permissions::all()->getName() ]; |
||
36 | } |
||
37 | |||
38 | // special case all permissions are revoked |
||
39 | if ($type == Authorization::AUTH_TYPE_REVOKE && $authorization->isEveryPermissionRevoked()) { |
||
40 | return [ Permissions::all()->getName() ]; |
||
41 | } |
||
42 | |||
43 | $names = []; |
||
44 | |||
45 | foreach ($permissions as $permission) { |
||
46 | $name = $permission->getName(); |
||
47 | // filter NONE and ALL from permissions array |
||
48 | if ($name != Permissions::none()->getName() && $name != Permissions::all()->getName()) { |
||
49 | $names[] = $name; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | return $names; |
||
54 | } |
||
56 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: