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