| Conditions | 7 |
| Paths | 7 |
| Total Lines | 70 |
| Code Lines | 42 |
| 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 |
||
| 35 | public function read(string $class, string $defaultController = 'Home', string $defaultMethod = 'index'): array |
||
| 36 | { |
||
| 37 | $reflection = new ReflectionClass($class); |
||
| 38 | |||
| 39 | if ($reflection->isAbstract()) { |
||
| 40 | return []; |
||
| 41 | } |
||
| 42 | |||
| 43 | $classname = $reflection->getName(); |
||
| 44 | $classShortname = $reflection->getShortName(); |
||
| 45 | |||
| 46 | $output = []; |
||
| 47 | $uriByClass = $this->getUriByClass($classname); |
||
| 48 | |||
| 49 | if ($this->hasRemap($reflection)) { |
||
| 50 | $methodName = '_remap'; |
||
| 51 | |||
| 52 | $routeWithoutController = $this->getRouteWithoutController( |
||
| 53 | $classShortname, |
||
| 54 | $defaultController, |
||
| 55 | $uriByClass, |
||
| 56 | $classname, |
||
| 57 | $methodName |
||
| 58 | ); |
||
| 59 | $output = [...$output, ...$routeWithoutController]; |
||
| 60 | |||
| 61 | $output[] = [ |
||
| 62 | 'route' => $uriByClass . '[/...]', |
||
| 63 | 'handler' => '\\' . $classname . '::' . $methodName, |
||
| 64 | ]; |
||
| 65 | |||
| 66 | return $output; |
||
| 67 | } |
||
| 68 | |||
| 69 | foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { |
||
| 70 | $methodName = $method->getName(); |
||
| 71 | |||
| 72 | $route = $uriByClass . '/' . $methodName; |
||
| 73 | |||
| 74 | // Exclut BaseController et initialize |
||
| 75 | if (preg_match('#\AbaseController.*#', $route) === 1) { |
||
| 76 | continue; |
||
| 77 | } |
||
| 78 | if (preg_match('#.*/initialize\z#', $route) === 1) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($methodName === $defaultMethod) { |
||
| 83 | $routeWithoutController = $this->getRouteWithoutController( |
||
| 84 | $classShortname, |
||
| 85 | $defaultController, |
||
| 86 | $uriByClass, |
||
| 87 | $classname, |
||
| 88 | $methodName |
||
| 89 | ); |
||
| 90 | $output = [...$output, ...$routeWithoutController]; |
||
| 91 | |||
| 92 | $output[] = [ |
||
| 93 | 'route' => $uriByClass, |
||
| 94 | 'handler' => '\\' . $classname . '::' . $methodName, |
||
| 95 | ]; |
||
| 96 | } |
||
| 97 | |||
| 98 | $output[] = [ |
||
| 99 | 'route' => $route . '[/...]', |
||
| 100 | 'handler' => '\\' . $classname . '::' . $methodName, |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | |||
| 104 | return $output; |
||
| 105 | } |
||
| 170 |