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