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

XmlConverter::xmlToArray()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 10

Duplication

Lines 5
Ratio 29.41 %

Code Coverage

Tests 10
CRAP Score 5.1158

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 1
dl 5
loc 17
ccs 10
cts 12
cp 0.8333
crap 5.1158
rs 8.8571
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
}