| Conditions | 12 |
| Paths | 183 |
| Total Lines | 73 |
| Code Lines | 44 |
| 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 |
||
| 73 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 74 | { |
||
| 75 | $io = new SymfonyStyle($input, $output); |
||
| 76 | |||
| 77 | OutputConfigurator::configure($output); |
||
| 78 | |||
| 79 | try { |
||
| 80 | $config = $this->getConfig($input, $output); |
||
| 81 | |||
| 82 | $recommendations = $config->getRecommendations(); |
||
| 83 | $warnings = $config->getWarnings(); |
||
| 84 | |||
| 85 | MessageRenderer::render($io, $recommendations, $warnings); |
||
| 86 | |||
| 87 | $hasRecommendationsOrWarnings = [] === $recommendations && [] === $warnings; |
||
| 88 | |||
| 89 | if (false === $hasRecommendationsOrWarnings) { |
||
| 90 | if ([] === $recommendations) { |
||
| 91 | $io->caution('The configuration file passed the validation with warnings.'); |
||
| 92 | } elseif ([] === $warnings) { |
||
| 93 | $io->caution('The configuration file passed the validation with recommendations.'); |
||
| 94 | } else { |
||
| 95 | $io->caution('The configuration file passed the validation with recommendations and warnings.'); |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | $io->success('The configuration file passed the validation.'); |
||
| 99 | } |
||
| 100 | |||
| 101 | return ($hasRecommendationsOrWarnings || $input->getOption(self::IGNORE_MESSAGES_OPTION)) ? 0 : 1; |
||
| 102 | } catch (Exception $exception) { |
||
| 103 | // Continue |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($output->isVerbose()) { |
||
| 107 | throw new RuntimeException( |
||
| 108 | sprintf( |
||
| 109 | 'The configuration file failed validation: %s', |
||
| 110 | $exception->getMessage() |
||
| 111 | ), |
||
| 112 | $exception->getCode(), |
||
| 113 | $exception |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($exception instanceof JsonValidationException) { |
||
| 118 | $output->writeln( |
||
| 119 | sprintf( |
||
| 120 | '<error>The configuration file failed validation: "%s" does not match the expected JSON ' |
||
| 121 | .'schema:</error>', |
||
| 122 | $exception->getValidatedFile() |
||
| 123 | ) |
||
| 124 | ); |
||
| 125 | |||
| 126 | $output->writeln(''); |
||
| 127 | |||
| 128 | foreach ($exception->getErrors() as $error) { |
||
| 129 | $output->writeln("<comment> - $error</comment>"); |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | $errorMessage = isset($exception) |
||
| 133 | ? sprintf('The configuration file failed validation: %s', $exception->getMessage()) |
||
| 134 | : 'The configuration file failed validation.' |
||
| 135 | ; |
||
| 136 | |||
| 137 | $output->writeln( |
||
| 138 | sprintf( |
||
| 139 | '<error>%s</error>', |
||
| 140 | $errorMessage |
||
| 141 | ) |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | |||
| 145 | return 1; |
||
| 146 | } |
||
| 148 |