| Conditions | 16 |
| Paths | 60 |
| Total Lines | 48 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| 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 declare(strict_types=1); |
||
| 86 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 87 | { |
||
| 88 | $path = $input->getArgument('path'); |
||
| 89 | $areaToFile = []; |
||
| 90 | $areaToFile['unknown'] = []; |
||
| 91 | $ignoredFiles = $input->getOption(self::OPTION_IGNORE_FILES) ? explode(',', $input->getOption(self::OPTION_IGNORE_FILES)) : []; |
||
| 92 | |||
| 93 | $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); |
||
| 94 | /** |
||
| 95 | * @var \RecursiveIteratorIterator<\RecursiveDirectoryIterator> $files |
||
| 96 | * @var \Symfony\Component\Finder\SplFileInfo $file |
||
| 97 | */ |
||
| 98 | foreach ($files as $file) { |
||
| 99 | $fileName = $file->getFilename(); |
||
| 100 | $filePath = $file->getRealPath(); |
||
| 101 | if ((\str_ends_with($fileName, '.js') || \str_ends_with($fileName, '.ts')) && !\str_ends_with($fileName, '.spec.js')) { |
||
| 102 | if (\count($ignoredFiles) > 0) { |
||
| 103 | if (\in_array($filePath, $ignoredFiles, true)) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $fileContent = \file_get_contents($filePath) ?: ''; |
||
| 108 | $matchCount = preg_match('/^.*@package (.*)$/m', $fileContent, $matches); |
||
| 109 | $filePath = $input->getOption(self::OPTION_RELATIVE) ? $input->getOption(self::OPTION_PREFIX_RELATIVE) . str_replace($path, '', $filePath) : $filePath; |
||
| 110 | if ($matchCount > 0) { |
||
| 111 | if (!\array_key_exists($matches[1], $areaToFile) || !\is_array($areaToFile[$matches[1]])) { |
||
| 112 | $areaToFile[$matches[1]] = []; |
||
| 113 | } |
||
| 114 | $areaToFile[$matches[1]][] = $filePath; |
||
| 115 | } else { |
||
| 116 | $areaToFile['unknown'][] = $filePath; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($input->getOption(self::OPTION_AREA)) { |
||
| 122 | $output->write( |
||
| 123 | $input->getOption(self::OPTION_SEPARATED) |
||
| 124 | ? \implode($input->getOption(self::OPTION_DELIMITER) ?: '|', $areaToFile[$input->getOption(self::OPTION_AREA)]) |
||
| 125 | : var_export($areaToFile[$input->getOption(self::OPTION_AREA)], true) |
||
| 126 | ); |
||
| 127 | } else { |
||
| 128 | $output->write( |
||
| 129 | var_export($areaToFile, true) |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | |||
| 133 | return 0; |
||
| 134 | } |
||
| 136 |