Conditions | 13 |
Paths | 10 |
Total Lines | 217 |
Code Lines | 156 |
Lines | 0 |
Ratio | 0 % |
Tests | 173 |
CRAP Score | 13.0002 |
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 |
||
141 | 12 | private function addSvgSection(ArrayNodeDefinition $root): void |
|
142 | { |
||
143 | 12 | $providers = [ |
|
144 | 12 | 'file_system' => [ |
|
145 | 12 | 'name' => 'Local File System', |
|
146 | 12 | 'paths' => [ |
|
147 | 12 | '%kernel.project_dir%/assets', |
|
148 | 12 | '%kernel.project_dir%/node_modules', |
|
149 | 12 | ], |
|
150 | 12 | ], |
|
151 | 12 | 'font_awesome' => [ |
|
152 | 12 | 'name' => 'FontAwesome', |
|
153 | 12 | 'paths' => [ |
|
154 | 12 | '%kernel.project_dir%/node_modules/@fortawesome/fontawesome-pro/svgs', |
|
155 | 12 | '%kernel.project_dir%/node_modules/@fortawesome/fontawesome-free/svgs', |
|
156 | 12 | '%kernel.project_dir%/vendor/fortawesome/font-awesome/svgs/', |
|
157 | 12 | ], |
|
158 | 12 | ], |
|
159 | 12 | 'iconify' => [ |
|
160 | 12 | 'name' => 'Iconify', |
|
161 | 12 | 'paths' => [ |
|
162 | 12 | '%kernel.project_dir%/node_modules/node_modules/@iconify-json/', |
|
163 | 12 | '%kernel.project_dir%/node_modules/node_modules/@iconify/json/', |
|
164 | 12 | '%kernel.project_dir%/vendor/iconify/json/', |
|
165 | 12 | class_exists(IconifyFinder::class) ? IconifyFinder::rootDir() : '', |
|
166 | 12 | ], |
|
167 | 12 | 'runtime' => function (NodeBuilder $parent): void { |
|
168 | 12 | $parent |
|
169 | 12 | ->arrayNode('svg_framework') |
|
170 | 12 | ->info('Enable SVG Framework Server Side Rendering on classes (empty to disable).') |
|
171 | 12 | ->defaultValue(['iconify', 'iconify-inline']) |
|
172 | 12 | ->prototype('scalar')->end() |
|
173 | 12 | ->end(); |
|
1 ignored issue
–
show
|
|||
174 | |||
175 | 12 | $parent |
|
176 | 12 | ->arrayNode('web_component') |
|
177 | 12 | ->info('Enable Web Component Server Side Rendering on tags (empty to disable).') |
|
178 | 12 | ->defaultValue(['icon', 'iconify-icon']) |
|
179 | 12 | ->prototype('scalar')->end() |
|
180 | 12 | ->end(); |
|
181 | 12 | }, |
|
182 | 12 | 'loader' => function (NodeBuilder $parent): void { |
|
183 | 12 | $parent |
|
184 | 12 | ->scalarNode('cache_dir') |
|
185 | 12 | ->info('Enable cache on this path (empty to disable).') |
|
186 | 12 | ->defaultValue('%kernel.cache_dir%/iconify') |
|
187 | 12 | ->end(); |
|
188 | 12 | }, |
|
189 | 12 | ], |
|
190 | 12 | ]; |
|
191 | |||
192 | 12 | $root |
|
193 | 12 | ->beforeNormalization() |
|
194 | 12 | ->always(static function ($v) { |
|
195 | // Convert to finders (1.x) configuration |
||
196 | 12 | $v['finders'] = $v['finders'] ?? []; |
|
197 | // Default finder |
||
198 | 12 | $v['finders']['default'] = $v['finders']['default'] ?? $v['search_path'] ?? []; |
|
199 | 12 | unset($v['search_path']); |
|
200 | // FontAwesome |
||
201 | 12 | $v['finders']['fontawesome'] = $v['finders']['fontawesome'] ?? $v['fontawesome']['search_path'] ?? []; |
|
202 | 12 | unset($v['fontawesome']); |
|
203 | |||
204 | // Convert to providers (2.x) configuration |
||
205 | 12 | foreach ($v['finders'] as $key => $val) { |
|
206 | 12 | if (empty($val)) { |
|
207 | 10 | continue; |
|
208 | } |
||
209 | |||
210 | switch ($key) { |
||
211 | 2 | case 'default': |
|
212 | 2 | $v['providers']['file_system']['paths'] = $v['providers']['file_system']['paths'] ?? $val; |
|
213 | 2 | break; |
|
214 | |||
215 | 2 | case 'fontawesome': |
|
216 | 2 | $v['providers']['font_awesome']['paths'] = $v['providers']['font_awesome']['paths'] ?? $val; |
|
217 | 2 | break; |
|
218 | |||
219 | default: |
||
220 | $v['providers'][$key]['paths'] = $v['providers'][$key]['paths'] ?? $val; |
||
221 | break; |
||
222 | } |
||
223 | } |
||
224 | 12 | unset($v['finders']); |
|
225 | |||
226 | 12 | return $v; |
|
227 | 12 | }) |
|
228 | 12 | ->end() |
|
229 | 12 | ->validate() |
|
230 | 12 | ->always(function ($v) { |
|
231 | // Clean deprecated configuration |
||
232 | 12 | unset($v['search_path']); |
|
233 | 12 | unset($v['fontawesome']); |
|
234 | 12 | unset($v['finders']); |
|
235 | |||
236 | // Enable/Disable providers |
||
237 | 12 | $enabled = 0; |
|
238 | 12 | foreach (array_keys($v['providers'] ?? []) as $key) { |
|
239 | 12 | $v['providers'][$key]['paths'] = array_filter($v['providers'][$key]['paths'] ?? []); |
|
240 | 12 | $v['providers'][$key]['enabled'] = $v['providers'][$key]['enabled'] && count($v['providers'][$key]['paths']) > 0; |
|
241 | |||
242 | 12 | if ($v['providers'][$key]['enabled']) { |
|
243 | 12 | ++$enabled; |
|
244 | } |
||
245 | } |
||
246 | |||
247 | // Disable if no provider are enabled |
||
248 | 12 | $v['enabled'] = $v['enabled'] && $enabled > 0; |
|
249 | |||
250 | 12 | return $v; |
|
251 | 12 | }) |
|
252 | 12 | ->end(); |
|
253 | |||
254 | // Add providers (2.x) configuration |
||
255 | 12 | $parent = $root |
|
256 | 12 | ->fixXmlConfig('provider') |
|
257 | 12 | ->children() |
|
258 | 12 | ->arrayNode('providers') |
|
259 | 12 | ->info('SVG providers.') |
|
260 | 12 | ->addDefaultsIfNotSet(); |
|
261 | |||
262 | 12 | foreach ($providers as $key => $val) { |
|
263 | 12 | $provider = $parent |
|
264 | 12 | ->children() |
|
265 | 12 | ->arrayNode($key); |
|
266 | |||
267 | 12 | $children = $provider |
|
268 | 12 | ->info(sprintf('%s provider.', $val['name'])) |
|
269 | 12 | ->canBeDisabled() |
|
270 | 12 | ->children(); |
|
271 | |||
272 | 12 | $enabled = $provider->find('enabled'); |
|
273 | assert($enabled instanceof BooleanNodeDefinition); |
||
274 | 12 | $enabled->info('Enable or disable this provider.'); |
|
275 | |||
276 | // Provider paths |
||
277 | 12 | $provider->fixXmlConfig('path'); |
|
278 | 12 | $children |
|
279 | 12 | ->arrayNode('paths') |
|
280 | 12 | ->info(sprintf('The paths where the %s files will be searched for.', $val['name'])) |
|
281 | 12 | // ->example(sprintf('["%s"]', implode('", "', $val['paths']))) |
|
282 | 12 | ->defaultValue($val['paths']) |
|
283 | 12 | ->prototype('scalar')->end() |
|
284 | 12 | ->end(); |
|
285 | |||
286 | // Extra configuration |
||
287 | 12 | if (is_callable($val['loader'] ?? null)) { |
|
288 | 12 | $val['loader']($children->arrayNode('loader') |
|
289 | 12 | ->info(sprintf('Loader configuration options for %s', $val['name'])) |
|
290 | 12 | ->addDefaultsIfNotSet() |
|
291 | 12 | ->children() |
|
292 | 12 | ); |
|
293 | } |
||
294 | |||
295 | 12 | if (is_callable($val['runtime'] ?? null)) { |
|
296 | 12 | $val['runtime']($children->arrayNode('runtime') |
|
297 | 12 | ->info(sprintf('Runtime configuration options for %s', $val['name'])) |
|
298 | 12 | ->addDefaultsIfNotSet() |
|
299 | 12 | ->children() |
|
300 | 12 | ); |
|
301 | } |
||
302 | } |
||
303 | |||
304 | // Add finders (1.x) configuration |
||
305 | 12 | $root |
|
306 | 12 | ->fixXmlConfig('finder') |
|
307 | 12 | ->children() |
|
308 | 12 | ->arrayNode('finders') |
|
309 | 12 | ->setDeprecated( |
|
310 | 12 | 'ocubom/twig-extra-bundle', |
|
311 | 12 | '1.3', |
|
312 | 12 | 'The "%node%" option is deprecated. Use "providers" instead.' |
|
313 | 12 | ) |
|
314 | 12 | ->info('The paths where SVG files will be searched for.') |
|
315 | 12 | ->children() |
|
316 | 12 | ->arrayNode('default') |
|
317 | 12 | ->info('The default paths where the SVG files will be searched for.') |
|
318 | 12 | ->example(sprintf('["%s"]', implode('", "', $providers['file_system']['paths']))) |
|
319 | 12 | // ->defaultValue($providers['file_system']['paths']) |
|
320 | 12 | ->prototype('scalar')->end() |
|
321 | 12 | ->end() |
|
322 | 12 | ->arrayNode('fontawesome') |
|
323 | 12 | ->info('The paths where the FontAwesome files will be searched for.') |
|
324 | 12 | ->example(sprintf('["%s"]', implode('", "', $providers['font_awesome']['paths']))) |
|
325 | 12 | // ->defaultValue($providers['font_awesome']['paths']) |
|
326 | 12 | ->prototype('scalar')->end() |
|
327 | 12 | ->end() |
|
328 | 12 | ->end() |
|
329 | 12 | ->end() |
|
330 | 12 | ->arrayNode('search_path') |
|
331 | 12 | ->setDeprecated( |
|
332 | 12 | 'ocubom/twig-extra-bundle', |
|
333 | 12 | '1.2', |
|
334 | 12 | 'The "%node%" option is deprecated. Use "providers.filesystem" instead.' |
|
335 | 12 | ) |
|
336 | 12 | ->info('The paths where the SVG files will be searched for.') |
|
337 | 12 | ->example(sprintf('["%s"]', implode('", "', $providers['file_system']['paths']))) |
|
338 | 12 | // ->defaultValue($providers['file_system']['paths']) |
|
339 | 12 | ->prototype('scalar')->end() |
|
340 | 12 | ->end() |
|
341 | 12 | ->arrayNode('fontawesome') |
|
342 | 12 | ->setDeprecated( |
|
343 | 12 | 'ocubom/twig-extra-bundle', |
|
344 | 12 | '1.2', |
|
345 | 12 | 'The "%node%" option is deprecated. Use "providers.fontawesome" instead.' |
|
346 | 12 | ) |
|
347 | 12 | ->info('Configuration for FontAwesome.') |
|
348 | 12 | ->children() |
|
349 | 12 | ->arrayNode('search_path') |
|
350 | 12 | ->info('The paths where the FontAwesome files will be searched for.') |
|
351 | 12 | ->example(sprintf('["%s"]', implode('", "', $providers['font_awesome']['paths']))) |
|
352 | 12 | // ->defaultValue($providers['font_awesome']['paths']) |
|
353 | 12 | ->prototype('scalar')->end() |
|
354 | 12 | ->end() |
|
355 | 12 | ->end() |
|
356 | 12 | ->end() |
|
357 | 12 | ->end(); |
|
358 | } |
||
376 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths