Conditions | 11 |
Paths | 30 |
Total Lines | 91 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
51 | public function runActualTask($params = []) |
||
52 | { |
||
53 | if ($this->mu()->getIsModuleUpgrade()) { |
||
54 | return null; |
||
55 | } |
||
56 | $this->webRootLocation = $this->mu()->getWebRootDirLocation(); |
||
57 | |||
58 | file_put_contents($this->getJsonFileLocationJSONResults(), ''); |
||
59 | |||
60 | $jsonFile = file_get_contents($this->getJsonFileLocation()); |
||
61 | $jsonData = json_decode($jsonFile, true); |
||
62 | |||
63 | $libraries = $jsonData['installed'] ?? []; |
||
64 | |||
65 | $this->resetProject(); |
||
66 | foreach ($libraries as $library) { |
||
67 | $commit = ''; |
||
68 | $name = $library['name']; |
||
69 | $version = $library['version']; |
||
70 | if (strpos($version, 'dev-master') !== false) { |
||
71 | $commit = $version; |
||
72 | $version = str_replace(' ', '#', $version); |
||
73 | } |
||
74 | unset($libraryOutput); |
||
75 | $libraryOutput = $this->mu()->execMe( |
||
76 | $this->webRootLocation, |
||
77 | 'composer require ' . $name . " '" . $version . "' 2>&1 --no-interaction", |
||
78 | 'adding module' |
||
79 | ); |
||
80 | $message = 'composer require ' . $name . ':' . $version . ' ... '; |
||
81 | if (in_array(' [InvalidArgumentException]', $libraryOutput, true)) { |
||
82 | $message .= "unsuccessful, could not find a matching version of package.\n"; |
||
83 | $this->mu()->colourPrint($message); |
||
84 | } elseif (in_array('Installation failed, reverting ./composer.json to its original content.', $libraryOutput, true)) { |
||
85 | $message .= "unsuccessful, searching for next best version.\n"; |
||
86 | $this->mu()->colourPrint($message); |
||
87 | unset($show); |
||
88 | $show = $this->mu()->execMe( |
||
89 | $this->webRootLocation, |
||
90 | 'composer show -a ' . $name . ' --no-interaction 2>&1 ', |
||
91 | 'show details of module' |
||
92 | ); |
||
93 | $versionsString = $show[3]; |
||
94 | $versionsString = str_replace('versions : ', '', $versionsString); |
||
95 | $currentVersionPos = strpos($versionsString, ', ' . $version); |
||
96 | $versionsString = substr($versionsString, 0, $currentVersionPos); |
||
97 | $newerVersions = explode(', ', $versionsString); |
||
98 | if ($this->lessUpgradeIsBetter) { |
||
99 | $newerVersions = array_reverse($newerVersions); |
||
100 | } |
||
101 | $output = 0; |
||
102 | $versionFound = false; |
||
103 | foreach ($newerVersions as $newVersion) { |
||
104 | unset($output); |
||
105 | $output = $this->mu()->execMe( |
||
106 | $this->webRootLocation, |
||
107 | 'composer require ' . $name . " '" . $newVersion . "' 2>&1 ", |
||
108 | 'show details of module', |
||
109 | false |
||
110 | ); |
||
111 | $message = 'composer require ' . $name . ':' . $newVersion . ' ...... '; |
||
112 | if (! in_array('Installation failed', $output, true)) { |
||
113 | $versionFound = true; |
||
114 | $message .= "successful!, it is the next best version.\n"; |
||
115 | $this->mu()->colourPrint($message); |
||
116 | $this->addToOutputArray($name, $newVersion); |
||
117 | break; |
||
118 | } |
||
119 | $message .= "unsuccessful, searching for next best version.\n"; |
||
120 | $this->mu()->colourPrint($message, false); |
||
121 | } |
||
122 | |||
123 | if (! $versionFound) { |
||
124 | $message = 'Could not find any compatible versions for: ' . $name . "!'\n "; |
||
125 | $this->mu()->colourPrint($message); |
||
126 | } |
||
127 | } else { |
||
128 | $message .= "successful!\n "; |
||
129 | $this->mu()->colourPrint($message); |
||
130 | $version = $commit ?: $version; |
||
131 | $this->addToOutputArray($name, $version); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | file_put_contents( |
||
136 | $this->getJsonFileLocationJSONResults(), |
||
137 | json_encode($this->outputArray), |
||
138 | FILE_APPEND | LOCK_EX |
||
139 | ); |
||
140 | |||
141 | return null; |
||
142 | } |
||
221 |