| Conditions | 10 |
| Paths | 10 |
| Total Lines | 55 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 declare(strict_types=1); |
||
| 83 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 84 | { |
||
| 85 | $this->nsPattern = $input->getOption(self::OPTION_NAMESPACE_PATTERN); |
||
| 86 | |||
| 87 | $classesPerArea = $this->getClassesPerArea(); |
||
| 88 | if ($input->getOption(self::OPTION_JSON)) { |
||
| 89 | $output->write( |
||
| 90 | json_encode( |
||
| 91 | $classesPerArea, |
||
| 92 | $input->getOption(self::OPTION_PRETTY) ? \JSON_PRETTY_PRINT : 0 |
||
| 93 | ) ?: '' |
||
| 94 | ); |
||
| 95 | } else { |
||
| 96 | $output->write( |
||
| 97 | var_export( |
||
| 98 | $classesPerArea, |
||
| 99 | true |
||
| 100 | ) |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($input->getOption(self::OPTION_GENERATE_PHPUNIT_TEST)) { |
||
| 105 | $unitFiles = []; |
||
|
|
|||
| 106 | foreach ($classesPerArea as $area => $classToFile) { |
||
| 107 | $unitFile = new \DOMDocument(); |
||
| 108 | // Load phpunit template |
||
| 109 | $unitFile->load('phpunit.xml.dist'); |
||
| 110 | $unitDocument = $unitFile->documentElement; |
||
| 111 | if ($unitDocument === null) { |
||
| 112 | return 1; |
||
| 113 | } |
||
| 114 | $coverage = $unitDocument->getElementsByTagName('coverage')->item(0); |
||
| 115 | if ($coverage === null) { |
||
| 116 | return 1; |
||
| 117 | } |
||
| 118 | $includeChildElement = $coverage->getElementsByTagName('include')->item(0); |
||
| 119 | if ($includeChildElement === null) { |
||
| 120 | return 1; |
||
| 121 | } |
||
| 122 | // Remove include from coverage to create our own includes |
||
| 123 | $coverage->removeChild($includeChildElement); |
||
| 124 | $includeElement = $unitFile->createElement('include'); |
||
| 125 | |||
| 126 | foreach ($classToFile as $class => $file) { |
||
| 127 | $fileElement = $unitFile->createElement('file', $file); |
||
| 128 | $includeElement->appendChild($fileElement); |
||
| 129 | } |
||
| 130 | $coverage->appendChild($includeElement); |
||
| 131 | |||
| 132 | // Create phpunit file per area |
||
| 133 | file_put_contents("phpunit.$area.xml", $unitFile->saveXML()); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | return 0; |
||
| 138 | } |
||
| 182 |