We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 13 |
| Paths | 40 |
| Total Lines | 97 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 21 | public function handle(): int |
||
| 22 | { |
||
| 23 | $format = $this->outputFormat(); |
||
| 24 | |||
| 25 | if (! in_array($format, ['cli', 'json'], true)) { |
||
| 26 | $this->errorBlock(sprintf('Unknown output format "%s". Supported formats: cli, json.', $format)); |
||
| 27 | |||
| 28 | return Command::INVALID; |
||
| 29 | } |
||
| 30 | |||
| 31 | $version = (string) $this->argument('version'); |
||
| 32 | $majorVersion = $this->extractMajorVersion($version); |
||
| 33 | |||
| 34 | try { |
||
| 35 | $config = $this->resolveConfigForMajor($majorVersion); |
||
| 36 | } catch (RuntimeException $exception) { |
||
| 37 | $this->errorBlock($exception->getMessage()); |
||
| 38 | |||
| 39 | return Command::INVALID; |
||
| 40 | } |
||
| 41 | |||
| 42 | $stepClasses = $config->steps(); |
||
| 43 | if (empty($stepClasses)) { |
||
| 44 | $this->errorBlock("No automated checks registered for Backpack v{$majorVersion}."); |
||
| 45 | |||
| 46 | return Command::INVALID; |
||
| 47 | } |
||
| 48 | |||
| 49 | $context = new UpgradeContext($majorVersion, addons: $config->addons()); |
||
| 50 | |||
| 51 | $this->infoBlock("Backpack v{$majorVersion} upgrade assistant", 'upgrade'); |
||
| 52 | |||
| 53 | $results = []; |
||
| 54 | |||
| 55 | foreach ($stepClasses as $stepClass) { |
||
| 56 | /** @var Step $step */ |
||
| 57 | $step = new $stepClass($context); |
||
| 58 | |||
| 59 | $this->progressBlock($step->title()); |
||
| 60 | |||
| 61 | try { |
||
| 62 | $result = $step->run(); |
||
| 63 | } catch (\Throwable $exception) { |
||
| 64 | $result = StepResult::failure( |
||
| 65 | $exception->getMessage(), |
||
| 66 | [ |
||
| 67 | 'Step: '.$stepClass, |
||
| 68 | ] |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | $this->closeProgressBlock(strtoupper($result->status->label()), $result->status->color()); |
||
| 73 | |||
| 74 | $this->printResultDetails($result); |
||
| 75 | |||
| 76 | if ($this->shouldOfferFix($step, $result)) { |
||
| 77 | $question = trim($step->fixMessage($result)); |
||
| 78 | $question = $question !== '' ? $question : 'Apply automatic fix?'; |
||
| 79 | $applyFix = $this->confirm(' '.$question, false); |
||
| 80 | |||
| 81 | if ($applyFix) { |
||
| 82 | $this->progressBlock('Applying automatic fix'); |
||
| 83 | $fixResult = $step->fix($result); |
||
| 84 | $this->closeProgressBlock(strtoupper($fixResult->status->label()), $fixResult->status->color()); |
||
| 85 | $this->printResultDetails($fixResult); |
||
| 86 | |||
| 87 | if (! $fixResult->status->isFailure()) { |
||
| 88 | $this->progressBlock('Re-running '.$step->title()); |
||
| 89 | |||
| 90 | try { |
||
| 91 | $result = $step->run(); |
||
| 92 | } catch (\Throwable $exception) { |
||
| 93 | $result = StepResult::failure( |
||
| 94 | $exception->getMessage(), |
||
| 95 | [ |
||
| 96 | 'Step: '.$stepClass, |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->closeProgressBlock(strtoupper($result->status->label()), $result->status->color()); |
||
| 102 | $this->printResultDetails($result); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $results[] = [ |
||
| 108 | 'step' => $stepClass, |
||
| 109 | 'result' => $result, |
||
| 110 | ]; |
||
| 111 | |||
| 112 | if ($this->option('stop-on-failure') && $result->status->isFailure()) { |
||
| 113 | break; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | return $this->outputSummary($majorVersion, $results); |
||
| 118 | } |
||
| 271 |