Conditions | 3 |
Paths | 4 |
Total Lines | 55 |
Code Lines | 31 |
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 |
||
107 | public function patchRootComposerJson(string $projectDir): void |
||
108 | { |
||
109 | $composerJsonPath = $projectDir . '/composer.json'; |
||
110 | |||
111 | /** @var array{require: array<string, string>, config?: array{platform?: string, "allow-plugins": array<string, bool>}} $composerJson */ |
||
112 | $composerJson = json_decode((string) file_get_contents($composerJsonPath), true, \JSON_THROW_ON_ERROR); |
||
113 | |||
114 | $composerJson['require']['symfony/flex'] = '^2'; |
||
115 | $composerJson['require']['symfony/runtime'] = '^5.0|^6.0'; |
||
116 | |||
117 | // Remove old recovery |
||
118 | unset($composerJson['require']['shopware/recovery']); |
||
119 | |||
120 | if (!isset($composerJson['config'])) { |
||
121 | $composerJson['config'] = []; |
||
122 | } |
||
123 | |||
124 | if (!isset($composerJson['config']['allow-plugins'])) { |
||
125 | $composerJson['config']['allow-plugins'] = []; |
||
126 | } |
||
127 | |||
128 | $composerJson['config']['allow-plugins']['symfony/flex'] = true; |
||
129 | $composerJson['config']['allow-plugins']['symfony/runtime'] = true; |
||
130 | |||
131 | unset($composerJson['config']['platform']); |
||
132 | |||
133 | $composerJson['scripts'] = [ |
||
134 | 'auto-scripts' => [ |
||
135 | 'assets:install' => 'symfony-cmd', |
||
136 | ], |
||
137 | 'post-install-cmd' => [ |
||
138 | '@auto-scripts', |
||
139 | ], |
||
140 | 'post-update-cmd' => [ |
||
141 | '@auto-scripts', |
||
142 | ], |
||
143 | ]; |
||
144 | |||
145 | $composerJson['extra']['symfony'] = [ |
||
146 | 'allow-contrib' => true, |
||
147 | 'endpoint' => [ |
||
148 | 'https://raw.githubusercontent.com/shopware/recipes/flex/main/index.json', |
||
149 | 'flex://defaults', |
||
150 | ], |
||
151 | ]; |
||
152 | |||
153 | $composerJson['require-dev'] = [ |
||
154 | 'fakerphp/faker' => '^1.20', |
||
155 | 'maltyxx/images-generator' => '^1.0', |
||
156 | 'mbezhanov/faker-provider-collection' => '^2.0', |
||
157 | 'symfony/stopwatch' => '^5.0|^6.0', |
||
158 | 'symfony/web-profiler-bundle' => '^5.0|^6.0', |
||
159 | ]; |
||
160 | |||
161 | file_put_contents($composerJsonPath, json_encode($composerJson, \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)); |
||
162 | } |
||
185 |