| Conditions | 9 |
| Paths | 24 |
| Total Lines | 69 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 54 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 55 | $outputType = $input->getOption('output'); |
||
| 56 | |||
| 57 | \OC_App::loadApps(); |
||
| 58 | $this->router->loadRoutes(); |
||
| 59 | |||
| 60 | $rows = []; |
||
| 61 | |||
| 62 | if ($input->getOption('with-details')) { |
||
| 63 | $headers = [ |
||
| 64 | 'Path', |
||
| 65 | 'Methods', |
||
| 66 | 'Controller', |
||
| 67 | 'Annotations', |
||
| 68 | ]; |
||
| 69 | /** @var Route[] $collections */ |
||
| 70 | $collections = []; |
||
| 71 | foreach ($this->router->getCollections() as $c) { |
||
| 72 | $new = $c->all(); |
||
| 73 | $collections = $collections + $new; |
||
| 74 | } |
||
| 75 | |||
| 76 | foreach ($collections as $name => $route) { |
||
| 77 | $c = $this->buildController($name); |
||
| 78 | $rows[] = array_merge([ |
||
| 79 | 'path' => $route->getPath(), |
||
| 80 | 'methods' => $route->getMethods() |
||
| 81 | ], $c); |
||
| 82 | } |
||
| 83 | } else { |
||
| 84 | $headers = [ |
||
| 85 | 'Path', |
||
| 86 | 'Methods' |
||
| 87 | ]; |
||
| 88 | foreach ($this->router->getCollections() as $routeCollection) { |
||
| 89 | foreach ($routeCollection as $route) { |
||
| 90 | $path = $route->getPath(); |
||
| 91 | if (isset($rows[$path])) { |
||
| 92 | $rows[$path]['methods'] = array_unique(array_merge($rows[$path]['methods'], $route->getMethods())); |
||
| 93 | } else { |
||
| 94 | $rows[$path] = [ |
||
| 95 | 'path' => $path, |
||
| 96 | 'methods' => $route->getMethods() |
||
| 97 | ]; |
||
| 98 | } |
||
| 99 | sort ($rows[$path]['methods']); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | usort($rows, function ($a, $b) { |
||
| 104 | return strcmp($a['path'], $b['path']); |
||
| 105 | }); |
||
| 106 | $rows = array_map(function($row) { |
||
| 107 | $row['methods'] = implode(',', $row['methods']); |
||
| 108 | return $row; |
||
| 109 | }, $rows); |
||
| 110 | |||
| 111 | if ($outputType === self::OUTPUT_FORMAT_JSON ) { |
||
| 112 | $output->write(json_encode($rows)); |
||
| 113 | } else if ($outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
||
| 114 | $output->writeln(json_encode($rows, JSON_PRETTY_PRINT)); |
||
| 115 | } else { |
||
| 116 | $table = new Table($output); |
||
| 117 | $table->setHeaders($headers); |
||
| 118 | |||
| 119 | $table->addRows($rows); |
||
| 120 | $table->render(); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 213 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.