Conditions | 13 |
Paths | 21 |
Total Lines | 36 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
129 | public function check(ResourceAI $identity): bool |
||
130 | { |
||
131 | if (!empty($this->onRole)) { |
||
132 | $role = $identity->getRole(); |
||
133 | if ($role === null || !isset($this->onRole[$role])) { |
||
134 | return false; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | if ($this->everybody === true) { |
||
139 | return true; |
||
140 | } |
||
141 | |||
142 | if ($this->onOwn === true) { |
||
143 | $CU = $identity->getUser(); |
||
144 | $owner = $identity->getOwner(); |
||
145 | if ($CU !== null && $owner !== null && $CU->getId() === $owner) { |
||
146 | return true; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | if (!empty($this->asRole)) { |
||
151 | $CU = $identity->getUser(); |
||
152 | if ($CU !== null) { |
||
153 | // @td Attach to CU |
||
154 | $roles = Registry::get('Permissions')->getRoles(); |
||
155 | $allRoles = $roles->get($CU->getRole()); |
||
156 | foreach ($allRoles as $role) { |
||
157 | if (isset($this->asRole[$role])) { |
||
158 | return true; |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 | |||
164 | return false; |
||
165 | } |
||
178 |