Conditions | 12 |
Paths | 265 |
Total Lines | 75 |
Code Lines | 32 |
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 |
||
118 | public function findRoutesInPresenter($presenter, & $routes) |
||
119 | { |
||
120 | $r = ClassType::from($presenter); |
||
121 | |||
122 | $route = $this->reader->getClassAnnotation($r, ApiRoute::class); |
||
123 | |||
124 | if (!$route) { |
||
125 | return []; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Add route to priority-sorted list |
||
130 | */ |
||
131 | if (empty($routes[$route->getPriority()])) { |
||
132 | $routes[$route->getPriority()] = []; |
||
133 | } |
||
134 | |||
135 | $route->setDescription($r->getAnnotation('description')); |
||
136 | |||
137 | if (!$route->getPresenter()) { |
||
138 | $route->setPresenter(preg_replace('/Presenter$/', '', $r->getShortName())); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Find apropriate methods |
||
143 | */ |
||
144 | foreach ($r->getMethods() as $method_r) { |
||
145 | $route_action = $this->reader->getMethodAnnotation($method_r, ApiRoute::class); |
||
146 | |||
147 | /** |
||
148 | * Get action without that ^action string |
||
149 | */ |
||
150 | $action = lcfirst(preg_replace('/^action/', '', $method_r->name)); |
||
151 | |||
152 | /** |
||
153 | * Route can be defined also for perticular action |
||
154 | */ |
||
155 | if ($route_action) { |
||
156 | if ($method_r instanceof Nette\Reflection\Method) { |
||
157 | $route_action->setDescription($method_r->getAnnotation('description')); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Action route will inherit presenter name nad priority from parent route |
||
162 | */ |
||
163 | if (!$route_action->getPresenter()) { |
||
164 | $route_action->setPresenter($route->getPresenter()); |
||
165 | } |
||
166 | |||
167 | if (!$route_action->getPriority()) { |
||
168 | $route_action->setPriority($route->getPriority()); |
||
169 | } |
||
170 | |||
171 | if (!$route_action->getFormat()) { |
||
172 | $route_action->setFormat($route->getFormat()); |
||
173 | } |
||
174 | |||
175 | if (!$route_action->getSection()) { |
||
176 | $route_action->setSection($route->getSection()); |
||
177 | } |
||
178 | |||
179 | if ($route_action->getMethod()) { |
||
180 | $route_action->setAction($action, $route_action->getMethod()); |
||
181 | } else { |
||
182 | $route_action->setAction($action); |
||
183 | } |
||
184 | |||
185 | $routes[$route->getPriority()][] = $route_action; |
||
186 | } else { |
||
187 | $route->setAction($action); |
||
188 | } |
||
189 | } |
||
190 | |||
191 | $routes[$route->getPriority()][] = $route; |
||
192 | } |
||
193 | |||
228 |
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.