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 |
||
81 | public function analyzeController(string $controllerInstanceName) : array |
||
82 | { |
||
83 | // Let's analyze the controller and get all the @Action annotations: |
||
84 | $urlsList = array(); |
||
85 | |||
86 | $controller = $this->container->get($controllerInstanceName); |
||
87 | |||
88 | $refClass = new \ReflectionClass($controller); |
||
89 | |||
90 | foreach ($refClass->getMethods() as $refMethod) { |
||
91 | $title = null; |
||
92 | // Now, let's check the "Title" annotation (note: we do not support multiple title annotations for the same method) |
||
93 | $titleAnnotation = $this->annotationReader->getMethodAnnotation($refMethod, Title::class); |
||
94 | if ($titleAnnotation !== null) { |
||
95 | /* @var $titleAnnotation TitleAnnotation */ |
||
96 | $title = $titleAnnotation->getTitle(); |
||
97 | } |
||
98 | |||
99 | // First, let's check the "Action" annotation |
||
100 | $actionAnnotation = $this->annotationReader->getMethodAnnotation($refMethod, Action::class); |
||
101 | if ($actionAnnotation !== null) { |
||
102 | $methodName = $refMethod->getName(); |
||
103 | if ($methodName === 'index') { |
||
104 | $url = $controllerInstanceName.'/'; |
||
105 | } else { |
||
106 | $url = $controllerInstanceName.'/'.$methodName; |
||
107 | } |
||
108 | $parameters = $this->parameterFetcherRegistry->mapParameters($refMethod); |
||
109 | $filters = FilterUtils::getFilters($refMethod, $this->annotationReader); |
||
110 | $urlsList[] = new SplashRoute($url, $controllerInstanceName, $refMethod->getName(), $title, $refMethod->getDocComment(), $this->getSupportedHttpMethods($refMethod), $parameters, $filters, $refClass->getFileName()); |
||
111 | } |
||
112 | |||
113 | // Now, let's check the "URL" annotation (note: we support multiple URL annotations for the same method) |
||
114 | $annotations = $this->annotationReader->getMethodAnnotations($refMethod); |
||
115 | |||
116 | foreach ($annotations as $annotation) { |
||
117 | if (!$annotation instanceof URL) { |
||
118 | continue; |
||
119 | } |
||
120 | |||
121 | /* @var $annotation URL */ |
||
122 | $url = $annotation->getUrl(); |
||
123 | |||
124 | // Get public properties if they exist in the URL |
||
125 | if (preg_match_all('/[^{]*{\$this->([^\/]*)}[^{]*/', $url, $output)) { |
||
126 | foreach ($output[1] as $param) { |
||
127 | $value = $this->readPrivateProperty($controller, $param); |
||
128 | $url = str_replace('{$this->'.$param.'}', $value, $url); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | $url = ltrim($url, '/'); |
||
133 | $parameters = $this->parameterFetcherRegistry->mapParameters($refMethod, $url); |
||
134 | $filters = FilterUtils::getFilters($refMethod, $this->annotationReader); |
||
135 | $urlsList[] = new SplashRoute($url, $controllerInstanceName, $refMethod->getName(), $title, $refMethod->getDocComment(), $this->getSupportedHttpMethods($refMethod), $parameters, $filters, $refClass->getFileName()); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | return $urlsList; |
||
140 | } |
||
141 | |||
197 |
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.