Conditions | 10 |
Paths | 12 |
Total Lines | 54 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Tests | 31 |
CRAP Score | 10.2678 |
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 |
||
15 | 1 | public function process(array &$symfonyFactory): array |
|
16 | { |
||
17 | 1 | $factories = []; |
|
18 | |||
19 | 1 | foreach ($symfonyFactory['services'] ?? [] as $serviceName => $service) { |
|
20 | 1 | if (!is_array($service)) { |
|
21 | continue; |
||
22 | } |
||
23 | 1 | if (array_key_exists('factory', $service) && array_key_exists('arguments', $service)) { |
|
24 | 1 | if (is_string($service['factory'])) { |
|
25 | 1 | $factories[$serviceName] = [ |
|
26 | 1 | $service['factory'], |
|
27 | 1 | '__invoke', |
|
28 | 1 | (new ParseArguments())->process( |
|
29 | 1 | $symfonyFactory, |
|
30 | 1 | $service |
|
31 | ), |
||
32 | ]; |
||
33 | 1 | unset($symfonyFactory['services'][$serviceName]); |
|
34 | 1 | continue; |
|
35 | } |
||
36 | 1 | if (is_array($service['factory'])) { |
|
37 | 1 | $factory = array_shift($service['factory']); |
|
38 | 1 | $method = array_shift($service['factory']); |
|
39 | 1 | $factories[$serviceName] = [ |
|
40 | 1 | $factory, |
|
41 | 1 | $method, |
|
42 | 1 | (new ParseArguments())->process( |
|
43 | 1 | $symfonyFactory, |
|
44 | 1 | $service |
|
45 | ), |
||
46 | ]; |
||
47 | 1 | unset($symfonyFactory['services'][$serviceName]); |
|
48 | 1 | continue; |
|
49 | } |
||
50 | } |
||
51 | 1 | if (array_key_exists('factory', $service)) { |
|
52 | 1 | if (is_string($service['factory'])) { |
|
53 | 1 | $factories[$serviceName] = $service['factory']; |
|
54 | 1 | unset($symfonyFactory['services'][$serviceName]); |
|
55 | 1 | continue; |
|
56 | } |
||
57 | |||
58 | if (is_array($service['factory'])) { |
||
59 | $factories[$serviceName] = $service['factory']; |
||
60 | unset($symfonyFactory['services'][$serviceName]); |
||
61 | continue; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | return [ |
||
67 | 'dependencies' => [ |
||
68 | 1 | 'factories' => $factories, |
|
69 | ], |
||
73 |