| Conditions | 11 |
| Paths | 24 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 72 | public function addAdminClassAces( |
||
| 73 | OutputInterface $output, |
||
| 74 | AclInterface $acl, |
||
| 75 | AclSecurityHandlerInterface $securityHandler, |
||
| 76 | array $roleInformation = [] |
||
| 77 | ) { |
||
| 78 | if (!$acl instanceof MutableAclInterface) { |
||
| 79 | throw new \InvalidArgumentException('$acl must implement '.MutableAclInterface::class); |
||
| 80 | } |
||
| 81 | if (\count($securityHandler->getAdminPermissions()) > 0) { |
||
| 82 | $builder = new $this->maskBuilderClass(); |
||
| 83 | |||
| 84 | foreach ($roleInformation as $role => $permissions) { |
||
| 85 | $aceIndex = $securityHandler->findClassAceIndexByRole($acl, $role); |
||
| 86 | $roleAdminPermissions = []; |
||
| 87 | |||
| 88 | foreach ($permissions as $permission) { |
||
| 89 | // add only the admin permissions |
||
| 90 | if (\in_array($permission, $securityHandler->getAdminPermissions(), true)) { |
||
| 91 | $builder->add($permission); |
||
| 92 | $roleAdminPermissions[] = $permission; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if (\count($roleAdminPermissions) > 0) { |
||
| 97 | if (false === $aceIndex) { |
||
| 98 | $acl->insertClassAce(new RoleSecurityIdentity($role), $builder->get()); |
||
| 99 | $action = 'add'; |
||
| 100 | } else { |
||
| 101 | $acl->updateClassAce($aceIndex, $builder->get()); |
||
| 102 | $action = 'update'; |
||
| 103 | } |
||
| 104 | |||
| 105 | if (null !== $output) { |
||
| 106 | $output->writeln(sprintf(' - %s role: %s, permissions: %s', $action, $role, json_encode($roleAdminPermissions))); |
||
| 107 | } |
||
| 108 | |||
| 109 | $builder->reset(); |
||
| 110 | } elseif (false !== $aceIndex) { |
||
| 111 | $acl->deleteClassAce($aceIndex); |
||
| 112 | |||
| 113 | if (null !== $output) { |
||
| 114 | $output->writeln(sprintf(' - remove role: %s', $role)); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | return true; |
||
| 120 | } |
||
| 121 | |||
| 122 | return false; |
||
| 123 | } |
||
| 124 | } |
||
| 125 |