| Conditions | 9 |
| Paths | 100 |
| Total Lines | 51 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 25.9506 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 79 | 1 | protected function execute(InputInterface $input, OutputInterface $output) |
|
|
1 ignored issue
–
show
|
|||
| 80 | { |
||
| 81 | 1 | $align = $input->getArgument('align') === Step::ALIGN_TO_LEFT |
|
| 82 | ? Step::ALIGN_TO_LEFT |
||
| 83 | 1 | : Step::ALIGN_TO_RIGHT; |
|
| 84 | |||
| 85 | 1 | $directory = $input->getArgument('directory'); |
|
| 86 | 1 | $finder = new Finder(); |
|
| 87 | $finder |
||
| 88 | 1 | ->files() |
|
| 89 | 1 | ->in($directory) |
|
| 90 | 1 | ->name('*.feature'); |
|
| 91 | |||
| 92 | 1 | $output->writeln("\nFinding files on <info>" . $directory . "</info>\n"); |
|
| 93 | |||
| 94 | /* @var $file \Symfony\Component\Finder\SplFileInfo */ |
||
| 95 | 1 | foreach ($finder as $file) { |
|
| 96 | |||
| 97 | $fileContent = $file->getContents(); |
||
| 98 | $contentWithoutComments = $this->removeComments($fileContent); |
||
|
1 ignored issue
–
show
|
|||
| 99 | |||
| 100 | $feature = $this->parser->parse($fileContent); |
||
| 101 | $tagFormatter = new Tags(); |
||
| 102 | $featureDescription = new FeatureDescription(); |
||
| 103 | $background = new Background($align); |
||
| 104 | $scenario = new Scenario($align); |
||
| 105 | |||
| 106 | $formatted = $feature->hasTags() ? $tagFormatter->format($feature->getTags()) . PHP_EOL : ''; |
||
| 107 | $formatted .= $featureDescription->format($feature->getTitle(), explode(PHP_EOL, $feature->getDescription())) . PHP_EOL . PHP_EOL; |
||
| 108 | $formatted .= $feature->hasBackground() ? $background->format($feature->getBackground()) . PHP_EOL : ''; |
||
| 109 | $formatted .= $feature->hasScenarios() ? $scenario->format($feature->getScenarios()) : ''; |
||
| 110 | |||
| 111 | if ($formatted !== $contentWithoutComments) { |
||
| 112 | |||
| 113 | if (! defined('FAILED')) { |
||
| 114 | define('FAILED', true); |
||
| 115 | } |
||
| 116 | |||
| 117 | $diff = new Differ("--- Original\n+++ Expected\n", false); |
||
| 118 | |||
| 119 | $output->writeln('<error>Wrong style: ' . $file->getRealPath() . '</error>'); |
||
| 120 | $output->writeln($diff->diff($contentWithoutComments, $formatted)); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | 1 | if (defined('FAILED')) { |
|
| 125 | return 1; |
||
| 126 | } |
||
| 127 | |||
| 128 | 1 | $output->writeln('<bg=green;fg=white> Everything is OK! </>'); |
|
| 129 | 1 | } |
|
| 130 | |||
| 156 |
A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.
You can also find more information in the “Code” section of your repository.