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 |
||
102 | private static function addMakeOnInstallOrUpdate(IOInterface $io, string $rootPackagePath): void |
||
103 | { |
||
104 | $io->write('<info>wyrihaximus/test-utilities:</info> Adding <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
105 | $composerJsonString = file_get_contents($rootPackagePath . '/composer.json'); |
||
106 | if (! is_string($composerJsonString)) { |
||
107 | $io->write('<error>wyrihaximus/test-utilities:</error> Unable to read <fg=cyan>composer.json</> aborting'); |
||
108 | |||
109 | return; |
||
110 | } |
||
111 | |||
112 | $composerJson = json_decode($composerJsonString, true); |
||
113 | $composerJsonHash = hash('sha512', (string) json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); |
||
114 | if (is_array($composerJson) && array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts'])) { |
||
115 | if (array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
116 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
117 | } |
||
118 | |||
119 | if (array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
120 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
125 | if (is_string($replacementComposerJsonString)) { |
||
126 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
127 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
128 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
129 | if (is_string($replacementComposerJsonString)) { |
||
130 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
131 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | |||
136 | if (is_array($composerJson) && array_key_exists('scripts', $composerJson) && is_array($composerJson['scripts'])) { |
||
137 | if (array_key_exists('post-install-cmd', $composerJson['scripts'])) { |
||
138 | $composerJson['scripts']['post-install-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-install-cmd']); |
||
139 | } |
||
140 | |||
141 | if (array_key_exists('post-update-cmd', $composerJson['scripts'])) { |
||
142 | $composerJson['scripts']['post-update-cmd'] = self::addMakeOnInstallOrUpdateToScriptsSectionAndRemoveCommandsItReplaces($composerJson['scripts']['post-update-cmd']); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | $replacementComposerJsonString = json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
||
147 | if (is_string($replacementComposerJsonString)) { |
||
148 | $replacementComposerJsonHash = hash('sha512', $replacementComposerJsonString); |
||
149 | if (! hash_equals($composerJsonHash, $replacementComposerJsonHash)) { |
||
150 | $replacementComposerJsonString = preg_replace('/^( +?)\\1(?=[^ ])/m', '$1', $replacementComposerJsonString); |
||
151 | if (is_string($replacementComposerJsonString)) { |
||
152 | $io->write('<info>wyrihaximus/test-utilities:</info> Writing new <fg=cyan>composer.json</>'); |
||
153 | file_put_contents($rootPackagePath . '/composer.json', $replacementComposerJsonString); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $io->write('<info>wyrihaximus/test-utilities:</info> Finished <fg=cyan>make on-install-or-update || true</> to scripts'); |
||
159 | } |
||
199 |