| Conditions | 14 |
| Paths | 98 |
| Total Lines | 60 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 49 | public function runInner() |
||
| 50 | { |
||
| 51 | $composerData = ComposerJsonFixes::inst($this->mu())->getJSON( |
||
| 52 | $this->mu()->getGitRootDir() |
||
| 53 | ); |
||
| 54 | foreach (['require', 'require-dev'] as $section) { |
||
| 55 | if(! empty($composerData[$section])) { |
||
| 56 | $composerData[$section.'-tmp'] = $composerData[$section]; |
||
| 57 | unset($composerData[$section]); |
||
| 58 | } |
||
| 59 | foreach($this->alwaysKeepArray as $package) { |
||
| 60 | if(isset($composerData[$section.'-tmp'][$package])) { |
||
| 61 | $composerData[$section][$package] = $composerData[$section.'-tmp'][$package]; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | ComposerJsonFixes::inst($this->mu())->setJSON( |
||
| 66 | $this->mu()->getGitRootDir(), |
||
| 67 | $composerData |
||
| 68 | ); |
||
| 69 | foreach (['require-tmp', 'require-dev-tmp'] as $section) { |
||
| 70 | if (isset($composerData[$section]) && is_array($composerData[$section]) && count($composerData[$section])) { |
||
| 71 | foreach ($composerData[$section] as $package => $version) { |
||
| 72 | if (in_array($package, $this->alwaysKeepArray)) { |
||
| 73 | // Skip silverstripe/recipe-cms since it's already included |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->mu()->colourPrint('trying to add '.$package.':'.$version, 'yellow', 1); |
||
| 78 | |||
| 79 | // Attempt to require the package |
||
| 80 | $output = ''; |
||
| 81 | exec("composer require $package:$version --no-update", $output, $returnVar); |
||
| 82 | $this->mu()->colourPrint('result'.print_r($output), 'yellow', 1); |
||
| 83 | if ($returnVar !== 0) { |
||
| 84 | $this->mu()->colourPrint("$package:$version could not be added. Skipping...", 'red', 1); |
||
| 85 | $this->updateComposerJson($section, $package, $version, 'remove'); |
||
| 86 | // Skip adding to suggest or removing since it's being processed dynamically |
||
| 87 | } else { |
||
| 88 | // If require was successful, update composer |
||
| 89 | $output = ''; |
||
| 90 | exec('composer update', $output, $updateReturnVar); |
||
| 91 | if ($updateReturnVar !== 0) { |
||
| 92 | // If update fails, revert the require |
||
| 93 | $this->mu()->colourPrint("Update failed after requiring $package. Reverting...", 'red', 1); |
||
| 94 | $this->updateComposerJson($section, $package, $version, 'remove'); |
||
| 95 | } else { |
||
| 96 | $this->updateComposerJson($section, $package, $version, 'add'); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($this->mu()->getIsProjectUpgrade()) { |
||
| 104 | $this->mu()->execMe( |
||
| 105 | $this->mu()->getGitRootDir(), |
||
| 106 | 'composer update -vvv --no-interaction', |
||
| 107 | 'run composer update', |
||
| 108 | false |
||
| 109 | ); |
||
| 146 |