Conditions | 21 |
Paths | 2017 |
Total Lines | 141 |
Code Lines | 94 |
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 |
||
229 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
230 | { |
||
231 | $verbosity = $output->getVerbosity(); |
||
232 | |||
233 | $passedConfig = $input->getOption('config'); |
||
234 | $passedRules = $input->getOption('rules'); |
||
235 | |||
236 | if (null !== $passedConfig && null !== $passedRules) { |
||
237 | throw new InvalidConfigurationException('Passing both `--config` and `--rules` options is not allowed.'); |
||
238 | } |
||
239 | |||
240 | $resolver = new ConfigurationResolver( |
||
241 | $this->defaultConfig, |
||
242 | [ |
||
243 | 'allow-risky' => $input->getOption('allow-risky'), |
||
244 | 'config' => $passedConfig, |
||
245 | 'dry-run' => $input->getOption('dry-run'), |
||
246 | 'rules' => $passedRules, |
||
247 | 'path' => $input->getArgument('path'), |
||
248 | 'path-mode' => $input->getOption('path-mode'), |
||
249 | 'using-cache' => $input->getOption('using-cache'), |
||
250 | 'cache-file' => $input->getOption('cache-file'), |
||
251 | 'format' => $input->getOption('format'), |
||
252 | 'diff' => $input->getOption('diff'), |
||
253 | 'stop-on-violation' => $input->getOption('stop-on-violation'), |
||
254 | 'verbosity' => $verbosity, |
||
255 | 'show-progress' => $input->getOption('show-progress'), |
||
256 | ], |
||
257 | getcwd(), |
||
258 | $this->toolInfo |
||
259 | ); |
||
260 | |||
261 | $reporter = $resolver->getReporter(); |
||
262 | |||
263 | $stdErr = $output instanceof ConsoleOutputInterface |
||
264 | ? $output->getErrorOutput() |
||
265 | : ('txt' === $reporter->getFormat() ? $output : null) |
||
266 | ; |
||
267 | |||
268 | if (null !== $stdErr) { |
||
269 | if (OutputInterface::VERBOSITY_VERBOSE <= $verbosity) { |
||
270 | $stdErr->writeln($this->getApplication()->getLongVersion()); |
||
271 | $stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION)); |
||
272 | } |
||
273 | |||
274 | $configFile = $resolver->getConfigFile(); |
||
275 | $stdErr->writeln(sprintf('Loaded config <comment>%s</comment>%s.', $resolver->getConfig()->getName(), null === $configFile ? '' : ' from "'.$configFile.'"')); |
||
276 | |||
277 | if ($resolver->getUsingCache()) { |
||
278 | $cacheFile = $resolver->getCacheFile(); |
||
279 | |||
280 | if (is_file($cacheFile)) { |
||
|
|||
281 | $stdErr->writeln(sprintf('Using cache file "%s".', $cacheFile)); |
||
282 | } |
||
283 | } |
||
284 | } |
||
285 | |||
286 | $progressType = $resolver->getProgress(); |
||
287 | $finder = $resolver->getFinder(); |
||
288 | |||
289 | if (null !== $stdErr && $resolver->configFinderIsOverridden()) { |
||
290 | $stdErr->writeln( |
||
291 | sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'Paths from configuration file have been overridden by paths provided as command arguments.') |
||
292 | ); |
||
293 | } |
||
294 | |||
295 | if ('none' === $progressType || null === $stdErr) { |
||
296 | $progressOutput = new NullOutput(); |
||
297 | } else { |
||
298 | $finder = new \ArrayIterator(iterator_to_array($finder)); |
||
299 | $progressOutput = new ProcessOutput( |
||
300 | $stdErr, |
||
301 | $this->eventDispatcher, |
||
302 | (new Terminal())->getWidth(), |
||
303 | \count($finder) |
||
304 | ); |
||
305 | } |
||
306 | |||
307 | $runner = new Runner( |
||
308 | $finder, |
||
309 | $resolver->getFixers(), |
||
310 | $resolver->getDiffer(), |
||
311 | 'none' !== $progressType ? $this->eventDispatcher : null, |
||
312 | $this->errorsManager, |
||
313 | $resolver->getLinter(), |
||
314 | $resolver->isDryRun(), |
||
315 | $resolver->getCacheManager(), |
||
316 | $resolver->getDirectory(), |
||
317 | $resolver->shouldStopOnViolation() |
||
318 | ); |
||
319 | |||
320 | $this->stopwatch->start('fixFiles'); |
||
321 | $changed = $runner->fix(); |
||
322 | $this->stopwatch->stop('fixFiles'); |
||
323 | |||
324 | $progressOutput->printLegend(); |
||
325 | |||
326 | $fixEvent = $this->stopwatch->getEvent('fixFiles'); |
||
327 | |||
328 | $reportSummary = new ReportSummary( |
||
329 | $changed, |
||
330 | $fixEvent->getDuration(), |
||
331 | $fixEvent->getMemory(), |
||
332 | OutputInterface::VERBOSITY_VERBOSE <= $verbosity, |
||
333 | $resolver->isDryRun(), |
||
334 | $output->isDecorated() |
||
335 | ); |
||
336 | |||
337 | $output->isDecorated() |
||
338 | ? $output->write($reporter->generate($reportSummary)) |
||
339 | : $output->write($reporter->generate($reportSummary), false, OutputInterface::OUTPUT_RAW) |
||
340 | ; |
||
341 | |||
342 | $invalidErrors = $this->errorsManager->getInvalidErrors(); |
||
343 | $exceptionErrors = $this->errorsManager->getExceptionErrors(); |
||
344 | $lintErrors = $this->errorsManager->getLintErrors(); |
||
345 | |||
346 | if (null !== $stdErr) { |
||
347 | $errorOutput = new ErrorOutput($stdErr); |
||
348 | |||
349 | if (\count($invalidErrors) > 0) { |
||
350 | $errorOutput->listErrors('linting before fixing', $invalidErrors); |
||
351 | } |
||
352 | |||
353 | if (\count($exceptionErrors) > 0) { |
||
354 | $errorOutput->listErrors('fixing', $exceptionErrors); |
||
355 | } |
||
356 | |||
357 | if (\count($lintErrors) > 0) { |
||
358 | $errorOutput->listErrors('linting after fixing', $lintErrors); |
||
359 | } |
||
360 | } |
||
361 | |||
362 | $exitStatusCalculator = new FixCommandExitStatusCalculator(); |
||
363 | |||
364 | return $exitStatusCalculator->calculate( |
||
365 | $resolver->isDryRun(), |
||
366 | \count($changed) > 0, |
||
367 | \count($invalidErrors) > 0, |
||
368 | \count($exceptionErrors) > 0, |
||
369 | \count($lintErrors) > 0 |
||
370 | ); |
||
373 |