| Conditions | 18 |
| Paths | 136 |
| Total Lines | 70 |
| Code Lines | 44 |
| 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 |
||
| 106 | public function run($param): void |
||
| 107 | { |
||
| 108 | // registering the commands to container. |
||
| 109 | foreach ($this->commands as $command) { |
||
| 110 | $this->container->register([$command[1], $command[0]], new $command[1]()); |
||
| 111 | } |
||
| 112 | |||
| 113 | $sign = isset($param[1]) ? $param[1] : 'list'; |
||
| 114 | $output = new Output(); |
||
| 115 | $input = new Input(); |
||
| 116 | if ($this->container->has($sign)) { |
||
| 117 | $cmd = $this->container->get($sign); |
||
| 118 | |||
| 119 | // default. |
||
| 120 | if (!isset($param[2])) { |
||
| 121 | if (count($cmd->getFlags()) > 0) { |
||
| 122 | $output->error('You must provide the flags'); |
||
| 123 | $output->error('For Help, php alphaz '.$cmd->getSign().' -h'); |
||
| 124 | exit; |
||
| 125 | } |
||
| 126 | $cmd->handle($output, $input); |
||
| 127 | } |
||
| 128 | // flag for quite |
||
| 129 | if (isset($param[2]) && strtolower($param[2]) == '-q') { |
||
| 130 | $cmd->handle($output->quiet(), $input); |
||
| 131 | } |
||
| 132 | if (isset($param[2]) && isset($param[3]) && strtolower($param[2]) == '-p') { |
||
| 133 | $params = $this->parseFlags($param[3]); |
||
| 134 | $command_flags = $cmd->getFlags(); |
||
| 135 | // get keys from $params. |
||
| 136 | $keys = array_keys($params); |
||
| 137 | |||
| 138 | // check if the keys are in the command flags (check if extra flag passed). |
||
| 139 | foreach ($keys as $key => $value) { |
||
| 140 | if (!in_array($value, $command_flags)) { |
||
| 141 | $output->error("Invalid flag: $value"); |
||
| 142 | exit; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | // check the keys should be in command flags. |
||
| 147 | foreach ($command_flags as $command_flag) { |
||
| 148 | if (!in_array($command_flag, $keys)) { |
||
| 149 | $output->error("Missing flag: $command_flag"); |
||
| 150 | exit; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | $cmd->handle($output, $input, $params); |
||
| 155 | } |
||
| 156 | |||
| 157 | // flag for help |
||
| 158 | if (isset($param[2]) && strtolower($param[2]) == '-h') { |
||
| 159 | $args = $cmd->getFlags(); |
||
| 160 | $output->write('<yellow>Description:</yellow>', true); |
||
| 161 | $output->write("<blue>\t".$cmd->getDescription().'</blue>', true); |
||
| 162 | $output->write("\n<yellow>Usage:</yellow>", true); |
||
| 163 | $output->write("<blue>\t".$cmd->getSign().'</blue>', true); |
||
| 164 | if (count($args) > 0) { |
||
| 165 | $output->write("\n<yellow>Arguments:</yellow>", true); |
||
| 166 | $output->write("<blue>\t".implode(',', $args).'</blue>', true); |
||
| 167 | } |
||
| 168 | $output->write("\n<yellow>Options:</yellow>", true); |
||
| 169 | $output->write('<green>-h, --help</green>'); |
||
| 170 | $output->write("<blue>\tDisplay this help message</blue>", true); |
||
| 171 | $output->write('<green>--q, --quiet</green>'); |
||
| 172 | $output->write("<blue>\tDo not output any message</blue>", true); |
||
| 173 | } |
||
| 174 | } else { |
||
| 175 | $output->error("Sorry, the given command ${sign} not found")->exit(); |
||
| 176 | } |
||
| 179 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths