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