| Conditions | 9 |
| Paths | 16 |
| Total Lines | 57 |
| Code Lines | 35 |
| 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 |
||
| 81 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 82 | { |
||
| 83 | $files = $this->files->toArray(); |
||
| 84 | |||
| 85 | if (empty($files)) { |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | $progress = $this->createProgressBar($input, $output); |
||
| 90 | $progress->start(count($files)); |
||
| 91 | |||
| 92 | $failed = []; |
||
| 93 | |||
| 94 | foreach ($files as $file) { |
||
| 95 | $progress->setMessage('Checking <info>' . $file . '</info>...'); |
||
| 96 | |||
| 97 | $process = new Process( |
||
| 98 | sprintf( |
||
| 99 | 'php -f %s -- fix %s %s', |
||
| 100 | escapeshellarg($this->binFile), |
||
| 101 | escapeshellarg($file), |
||
| 102 | $this->configFile ? ('--config-file=' . escapeshellarg($this->configFile)) : '' |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | $process->run(); |
||
| 106 | |||
| 107 | switch ($process->getExitCode()) { |
||
| 108 | case 0: |
||
|
|
|||
| 109 | // file has been changed |
||
| 110 | if ($this->addAutomatically) { |
||
| 111 | exec('git add ' . escapeshellarg($file)); |
||
| 112 | } |
||
| 113 | break; |
||
| 114 | case 1: |
||
| 115 | // file not changed |
||
| 116 | break; |
||
| 117 | default: |
||
| 118 | // some sort of error |
||
| 119 | $failed[$file] = explode("\n", str_replace(PHP_EOL, "\n", $process->getOutput())); |
||
| 120 | break; |
||
| 121 | } |
||
| 122 | |||
| 123 | $progress->advance(); |
||
| 124 | } |
||
| 125 | |||
| 126 | if (count($failed)) { |
||
| 127 | $message = 'PhpCsFixerOld failed for the following file(s):'; |
||
| 128 | foreach ($failed as $file => $result) { |
||
| 129 | $message .= PHP_EOL . '- ' . $file . ':'; |
||
| 130 | $message .= PHP_EOL . ' - ' . implode(PHP_EOL . ' - ', $result); |
||
| 131 | } |
||
| 132 | throw new \RuntimeException($message); |
||
| 133 | } |
||
| 134 | |||
| 135 | $progress->setMessage('Finished.'); |
||
| 136 | $progress->finish(); |
||
| 137 | } |
||
| 138 | |||
| 150 |