| Conditions | 9 |
| Paths | 25 |
| Total Lines | 60 |
| Code Lines | 33 |
| 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 |
||
| 80 | public function analyzeController(string $controllerInstanceName) : array |
||
| 81 | { |
||
| 82 | // Let's analyze the controller and get all the @Action annotations: |
||
| 83 | $urlsList = array(); |
||
| 84 | |||
| 85 | $controller = $this->container->get($controllerInstanceName); |
||
| 86 | |||
| 87 | $refClass = new \ReflectionClass($controller); |
||
| 88 | |||
| 89 | foreach ($refClass->getMethods() as $refMethod) { |
||
| 90 | $title = null; |
||
| 91 | // Now, let's check the "Title" annotation (note: we do not support multiple title annotations for the same method) |
||
| 92 | $titleAnnotation = $this->annotationReader->getMethodAnnotation($refMethod, Title::class); |
||
| 93 | if ($titleAnnotation !== null) { |
||
| 94 | /* @var $titleAnnotation TitleAnnotation */ |
||
| 95 | $title = $titleAnnotation->getTitle(); |
||
| 96 | } |
||
| 97 | |||
| 98 | // First, let's check the "Action" annotation |
||
| 99 | $actionAnnotation = $this->annotationReader->getMethodAnnotation($refMethod, Action::class); |
||
| 100 | if ($actionAnnotation !== null) { |
||
| 101 | $methodName = $refMethod->getName(); |
||
| 102 | if ($methodName === 'index') { |
||
| 103 | $url = $controllerInstanceName.'/'; |
||
| 104 | } else { |
||
| 105 | $url = $controllerInstanceName.'/'.$methodName; |
||
| 106 | } |
||
| 107 | $parameters = $this->parameterFetcherRegistry->mapParameters($refMethod); |
||
| 108 | $filters = FilterUtils::getFilters($refMethod, $this->annotationReader); |
||
| 109 | $urlsList[] = new SplashRoute($url, $controllerInstanceName, $refMethod->getName(), $title, $refMethod->getDocComment(), $this->getSupportedHttpMethods($refMethod), $parameters, $filters); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Now, let's check the "URL" annotation (note: we support multiple URL annotations for the same method) |
||
| 113 | $annotations = $this->annotationReader->getMethodAnnotations($refMethod); |
||
| 114 | |||
| 115 | foreach ($annotations as $annotation) { |
||
| 116 | if (!$annotation instanceof URL) { |
||
| 117 | continue; |
||
| 118 | } |
||
| 119 | |||
| 120 | /* @var $annotation URL */ |
||
| 121 | $url = $annotation->getUrl(); |
||
| 122 | |||
| 123 | // Get public properties if they exist in the URL |
||
| 124 | if (preg_match_all('/[^{]*{\$this->([^\/]*)}[^{]*/', $url, $output)) { |
||
| 125 | foreach ($output[1] as $param) { |
||
| 126 | $value = $this->readPrivateProperty($controller, $param); |
||
| 127 | $url = str_replace('{$this->'.$param.'}', $value, $url); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $url = ltrim($url, '/'); |
||
| 132 | $parameters = $this->parameterFetcherRegistry->mapParameters($refMethod, $url); |
||
| 133 | $filters = FilterUtils::getFilters($refMethod, $this->annotationReader); |
||
| 134 | $urlsList[] = new SplashRoute($url, $controllerInstanceName, $refMethod->getName(), $title, $refMethod->getDocComment(), $this->getSupportedHttpMethods($refMethod), $parameters, $filters); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return $urlsList; |
||
| 139 | } |
||
| 140 | |||
| 186 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.