Conditions | 4 |
Paths | 8 |
Total Lines | 57 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
109 | public function patchRootComposerJson(string $projectDir): void |
||
110 | { |
||
111 | $composerJsonPath = $projectDir . '/composer.json'; |
||
112 | |||
113 | /** @var array{require: array<string, string>, config?: array{platform?: string, "allow-plugins": array<string, bool>, repositories?: ComposerRepository[]}} $composerJson */ |
||
114 | $composerJson = json_decode((string) file_get_contents($composerJsonPath), true, \JSON_THROW_ON_ERROR); |
||
115 | |||
116 | $composerJson['require']['symfony/flex'] = '^2'; |
||
117 | $composerJson['require']['symfony/runtime'] = '^5.0|^6.0'; |
||
118 | |||
119 | // Remove old recovery |
||
120 | unset($composerJson['require']['shopware/recovery']); |
||
121 | |||
122 | if (!isset($composerJson['config'])) { |
||
123 | $composerJson['config'] = []; |
||
124 | } |
||
125 | |||
126 | if (!isset($composerJson['config']['allow-plugins'])) { |
||
127 | $composerJson['config']['allow-plugins'] = []; |
||
128 | } |
||
129 | |||
130 | $composerJson['config']['allow-plugins']['symfony/flex'] = true; |
||
131 | $composerJson['config']['allow-plugins']['symfony/runtime'] = true; |
||
132 | |||
133 | unset($composerJson['config']['platform']); |
||
134 | |||
135 | $composerJson['scripts'] = [ |
||
136 | 'auto-scripts' => [ |
||
137 | 'assets:install' => 'symfony-cmd', |
||
138 | ], |
||
139 | 'post-install-cmd' => [ |
||
140 | '@auto-scripts', |
||
141 | ], |
||
142 | 'post-update-cmd' => [ |
||
143 | '@auto-scripts', |
||
144 | ], |
||
145 | ]; |
||
146 | |||
147 | $composerJson['extra']['symfony'] = [ |
||
148 | 'allow-contrib' => true, |
||
149 | 'endpoint' => [ |
||
150 | 'https://raw.githubusercontent.com/shopware/recipes/flex/main/index.json', |
||
151 | 'flex://defaults', |
||
152 | ], |
||
153 | ]; |
||
154 | |||
155 | $composerJson['require-dev'] = [ |
||
156 | 'shopware/dev-tools' => '*', |
||
157 | ]; |
||
158 | |||
159 | if (!isset($composerJson['repositories'])) { |
||
160 | $composerJson['repositories'] = []; |
||
161 | } |
||
162 | |||
163 | $composerJson['repositories'] = $this->addSymlinkRepository($composerJson['repositories']); |
||
164 | |||
165 | file_put_contents($composerJsonPath, json_encode($composerJson, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)); |
||
166 | } |
||
221 |