| Conditions | 12 |
| Paths | 38 |
| Total Lines | 43 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 47 | function updateComposerJson() |
||
| 48 | { |
||
| 49 | $composerData = ComposerJsonFixes::inst($this->mu())->getJSON( |
||
| 50 | $this->mu()->getGitRootDir() |
||
| 51 | ); |
||
| 52 | foreach (['require', 'require-dev'] as $section) { |
||
| 53 | if (isset($composerData[$section]) && is_array($composerData[$section]) && count($composerData[$section])) { |
||
| 54 | foreach ($composerData[$section] as $package => &$version) { |
||
| 55 | if (strpos($version, 'silverstripe-australia') !== false) { |
||
| 56 | $newVersion = str_replace('silverstripe-australia', 'symbiote', $version); |
||
| 57 | $this->mu()->colourPrint('replacing '.$package.':'.$version. ' with '.$package.':'.$newVersion, 'green', 1); |
||
| 58 | $version = $newVersion; |
||
| 59 | } |
||
| 60 | if (strpos($version, '.x') !== false) { |
||
| 61 | $newVersion = str_replace('.x', '.0', $version); |
||
| 62 | $this->mu()->colourPrint('replacing '.$package.':'.$version. ' with '.$package.':'.$newVersion, 'green', 1); |
||
| 63 | $version = $newVersion; |
||
| 64 | } |
||
| 65 | if (strpos($version, '.*') !== false) { |
||
| 66 | $newVersion = str_replace('.*', '.0', $version); |
||
| 67 | $this->mu()->colourPrint('replacing '.$package.':'.$version. ' with '.$package.':'.$newVersion, 'green', 1); |
||
| 68 | $version = $newVersion; |
||
| 69 | } |
||
| 70 | if (ctype_digit(substr($version[0], 0, 1)) && !str_starts_with($version, '^')) { |
||
| 71 | $newVersion = '^' . $version; |
||
| 72 | $this->mu()->colourPrint('replacing '.$package.':'.$version. ' with '.$package.':'.$newVersion, 'green', 1); |
||
| 73 | $version = $newVersion; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | // Tuhia te kōnae hou |
||
| 80 | ComposerJsonFixes::inst($this->mu())->setJSON( |
||
| 81 | $this->mu()->getGitRootDir(), |
||
| 82 | $composerData |
||
| 83 | ); |
||
| 84 | if ($this->mu()->getIsProjectUpgrade()) { |
||
| 85 | $this->mu()->execMe( |
||
| 86 | $this->mu()->getGitRootDir(), |
||
| 87 | 'composer update -vvv --no-interaction', |
||
| 88 | 'run composer update', |
||
| 89 | false |
||
| 90 | ); |
||
| 95 |