| Conditions | 9 |
| Paths | 13 |
| Total Lines | 66 |
| Code Lines | 37 |
| 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 |
||
| 34 | protected function doExecute(InputInterface $input, OutputInterface $output): int |
||
| 35 | { |
||
| 36 | OutputHelper::renderHeader($output); |
||
| 37 | |||
| 38 | $this->enrichRepositories(); |
||
| 39 | |||
| 40 | $filename = $input->getArgument('filename'); |
||
| 41 | $pattern = $input->getArgument('pattern'); |
||
| 42 | |||
| 43 | /** @var QuestionHelper $questionHelper */ |
||
| 44 | $questionHelper = $this->getHelper('question'); |
||
| 45 | |||
| 46 | if (!file_exists($filename)) { |
||
| 47 | $this->renderErrorBox('File not found.'); |
||
| 48 | return SymfonyCommand::FAILURE; |
||
| 49 | } |
||
| 50 | |||
| 51 | $filenames = [ |
||
| 52 | basename($filename), |
||
| 53 | pathinfo($filename, PATHINFO_EXTENSION) |
||
| 54 | ]; |
||
| 55 | |||
| 56 | if (is_dir($filename)) { |
||
| 57 | $filenames[] = FileParameter::DIRECTORY; |
||
| 58 | } |
||
| 59 | |||
| 60 | $fileCommands = $this->getRepositoryCollection()->searchByFile($filenames); |
||
| 61 | |||
| 62 | if ($pattern) { |
||
| 63 | foreach ($fileCommands as $key => $fileCommand) { |
||
| 64 | if (str_contains(strtolower($fileCommand->getName()), strtolower($pattern))) { |
||
| 65 | continue; |
||
| 66 | } |
||
| 67 | if (str_contains(strtolower($fileCommand->getDescription()), strtolower($pattern))) { |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | unset($fileCommands[$key]); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $this->renderInfoBox('This is a list of commands that are applicable to the given file or file type.'); |
||
| 75 | |||
| 76 | if (empty($fileCommands)) { |
||
| 77 | $this->renderErrorBox('No commands found that match this file type.'); |
||
| 78 | return SymfonyCommand::FAILURE; |
||
| 79 | } |
||
| 80 | |||
| 81 | $command = OutputHelper::renderCommands( |
||
| 82 | $output, |
||
| 83 | $input, |
||
| 84 | $questionHelper, |
||
| 85 | $fileCommands, |
||
| 86 | null, |
||
| 87 | -1, |
||
| 88 | true |
||
| 89 | ); |
||
| 90 | |||
| 91 | if ($command === false) { |
||
|
|
|||
| 92 | return SymfonyCommand::FAILURE; |
||
| 93 | } |
||
| 94 | |||
| 95 | $output->writeln(''); |
||
| 96 | |||
| 97 | $values = [$this->getParameterIdentifier($command, $filenames) => $filename]; |
||
| 98 | |||
| 99 | return $this->runCommand($command, $values); |
||
| 100 | } |
||
| 117 |