XmlConverter::xmlToArray()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
ccs 10
cts 10
cp 1
crap 4
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
}