Conditions | 11 |
Paths | 24 |
Total Lines | 56 |
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 |
||
70 | public function addAdminClassAces( |
||
71 | OutputInterface $output, |
||
72 | AclInterface $acl, |
||
73 | AclSecurityHandlerInterface $securityHandler, |
||
74 | array $roleInformation = [] |
||
75 | ) { |
||
76 | if (!$acl instanceof MutableAclInterface) { |
||
77 | throw new \TypeError(sprintf( |
||
|
|||
78 | 'Argument 2 passed to "%s()" must implement "%s".', |
||
79 | __METHOD__, |
||
80 | MutableAclInterface::class |
||
81 | )); |
||
82 | } |
||
83 | if (\count($securityHandler->getAdminPermissions()) > 0) { |
||
84 | $builder = new $this->maskBuilderClass(); |
||
85 | |||
86 | foreach ($roleInformation as $role => $permissions) { |
||
87 | $aceIndex = $securityHandler->findClassAceIndexByRole($acl, $role); |
||
88 | $roleAdminPermissions = []; |
||
89 | |||
90 | foreach ($permissions as $permission) { |
||
91 | // add only the admin permissions |
||
92 | if (\in_array($permission, $securityHandler->getAdminPermissions(), true)) { |
||
93 | $builder->add($permission); |
||
94 | $roleAdminPermissions[] = $permission; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if (\count($roleAdminPermissions) > 0) { |
||
99 | if (false === $aceIndex) { |
||
100 | $acl->insertClassAce(new RoleSecurityIdentity($role), $builder->get()); |
||
101 | $action = 'add'; |
||
102 | } else { |
||
103 | $acl->updateClassAce($aceIndex, $builder->get()); |
||
104 | $action = 'update'; |
||
105 | } |
||
106 | |||
107 | if (null !== $output) { |
||
108 | $output->writeln(sprintf(' - %s role: %s, permissions: %s', $action, $role, json_encode($roleAdminPermissions))); |
||
109 | } |
||
110 | |||
111 | $builder->reset(); |
||
112 | } elseif (false !== $aceIndex) { |
||
113 | $acl->deleteClassAce($aceIndex); |
||
114 | |||
115 | if (null !== $output) { |
||
116 | $output->writeln(sprintf(' - remove role: %s', $role)); |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
121 | return true; |
||
122 | } |
||
123 | |||
124 | return false; |
||
125 | } |
||
126 | } |
||
127 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.