| Conditions | 22 |
| Paths | 4320 |
| Total Lines | 100 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 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 |
||
| 61 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 62 | |||
| 63 | $this->app->initialize(); |
||
| 64 | $this->app->boot(); |
||
| 65 | |||
| 66 | $console = new Application(); |
||
| 67 | |||
| 68 | $filtername = $input->getArgument('name'); |
||
| 69 | $sort = $input->getOption('sort'); |
||
| 70 | $orderby = $input->getOption('orderby'); |
||
| 71 | |||
| 72 | $table = $console->getHelperSet()->get('table'); |
||
| 73 | $table->setHeaders(array('Name', 'Path', 'Pattern')); |
||
| 74 | $table->setLayout(TableHelper::LAYOUT_DEFAULT); |
||
| 75 | |||
| 76 | $controllers = $this->app['controllers']; |
||
| 77 | $collection = $controllers->flush(); |
||
| 78 | |||
| 79 | foreach ($collection as $name => $route) { |
||
| 80 | if (!empty($filtername) && !preg_match("/$filtername/", $name)) { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | $requirements = array(); |
||
| 85 | foreach ($route->getRequirements() as $key => $requirement) { |
||
| 86 | // $requirements[] = $key . ' => ' . $requirement; |
||
| 87 | $requirements[] = $requirement; |
||
| 88 | } |
||
| 89 | |||
| 90 | $table->addRow(array( |
||
| 91 | $name, |
||
| 92 | $route->getPath(), |
||
| 93 | join(', ', $requirements) |
||
| 94 | )); |
||
| 95 | } |
||
| 96 | |||
| 97 | |||
| 98 | $routes = $this->app['routes']->all(); |
||
| 99 | |||
| 100 | // 引数で並び替える。 |
||
| 101 | if (!empty($sort)) { |
||
| 102 | $orderby = (!empty($orderby)) ? $orderby : "name"; |
||
| 103 | } |
||
| 104 | if (!empty($orderby)) { |
||
| 105 | $sort = (!empty($sort)) ? $sort : "ASC"; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (strtoupper($orderby) === "NAME") { |
||
| 109 | if (strtoupper($sort) === "DESC") { |
||
| 110 | krsort($routes); |
||
| 111 | } else { |
||
| 112 | ksort($routes); |
||
| 113 | } |
||
| 114 | } else if (strtoupper($orderby) === "PATH") { |
||
| 115 | uasort($routes, function($a, $b) { |
||
| 116 | return strcmp($a->getPattern(), $b->getPattern()); |
||
| 117 | }); |
||
| 118 | } |
||
| 119 | |||
| 120 | $maxName = 4; |
||
| 121 | $maxMethod = 6; |
||
| 122 | foreach ($routes as $name => $route) { |
||
| 123 | if (!empty($filtername) && !preg_match("/$filtername/", $name)) { |
||
| 124 | unset($routes[$name]); |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | |||
| 128 | $requirements = $route->getRequirements(); |
||
| 129 | $method = isset($requirements['_method']) |
||
| 130 | ? strtoupper(is_array($requirements['_method']) |
||
| 131 | ? implode(', ', $requirements['_method']) : $requirements['_method'] |
||
| 132 | ) |
||
| 133 | : 'ANY'; |
||
| 134 | |||
| 135 | if (strlen($name) > $maxName) { |
||
| 136 | $maxName = strlen($name); |
||
| 137 | } |
||
| 138 | |||
| 139 | if (strlen($method) > $maxMethod) { |
||
| 140 | $maxMethod = strlen($method); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | foreach ($routes as $name => $route) { |
||
| 145 | $requirements = $route->getRequirements(); |
||
| 146 | $method = isset($requirements['_method']) |
||
| 147 | ? strtoupper(is_array($requirements['_method']) |
||
| 148 | ? implode(', ', $requirements['_method']) : $requirements['_method'] |
||
| 149 | ) |
||
| 150 | : 'ANY'; |
||
| 151 | |||
| 152 | $table->addRow(array( |
||
| 153 | $name, |
||
| 154 | $route->getPattern(), |
||
| 155 | $method, |
||
| 156 | )); |
||
| 157 | } |
||
| 158 | |||
| 159 | $table->render($output); |
||
| 160 | } |
||
| 161 | |||
| 163 |