| Conditions | 10 |
| Paths | 23 |
| Total Lines | 49 |
| Code Lines | 30 |
| 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 |
||
| 69 | public function addAdminClassAces( |
||
| 70 | OutputInterface $output, |
||
| 71 | AclInterface $acl, |
||
| 72 | AclSecurityHandlerInterface $securityHandler, |
||
| 73 | array $roleInformation = [] |
||
| 74 | ) { |
||
| 75 | if (count($securityHandler->getAdminPermissions()) > 0) { |
||
| 76 | $builder = new $this->maskBuilderClass(); |
||
| 77 | |||
| 78 | foreach ($roleInformation as $role => $permissions) { |
||
| 79 | $aceIndex = $securityHandler->findClassAceIndexByRole($acl, $role); |
||
| 80 | $roleAdminPermissions = []; |
||
| 81 | |||
| 82 | foreach ($permissions as $permission) { |
||
| 83 | // add only the admin permissions |
||
| 84 | if (in_array($permission, $securityHandler->getAdminPermissions())) { |
||
| 85 | $builder->add($permission); |
||
| 86 | $roleAdminPermissions[] = $permission; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if (count($roleAdminPermissions) > 0) { |
||
| 91 | if (false === $aceIndex) { |
||
| 92 | $acl->insertClassAce(new RoleSecurityIdentity($role), $builder->get()); |
||
| 93 | $action = 'add'; |
||
| 94 | } else { |
||
| 95 | $acl->updateClassAce($aceIndex, $builder->get()); |
||
| 96 | $action = 'update'; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (null !== $output) { |
||
| 100 | $output->writeln(sprintf(' - %s role: %s, permissions: %s', $action, $role, json_encode($roleAdminPermissions))); |
||
| 101 | } |
||
| 102 | |||
| 103 | $builder->reset(); |
||
| 104 | } elseif (false !== $aceIndex) { |
||
| 105 | $acl->deleteClassAce($aceIndex); |
||
| 106 | |||
| 107 | if (null !== $output) { |
||
| 108 | $output->writeln(sprintf(' - remove role: %s', $role)); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return true; |
||
| 114 | } |
||
| 115 | |||
| 116 | return false; |
||
| 117 | } |
||
| 118 | } |
||
| 119 |