| Conditions | 11 |
| Paths | 18 |
| Total Lines | 35 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 11 |
| 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 |
||
| 31 | 24 | public function loadArray($data, \DOMElement $domElement = null) |
|
| 32 | { |
||
| 33 | 24 | $domElement = is_null($domElement) ? $this : $domElement; |
|
| 34 | |||
| 35 | 24 | if (is_array($data)) { |
|
| 36 | 16 | foreach ($data as $key => $value) { |
|
| 37 | 16 | if (is_null($value)) { |
|
| 38 | 4 | $domNode = $this->createElement($key); |
|
| 39 | 4 | $domNode->setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil", "true"); |
|
| 40 | 4 | $domElement->appendChild($domNode); |
|
| 41 | } else { |
||
| 42 | 16 | if (is_int($key)) { |
|
| 43 | 6 | if ($key === 0) { |
|
| 44 | 6 | $domNode = $domElement; |
|
| 45 | } else { |
||
| 46 | 6 | $domNode = $this->createElement($domElement->tagName); |
|
|
1 ignored issue
–
show
|
|||
| 47 | 6 | $domElement->parentNode->appendChild($domNode); |
|
| 48 | } |
||
| 49 | } else { |
||
| 50 | 16 | if (preg_match('/^\@(.*)$/', $key, $attribute)) { |
|
| 51 | 6 | $domElement->setAttribute($attribute[1], $value); |
|
| 52 | 6 | continue; |
|
| 53 | } else { |
||
| 54 | 16 | $domNode = $this->createElement($key); |
|
| 55 | 16 | $domElement->appendChild($domNode); |
|
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | } |
||
| 60 | 16 | $this->loadArray($value, $domNode); |
|
| 61 | } |
||
| 62 | 22 | } elseif (is_bool($data) === true) { |
|
| 63 | 2 | $domElement->appendChild($this->createTextNode((boolval($data) ? 'true' : 'false'))); |
|
| 64 | 20 | } elseif (!empty($data)) { |
|
| 65 | 12 | $domElement->appendChild($this->createTextNode($data)); |
|
| 66 | } |
||
| 69 |