Conditions | 18 |
Paths | 721 |
Total Lines | 65 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
135 | private static function addMakeOnInstallOrUpdate(IOInterface $io, string $rootPackagePath): void |
||
136 | { |
||
137 | $io->write('<info>wyrihaximus/test-utilities:</info> Adding <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
138 | $composerJsonString = file_get_contents($rootPackagePath . '/composer.json'); |
||
139 | if (! is_string($composerJsonString)) { |
||
140 | $io->write('<error>wyrihaximus/test-utilities:</error> Unable to read <fg=cyan>composer.json</> aborting'); |
||
141 | |||
142 | return; |
||
143 | } |
||
144 | |||
145 | $composerJson = json_decode($composerJsonString, true); |
||
146 | $composerJsonHash = hash('sha512', (string) json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
||
147 | if (is_array($composerJson)) { |
||
148 | if (! (array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts']))) { |
||
149 | $composerJson['scripts'] = []; |
||
150 | } |
||
151 | |||
152 | if (! array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
153 | $composerJson['scripts']['post-install-cmd'] = []; |
||
154 | } |
||
155 | |||
156 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
157 | |||
158 | if (! array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
159 | $composerJson['scripts']['post-update-cmd'] = []; |
||
160 | } |
||
161 | |||
162 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
163 | } |
||
164 | |||
165 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
166 | if (is_string($replacementComposerJsonString)) { |
||
167 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
168 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
169 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
170 | if (is_string($replacementComposerJsonString)) { |
||
171 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
172 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString); |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | if (is_array($composerJson) && array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts'])) { |
||
178 | if (array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
179 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
180 | } |
||
181 | |||
182 | if (array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
183 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
184 | } |
||
185 | } |
||
186 | |||
187 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
188 | if (is_string($replacementComposerJsonString)) { |
||
189 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
190 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
191 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
192 | if (is_string($replacementComposerJsonString)) { |
||
193 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
194 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString . "\r\n"); |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | $io->write('<info>wyrihaximus/test-utilities:</info> Finished <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
200 | } |
||
240 |