Passed
Branch 2.0.0 (fac5a8)
by Chubarov
02:44
created

XmlConverter::xmlToArrayRecursive()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 7
Ratio 31.82 %

Code Coverage

Tests 11
CRAP Score 6.6829

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 6
nop 1
dl 7
loc 22
ccs 11
cts 15
cp 0.7332
crap 6.6829
rs 8.6737
c 0
b 0
f 0
1
<?php
2
namespace agoalofalife\bpm\Handlers;
3
4
5
use SimpleXMLElement;
6
7
trait XmlConverter
8
{
9 4
    private function xmlToArrayRecursive($xml) {
10 4
        $xml = (array) $xml;
11
12 4
        if(empty($xml)) {
13 2
            return null;
14
        }
15
16 3
        foreach ($xml as $key => $val) {
17 3
            if (is_array($val)){
18
                $xml[$key] = $this->xmlToArray($val);
19 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20 3
                if ($val instanceof SimpleXMLElement) {
21 3
                    $xml[$key] = $this->xmlToArray($val);
22 3
                } elseif (empty($val)) {
23
                    $xml[$key] = null;
24
                }
25
            }
26
27 3
        }
28
29 3
        return $xml;
30
    }
31
32 4
    private function xmlToArray($xml) {
33 4
        $xml = (array) $xml;
34
35 4
        if(empty($xml)) {
36 1
            return null;
37
        }
38
39 4
        foreach ($xml as $key=>$val) {
40 4 View Code Duplication
            if ($val instanceof SimpleXMLElement) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41 1
                $xml[$key] = $this->xmlToArray($val);
42 4
            } elseif (empty($val)) {
43
                $xml[$key] = null;
44
            }
45 4
        }
46
47 4
        return $xml;
48
    }
49
}