| Conditions | 6 |
| Paths | 7 |
| Total Lines | 59 |
| Code Lines | 31 |
| 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 |
||
| 64 | public function autocomplete($arguments) |
||
| 65 | { |
||
| 66 | $generator = $arguments['generator']; |
||
| 67 | $command = $arguments['command']; |
||
| 68 | $prev = $arguments['prev']; |
||
| 69 | $cur = $arguments['cur']; |
||
| 70 | $controllerClass = 'controllers\\' . $generator; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @todo add autogeneration this list |
||
| 74 | */ |
||
| 75 | $generators = [ |
||
| 76 | 'addon', |
||
| 77 | 'addon-xml', |
||
| 78 | 'help' |
||
| 79 | ]; |
||
| 80 | |||
| 81 | $autocompletes = []; |
||
| 82 | // $this->filesystem->write(ROOT_DIR . '/logs/terminal.txt', "gen: $generator; com: $command; prev: $prev; cur: $cur; " . implode(',', $autocompletes)); |
||
| 83 | |||
| 84 | // if (empty($generator)) { |
||
| 85 | // $autocompletes = $generators; |
||
| 86 | // } |
||
| 87 | |||
| 88 | if (class_exists($controllerClass)) { |
||
| 89 | $refl = new ReflectionClass($controllerClass); |
||
| 90 | $controller = $refl->newInstanceArgs([ |
||
| 91 | $this->config, |
||
| 92 | $this->terminal, |
||
| 93 | $this->filesystem |
||
| 94 | ]); |
||
| 95 | |||
| 96 | $method = $command; |
||
| 97 | $is_method_exists = method_exists($controllerClass, $method); |
||
| 98 | |||
| 99 | if ($method) { |
||
| 100 | $method_autocomplete = $command . 'Autocomplete'; |
||
| 101 | $autocompletes = method_exists($controllerClass, $method_autocomplete) ? $controller->{$method_autocomplete}($prev, $cur, $arguments) : []; |
||
| 102 | // $autocompletes = method_exists($controllerClass, $method) ? $controller->{$method}($prev, $cur) : $this->config->getSystemKeys(); |
||
| 103 | // $autocompletes = array_merge($autocompletes, $this->config->getSystemKeys()); |
||
| 104 | $this->filesystem->write(ROOT_DIR . '/logs/terminal.txt', "gen: $generator; method: $method_autocomplete; " . implode(',', $autocompletes) . ':::' . method_exists($controllerClass, $method_autocomplete)); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (empty($autocompletes) && !$is_method_exists) { |
||
| 108 | $allowedMethods = $controller::getAllowedMethods(); |
||
| 109 | $autocompletes = array_map(function($method) use ($generator) { |
||
| 110 | return $generator . '/' . $method; |
||
| 111 | }, $allowedMethods); |
||
| 112 | // $autocompletes[] = 'aaaaaaaaaaaaaddddd'; |
||
| 113 | } |
||
| 114 | } else { |
||
| 115 | $autocompletes = $generators; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @todo return array |
||
| 120 | */ |
||
| 121 | $this->terminal->echo(implode(' ', $autocompletes)); |
||
| 122 | exit(0); |
||
|
|
|||
| 123 | } |
||
| 125 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.