Passed
Branch master (e96466)
by Chubarov
03:06
created

XmlConverter::xmlToArrayRecursive()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 1
dl 0
loc 24
ccs 13
cts 13
cp 1
crap 5
rs 8.5125
c 0
b 0
f 0
1
<?php
2
namespace agoalofalife\bpm\Handlers;
3
4
5
use SimpleXMLElement;
6
7
trait XmlConverter
8
{
9 6
    private function xmlToArrayRecursive($xml) {
10 6
        $xml = (array) $xml;
11
12 6
        if(empty($xml)) {
13 3
            return null;
14
        }
15
16 4
        foreach ($xml as $key => $val) {
17 4
            if (is_array($val)){
18 1
                $xml[$key] = $this->xmlToArray($val);
19 1
            } else {
20 4
                if ($val instanceof SimpleXMLElement) {
21 3
                    $xml[$key] = $this->xmlToArray($val);
22 3
                }
23
                // TODO not smog to find a similar case
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
//                elseif (empty($val)) {
25
//                    $xml[$key] = null;
26
//                }
27
            }
28
29 4
        }
30
31 4
        return $xml;
32
    }
33
34 4
    private function xmlToArray($xml) {
35 4
        $xml = (array) $xml;
36
37 4
        if(empty($xml)) {
38 1
            return null;
39
        }
40
41 4
        foreach ($xml as $key=>$val) {
42 4
            if ($val instanceof SimpleXMLElement) {
43 2
                $xml[$key] = $this->xmlToArray($val);
44 2
            }
45
            // TODO not smog to find a similar case
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
//            elseif (empty($val)) {
47
//                $xml[$key] = null;
48
//            }
49 4
        }
50
51 4
        return $xml;
52
    }
53
}