| Conditions | 7 |
| Paths | 19 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 declare(strict_types = 1); |
||
| 71 | public function load($resource, $type = null): RouteCollection |
||
| 72 | { |
||
| 73 | $resource = (string)$resource; |
||
| 74 | if (in_array($resource, $this->descriptions)) { |
||
| 75 | throw new \RuntimeException("Resource '$resource' was already loaded"); |
||
| 76 | } |
||
| 77 | |||
| 78 | $description = $this->repository->get($resource); |
||
| 79 | |||
| 80 | $routes = new RouteCollection(); |
||
| 81 | $router = $description->getExtension('router') ?: 'swagger.controller'; |
||
| 82 | $routerController = $description->getExtension('router-controller'); |
||
| 83 | |||
| 84 | foreach ($description->getPaths() as $pathItem) { |
||
| 85 | $relativePath = ltrim($pathItem->getPath(), '/'); |
||
| 86 | $resourceName = strpos($relativePath, '/') |
||
| 87 | ? substr($relativePath, 0, strpos($relativePath, '/')) |
||
| 88 | : $relativePath; |
||
| 89 | |||
| 90 | $routerController = $pathItem->getExtension('router-controller') ?: $routerController; |
||
| 91 | |||
| 92 | foreach ($pathItem->getOperations() as $operation) { |
||
| 93 | $controllerKey = $this->resolveControllerKey( |
||
| 94 | $operation, |
||
| 95 | $resourceName, |
||
| 96 | $router, |
||
| 97 | $routerController |
||
| 98 | ); |
||
| 99 | $defaults = [ |
||
| 100 | '_controller' => $controllerKey, |
||
| 101 | RequestMeta::ATTRIBUTE_URI => $resource, |
||
| 102 | RequestMeta::ATTRIBUTE_PATH => $pathItem->getPath(), |
||
| 103 | ]; |
||
| 104 | |||
| 105 | $route = new Route( |
||
| 106 | $pathItem->getPath(), |
||
| 107 | $defaults, |
||
| 108 | $this->resolveRequirements($operation), |
||
| 109 | [], |
||
| 110 | '', |
||
| 111 | $description->getSchemes() |
||
| 112 | ); |
||
| 113 | $route->setMethods($operation->getMethod()); |
||
| 114 | $routes->add($this->createRouteId($resource, $pathItem->getPath(), $controllerKey), $route); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $this->descriptions[] = $resource; |
||
| 119 | |||
| 120 | return $routes; |
||
| 121 | } |
||
| 122 | |||
| 200 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: