| Conditions | 16 |
| Paths | 96 |
| Total Lines | 119 |
| 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 |
||
| 100 | /** @var Route $route */ |
||
| 101 | $messageFormat = '%s route: [%s] %s'; |
||
| 102 | $routeMethods = implode(',', $generator->getMethods($route)); |
||
| 103 | $routePath = $generator->getUri($route); |
||
| 104 | |||
| 105 | if (! $this->isValidRoute($route) || ! $this->isRouteVisibleForDocumentation($route->getAction())) { |
||
| 106 | $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath)); |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | try { |
||
| 111 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply'] ?? []); |
||
| 112 | $this->info(sprintf($messageFormat, 'Processed', $routeMethods, $routePath)); |
||
| 113 | } catch (\Exception $exception) { |
||
| 114 | $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath).' - '.$exception->getMessage()); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | return $parsedRoutes; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param Route $route |
||
| 123 | * |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | private function isValidRoute(Route $route) |
||
| 127 | { |
||
| 128 | $action = Utils::getRouteClassAndMethodNames($route->getAction()); |
||
| 129 | if (is_array($action)) { |
||
| 130 | $action = implode('@', $action); |
||
| 131 | } |
||
| 132 | |||
| 133 | return ! is_callable($action) && ! is_null($action); |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param array $action |
||
| 138 | * |
||
| 139 | * @throws ReflectionException |
||
| 140 | * |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | private function isRouteVisibleForDocumentation(array $action) |
||
| 144 | { |
||
| 145 | list($class, $method) = Utils::getRouteClassAndMethodNames($action); |
||
| 146 | $reflection = new ReflectionClass($class); |
||
| 147 | |||
| 148 | if (! $reflection->hasMethod($method)) { |
||
| 149 | return false; |
||
| 150 | } |
||
| 151 | |||
| 152 | $comment = $reflection->getMethod($method)->getDocComment(); |
||
| 153 | |||
| 154 | if ($comment) { |
||
| 155 | $phpdoc = new DocBlock($comment); |
||
| 156 | |||
| 157 | return collect($phpdoc->getTags()) |
||
| 158 | ->filter(function ($tag) { |
||
| 159 | return $tag->getName() === 'hideFromAPIDocumentation'; |
||
| 160 | }) |
||
| 161 | ->isEmpty(); |
||
| 162 | } |
||
| 163 | |||
| 164 | return true; |
||
| 165 | } |
||
| 166 | } |
||
| 167 |