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

XmlConverter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 43
Duplicated Lines 27.91 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
dl 12
loc 43
ccs 21
cts 27
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B xmlToArrayRecursive() 7 22 6
B xmlToArray() 5 17 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}