Conditions | 16 |
Paths | 257 |
Total Lines | 55 |
Code Lines | 28 |
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 |
||
58 | private function loadV1(\SimpleXmlElement $xml, \Dice\Dice $dice) |
||
59 | { |
||
60 | foreach ($xml as $key => $value) { |
||
61 | $rule = $dice->getRule((string) $value->name); |
||
62 | |||
63 | if (isset($value->shared)) { |
||
64 | $rule['shared'] = ((string) $value->shared === 'true'); |
||
65 | } |
||
66 | |||
67 | if (isset($value->inherit)) { |
||
68 | $rule['inherit'] = (bool) $value->inherit; |
||
69 | } |
||
70 | |||
71 | if ($value->call) { |
||
72 | foreach ($value->call as $name => $call) { |
||
73 | $callArgs = []; |
||
74 | if ($call->params) { |
||
75 | foreach ($call->params->children() as $key => $param) { |
||
|
|||
76 | $callArgs[] = $this->getComponent($param); |
||
77 | } |
||
78 | } |
||
79 | $rule['call'][] = [(string) $call->method, $callArgs]; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | if ($value->instanceOf) { |
||
84 | $rule['instanceOf'] = (string) $value->instanceOf; |
||
85 | } |
||
86 | |||
87 | if ($value->newInstances) { |
||
88 | foreach ($value->newInstances as $ni) { |
||
89 | $rule['newInstances'][] = (string) $ni; |
||
90 | } |
||
91 | } |
||
92 | |||
93 | if ($value->substitutions) { |
||
94 | foreach ($value->substitutions as $use) { |
||
95 | $rule['substitutions'][(string) $use->as] = $this->getComponent($use->use, true); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if ($value->constructParams) { |
||
100 | $rule = $this->doConstructParams($value, $rule); |
||
101 | } |
||
102 | |||
103 | if ($value->shareInstances) { |
||
104 | foreach ($value->shareInstances->children() as $share) { |
||
105 | $rule['shareInstances'][] = $this->getComponent($share); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $dice->addRule((string) $value->name, $rule); |
||
110 | } |
||
111 | |||
112 | return $dice; |
||
113 | } |
||
164 |