Conditions | 19 |
Paths | 289 |
Total Lines | 88 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
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 |
||
230 | private function buildText(array $routes, int $indent = 0, string $parent = '') |
||
231 | { |
||
232 | $templateContent = ''; |
||
233 | $fallback = ''; |
||
234 | foreach ($routes as $route_key => $route) { |
||
235 | if ('' !== $parent) { |
||
236 | $parent .= '.'; |
||
237 | } |
||
238 | $parent .= (true === isset($route['prefix'])) ? $route['prefix'] : ''; |
||
239 | $templateString = ''; |
||
240 | $tabs = (true === isset($route['prefix'])) ? (($indent * 3) + 3) : 0; |
||
241 | if (true === isset($route['custom'])) { |
||
242 | foreach ($route['custom'] as $custom_key => $custom) { |
||
243 | if (true === isset($custom['function']) && '' !== $custom['function']) { |
||
244 | $custom['function'] = '@'.$custom['function']; |
||
245 | } |
||
246 | $vars = [ |
||
247 | '$ITERATION_CUSTOM_METHOD$' => $custom['method'], |
||
248 | '$ITERATION_CUSTOM_ENDPOINT$' => $custom['endpoint'], |
||
249 | '$ITERATION_CUSTOM_CONTROLLER$' => $custom['controller'], |
||
250 | '$ITERATION_CUSTOM_FUNCTION$' => $custom['function'], |
||
251 | '$ITERATION_CUSTOM_NAME$' => $custom['name'], |
||
252 | '$INDENT$' => infy_tabs($tabs), |
||
253 | ]; |
||
254 | $templateString .= get_artomator_template('scaffold.routes.prefixed.custom'); |
||
255 | $templateString = fill_template($vars, $templateString); |
||
256 | } |
||
257 | } |
||
258 | if (isset($route['resources'])) { |
||
259 | $tabs = (isset($route['prefix'])) ? (($indent * 3) + 3) : 0; |
||
260 | foreach ($route['resources'] as $resource_key => $only) { |
||
261 | if ('' === $fallback) { |
||
262 | $fallback = $parent.'.'.Str::lower($resource_key).'.index'; |
||
263 | } |
||
264 | |||
265 | if ($resource_key !== $only) { |
||
266 | $only = '->only([\''.implode('\', \'', explode(',', $only)).'\'])'; |
||
267 | } else { |
||
268 | $only = ''; |
||
269 | } |
||
270 | |||
271 | $className = $parent; |
||
272 | $className .= (true === isset($route['prefix'])) ? '.'.$route['prefix'] : ''; |
||
273 | $className .= '.'.$resource_key; |
||
274 | $className = explode('.', $className); |
||
275 | foreach ($className as &$path) { |
||
276 | $path = ucfirst($path); |
||
277 | } |
||
278 | $className = implode('\\', $className); |
||
279 | |||
280 | $this->classNames[] = $className; |
||
281 | |||
282 | $vars = [ |
||
283 | '$ITERATION_MODEL_NAME_PLURAL_CAMEL$' => Str::camel(Str::plural($resource_key)), |
||
284 | '$ITERATION_MODEL_NAME$' => $resource_key, |
||
285 | '$ITERATION_ONLY$' => $only, |
||
286 | '$INDENT$' => infy_tabs($tabs), |
||
287 | ]; |
||
288 | $templateString .= get_artomator_template('scaffold.routes.prefixed.route'); |
||
289 | $templateString = fill_template($vars, $templateString); |
||
290 | } |
||
291 | } |
||
292 | if (true === (isset($route['group']))) { |
||
293 | $templateString .= $this->buildText($route['group'], ($indent + 1), $parent); |
||
294 | } |
||
295 | if (true === (isset($route['prefix']))) { |
||
296 | $vars = [ |
||
297 | '$ITERATION_NAMESPACE_CAMEL$' => ucfirst($route_key), |
||
298 | '$ITERATION_NAMESPACE_LOWER$' => strtolower($route_key), |
||
299 | '$FALLBACK_ROUTE$' => $fallback, |
||
300 | '$INDENT$' => infy_tabs($indent * 3), |
||
301 | ]; |
||
302 | if ('' !== $fallback) { |
||
303 | $fallback_tmp = get_artomator_template('scaffold.routes.prefixed.fallback'); |
||
304 | } else { |
||
305 | $fallback_tmp = ''; |
||
306 | } |
||
307 | $templateString = get_artomator_template('scaffold.routes.prefixed.namespace') |
||
308 | .$templateString |
||
309 | .$fallback_tmp |
||
310 | .get_artomator_template('scaffold.routes.prefixed.closure'); |
||
311 | |||
312 | $templateString = fill_template($vars, $templateString); |
||
313 | } |
||
314 | $templateContent .= $templateString; |
||
315 | } |
||
316 | |||
317 | return $templateContent; |
||
318 | } |
||
343 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..