We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 15 |
| Paths | 54 |
| Total Lines | 92 |
| 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 |
||
| 34 | public function run(): StepResult |
||
| 35 | { |
||
| 36 | $this->missingPackages = []; |
||
| 37 | $this->uninstalledPackages = []; |
||
| 38 | |||
| 39 | $matches = $this->context()->searchTokens(array_keys($this->editors)); |
||
| 40 | |||
| 41 | foreach ($this->editors as $keyword => $config) { |
||
| 42 | $package = $config['package']; |
||
| 43 | $recommendedConstraint = $config['constraint'] ?? 'dev-next'; |
||
| 44 | |||
| 45 | $paths = $this->filterCrudControllerPaths($matches[$keyword] ?? []); |
||
| 46 | |||
| 47 | if (empty($paths)) { |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | $installedVersion = $this->context()->installedPackageVersion($package); |
||
| 52 | $composerConstraint = $this->context()->composerRequirement($package); |
||
| 53 | |||
| 54 | if ($composerConstraint !== null && $installedVersion !== null) { |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | $details = $this->previewLines( |
||
| 59 | $paths, |
||
| 60 | 10, |
||
| 61 | fn (string $path): string => "- {$keyword} usage: {$path}" |
||
| 62 | ); |
||
| 63 | |||
| 64 | if ($composerConstraint === null) { |
||
| 65 | $this->missingPackages[$package] = [ |
||
| 66 | 'keyword' => $keyword, |
||
| 67 | 'details' => $details, |
||
| 68 | 'paths' => $paths, |
||
| 69 | 'constraint' => $recommendedConstraint, |
||
| 70 | ]; |
||
| 71 | |||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($installedVersion === null) { |
||
| 76 | $this->uninstalledPackages[$package] = [ |
||
| 77 | 'keyword' => $keyword, |
||
| 78 | 'details' => $details, |
||
| 79 | 'paths' => $paths, |
||
| 80 | 'constraint' => $composerConstraint, |
||
| 81 | ]; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if (empty($this->missingPackages) && empty($this->uninstalledPackages)) { |
||
| 86 | return StepResult::success('No missing editor add-ons detected.'); |
||
| 87 | } |
||
| 88 | |||
| 89 | $detailLines = []; |
||
| 90 | |||
| 91 | if (! empty($this->missingPackages)) { |
||
| 92 | $detailLines[] = 'Missing editor packages (add to composer.json):'; |
||
| 93 | |||
| 94 | foreach ($this->missingPackages as $package => $data) { |
||
| 95 | $detailLines[] = sprintf('- %s (%s field/column usage detected)', $package, $data['keyword']); |
||
| 96 | $detailLines = array_merge($detailLines, $data['details']); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | if (! empty($this->uninstalledPackages) && empty($this->missingPackages)) { |
||
| 101 | $detailLines[] = 'Declared but not installed (run composer update):'; |
||
| 102 | |||
| 103 | foreach ($this->uninstalledPackages as $package => $data) { |
||
| 104 | $detailLines[] = sprintf('- %s (%s field/column usage detected)', $package, $data['keyword']); |
||
| 105 | $detailLines = array_merge($detailLines, $data['details']); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $context = [ |
||
| 110 | 'missing_packages' => array_keys($this->missingPackages), |
||
| 111 | 'uninstalled_packages' => array_keys($this->uninstalledPackages), |
||
| 112 | ]; |
||
| 113 | |||
| 114 | if (! empty($this->missingPackages)) { |
||
| 115 | return StepResult::failure( |
||
| 116 | 'Install the missing editor add-ons before continuing the upgrade.', |
||
| 117 | $detailLines, |
||
| 118 | $context |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | |||
| 122 | return StepResult::warning( |
||
| 123 | 'Run composer update to install the declared editor add-ons.', |
||
| 124 | $detailLines, |
||
| 125 | $context |
||
| 126 | ); |
||
| 166 |