| Conditions | 16 |
| Paths | 378 |
| Total Lines | 43 |
| Code Lines | 36 |
| 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 |
||
| 38 | protected function parseMethods($methods) { |
||
| 39 | $hasPermission = false; |
||
| 40 | $controllerClass = $this->controllerClass; |
||
| 41 | $controller = ClassUtils::getClassSimpleName($controllerClass); |
||
| 42 | foreach ($methods as $method) { |
||
| 43 | $action = $method->name; |
||
| 44 | $permission = 'ALL'; |
||
| 45 | if ($method->getDeclaringClass()->getName() === $controllerClass) { |
||
| 46 | try { |
||
| 47 | $annotResource = Reflexion::getAnnotationMethod($controllerClass, $action, '@resource'); |
||
|
|
|||
| 48 | $annotPermission = Reflexion::getAnnotationMethod($controllerClass, $action, '@permission'); |
||
| 49 | $annotsAllow = Reflexion::getAnnotationsMethod($controllerClass, $action, '@allow'); |
||
| 50 | if (isset($annotResource)) { |
||
| 51 | $resource = $annotResource->name; |
||
| 52 | AclManager::addResource($annotResource->name, $controller . '.' . $action); |
||
| 53 | } |
||
| 54 | if (isset($annotPermission)) { |
||
| 55 | $permission = $annotPermission->name; |
||
| 56 | AclManager::addPermission($annotPermission->name, $annotPermission->level); |
||
| 57 | $hasPermission = true; |
||
| 58 | $this->permissionMap->addAction($controller, $action, $annotResource ?? ($this->mainResource ? $this->mainResource->name : $controller . '.' . $action), $annotPermission->name); |
||
| 59 | } elseif (isset($annotResource)) { |
||
| 60 | $this->permissionMap->addAction($controller, $action, $annotResource, 'ALL'); |
||
| 61 | } |
||
| 62 | $annotsAllow = Reflexion::getAnnotationsMethod($controllerClass, $method, '@allow'); |
||
| 63 | if (count($annotsAllow) > 0) { |
||
| 64 | $this->addAllows($annotsAllow, $controller, $action, $resource, $permission); |
||
| 65 | } |
||
| 66 | } catch (\Exception $e) {} |
||
| 67 | } |
||
| 68 | } |
||
| 69 | if ($hasPermission || $this->mainResource != null || $this->mainPermission != null) { |
||
| 70 | $permission = 'ALL'; |
||
| 71 | $resource = $this->mainResource ? $this->mainResource->name : $controller; |
||
| 72 | $this->permissionMap->addAction($controller, '*', $resource, $this->mainPermission ? $this->mainPermission->name : 'ALL'); |
||
| 73 | AclManager::addResource($resource, $controller . '.*'); |
||
| 74 | if (isset($this->mainPermission)) { |
||
| 75 | $permission = $this->mainPermission->name; |
||
| 76 | AclManager::addPermission($this->mainPermission->name, ($this->mainPermission->level) ?? 0); |
||
| 77 | } |
||
| 78 | $annotsAllow = $annotsAllow = Reflexion::getAnnotationClass($controllerClass, '@allow'); |
||
| 79 | if (count($annotsAllow) > 0) { |
||
| 80 | $this->addAllows($annotsAllow, $controller, '*', $resource, $permission); |
||
| 81 | } |
||
| 127 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.