| Conditions | 6 |
| Paths | 12 |
| Total Lines | 54 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 59 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 60 | { |
||
| 61 | try { |
||
| 62 | $this->getConfig($input); |
||
| 63 | |||
| 64 | $output->writeln( |
||
| 65 | '<info>The configuration file passed validation.</info>' |
||
| 66 | ); |
||
| 67 | |||
| 68 | return 0; |
||
| 69 | } catch (Exception $exception) { |
||
| 70 | // Continue |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($output->isVerbose()) { |
||
| 74 | throw new RuntimeException( |
||
| 75 | sprintf( |
||
| 76 | 'The configuration file failed validation: %s', |
||
| 77 | $exception->getMessage() |
||
| 78 | ), |
||
| 79 | $exception->getCode(), |
||
| 80 | $exception |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($exception instanceof JsonValidationException) { |
||
| 85 | $output->writeln( |
||
| 86 | sprintf( |
||
| 87 | '<error>The configuration file failed validation: "%s" does not match the expected JSON ' |
||
| 88 | .'schema:</error>', |
||
| 89 | $exception->getValidatedFile() |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | |||
| 93 | $output->writeln(''); |
||
| 94 | |||
| 95 | foreach ($exception->getErrors() as $error) { |
||
| 96 | $output->writeln("<comment> - $error</comment>"); |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | $errorMessage = isset($exception) |
||
| 100 | ? sprintf('The configuration file failed validation: %s', $exception->getMessage()) |
||
| 101 | : 'The configuration file failed validation.' |
||
| 102 | ; |
||
| 103 | |||
| 104 | $output->writeln( |
||
| 105 | sprintf( |
||
| 106 | '<error>%s</error>', |
||
| 107 | $errorMessage |
||
| 108 | ) |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | return 1; |
||
| 113 | } |
||
| 115 |