| Conditions | 13 |
| Paths | 129 |
| Total Lines | 47 |
| Code Lines | 24 |
| 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 |
||
| 115 | private function loadV2(\SimpleXmlElement $xml, \Dice\Dice $dice) |
||
| 116 | { |
||
| 117 | foreach ($xml as $key => $value) { |
||
| 118 | $rule = $dice->getRule((string) $value->name); |
||
| 119 | |||
| 120 | if ($value->call) { |
||
| 121 | foreach ($value->call as $name => $call) { |
||
| 122 | $callArgs = []; |
||
| 123 | foreach ($call->children() as $key => $param) { |
||
| 124 | $callArgs[] = $this->getComponent($param); |
||
| 125 | } |
||
| 126 | $rule['call'][] = [(string) $call['method'], $callArgs]; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | if (isset($value['inherit'])) { |
||
| 131 | $rule['inherit'] = (bool) $value['inherit']; |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($value['instanceOf']) { |
||
| 135 | $rule['instanceOf'] = (string) $value['instanceOf']; |
||
| 136 | } |
||
| 137 | |||
| 138 | if (isset($value['shared'])) { |
||
| 139 | $rule['shared'] = ((string) $value['shared'] === 'true'); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($value->constructParams) { |
||
| 143 | $rule = $this->doConstructParams($value, $rule); |
||
| 144 | } |
||
| 145 | |||
| 146 | if ($value->substitute) { |
||
| 147 | foreach ($value->substitute as $use) { |
||
| 148 | $rule['substitutions'][(string) $use['as']] = $this->getComponent($use['use'], true); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($value->shareInstances) { |
||
| 153 | foreach ($value->shareInstances->children() as $share) { |
||
| 154 | $rule['shareInstances'][] = $this->getComponent($share); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | $dice->addRule((string) $value['name'], $rule); |
||
| 159 | } |
||
| 160 | |||
| 161 | return $dice; |
||
| 162 | } |
||
| 164 |