| Conditions | 8 |
| Paths | 17 |
| Total Lines | 54 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 44 | public function run(array $messages) |
||
| 45 | { |
||
| 46 | $this->outputHandler->setTitle('Checking code mess with PHPMD'); |
||
| 47 | $this->output->write($this->outputHandler->getTitle()); |
||
| 48 | |||
| 49 | $errors = []; |
||
| 50 | |||
| 51 | foreach ($this->files as $file) { |
||
| 52 | if (!preg_match($this->needle, $file)) { |
||
| 53 | continue; |
||
| 54 | } |
||
| 55 | |||
| 56 | $pmdRulesXml = realpath(__DIR__.self::COMPOSER_VENDOR_DIR).'/../PmdRules.xml'; |
||
| 57 | if (!file_exists($pmdRulesXml)) { |
||
| 58 | throw new PHPMDViolationsException('You don\'t have specific PmdRules.xml in the root of your project. See Readme.md to create it'); |
||
| 59 | } |
||
| 60 | |||
| 61 | $command = array( |
||
| 62 | 'php', |
||
| 63 | $this->getBinPath('phpmd'), |
||
| 64 | $file, |
||
| 65 | 'text', |
||
| 66 | '/PmdRules.xml', |
||
| 67 | ); |
||
| 68 | |||
| 69 | if ($this->getMinimumPriority() > -1) { |
||
| 70 | array_push($command, '--minimumpriority'); |
||
| 71 | array_push($command, $this->getMinimumPriority()); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (false === $this->ignoreFiles->isIgnored($file)) { |
||
| 75 | $processBuilder = new ProcessBuilder($command); |
||
| 76 | $process = $processBuilder->getProcess(); |
||
| 77 | $process->run(); |
||
| 78 | |||
| 79 | if (false === $process->isSuccessful()) { |
||
| 80 | $errors[] = $process->getOutput(); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $errors = array_filter($errors, function ($var) { |
||
| 86 | return trim($var); |
||
| 87 | }); |
||
| 88 | |||
| 89 | if (!empty($errors)) { |
||
| 90 | $this->writeOutputError( |
||
| 91 | new PHPMDViolationsException("Check MD errors listed above"), |
||
| 92 | implode("\n", $errors) |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | $this->output->writeln($this->outputHandler->getSuccessfulStepMessage()); |
||
| 97 | } |
||
| 98 | |||
| 131 |