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