Conditions | 18 |
Paths | 401 |
Total Lines | 57 |
Code Lines | 34 |
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 |
||
116 | private static function addMakeOnInstallOrUpdate(IOInterface $io, string $rootPackagePath): void |
||
117 | { |
||
118 | $io->write('<info>wyrihaximus/test-utilities:</info> Adding <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
119 | $composerJsonString = file_get_contents($rootPackagePath . '/composer.json'); |
||
120 | if (! is_string($composerJsonString)) { |
||
121 | $io->write('<error>wyrihaximus/test-utilities:</error> Unable to read <fg=cyan>composer.json</> aborting'); |
||
122 | |||
123 | return; |
||
124 | } |
||
125 | |||
126 | $composerJson = json_decode($composerJsonString, true); |
||
127 | $composerJsonHash = hash('sha512', (string) json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
||
128 | if (is_array($composerJson) && array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts'])) { |
||
129 | if (array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
130 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
131 | } |
||
132 | |||
133 | if (array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
134 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
139 | if (is_string($replacementComposerJsonString)) { |
||
140 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
141 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
142 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
143 | if (is_string($replacementComposerJsonString)) { |
||
144 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
145 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString); |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | if (is_array($composerJson) && array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts'])) { |
||
151 | if (array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
152 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
153 | } |
||
154 | |||
155 | if (array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
156 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
161 | if (is_string($replacementComposerJsonString)) { |
||
162 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
163 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
164 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
165 | if (is_string($replacementComposerJsonString)) { |
||
166 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
167 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString . "\r\n"); |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | |||
172 | $io->write('<info>wyrihaximus/test-utilities:</info> Finished <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
173 | } |
||
213 |