| Conditions | 4 |
| Paths | 3 |
| Total Lines | 60 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 56 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 57 | { |
||
| 58 | $applicationName = $this->getParameter('application.name'); |
||
| 59 | |||
| 60 | $routes = $this->routes->all(); |
||
| 61 | |||
| 62 | $dumper = new Dumper(); |
||
| 63 | |||
| 64 | $resources = []; |
||
| 65 | foreach ($routes as $name => $route) { |
||
| 66 | $parameters = iterator_to_array($this->getParameters($route)); |
||
| 67 | |||
| 68 | $data = [ |
||
| 69 | 'summary' => $name, |
||
| 70 | 'responses' => [ |
||
| 71 | 200 => [ |
||
| 72 | 'description' => 'OK' |
||
| 73 | ] |
||
| 74 | ] |
||
| 75 | ]; |
||
| 76 | |||
| 77 | if ($parameters) { |
||
|
|
|||
| 78 | $data['parameters'] = $parameters; |
||
| 79 | } |
||
| 80 | |||
| 81 | $resources[$route->getPath()][strtolower(implode(',', $route->getMethods()) ?: 'get')] = $data; |
||
| 82 | } |
||
| 83 | |||
| 84 | $url = parse_url($this->getParameter('application.url')); |
||
| 85 | |||
| 86 | $formatted = [ |
||
| 87 | 'swagger' => '2.0', |
||
| 88 | 'info' => [ |
||
| 89 | 'title' => $applicationName, |
||
| 90 | 'description' => sprintf('%s API', $applicationName), |
||
| 91 | 'version' => '1.0.0' |
||
| 92 | ], |
||
| 93 | 'consumes' => ['application/json'], |
||
| 94 | 'produces' => ['application/json', 'text/html'], |
||
| 95 | 'host' => $url['host'], |
||
| 96 | 'schemes' => [$url['scheme']], |
||
| 97 | 'securityDefinitions' => [ |
||
| 98 | 'token' => [ |
||
| 99 | 'type' => 'apiKey', |
||
| 100 | 'description' => 'Given API Token', |
||
| 101 | 'name' => 'Token', |
||
| 102 | 'in' => 'Header' |
||
| 103 | ] |
||
| 104 | ], |
||
| 105 | 'security' => [ |
||
| 106 | 'token' => [ |
||
| 107 | 'all' |
||
| 108 | ] |
||
| 109 | ], |
||
| 110 | 'paths' => $resources, |
||
| 111 | ]; |
||
| 112 | |||
| 113 | echo $dumper->dump($formatted, 4); |
||
| 114 | echo PHP_EOL; |
||
| 115 | } |
||
| 116 | |||
| 136 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.