PhpFile   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 33.9 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 20
loc 59
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toXml() 10 24 4
A processGroups() 10 13 4
A processElements() 0 16 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
3
namespace Magium\Configuration\File\Configuration;
4
5
class PhpFile extends AbstractConfigurationFile
6
{
7
8 1
    public function toXml()
9
    {
10 1
        $file = $this->getFile();
11 1
        $results = include $file;
12 1
        $config = new \SimpleXMLElement('<magiumConfiguration />');
13 1 View Code Duplication
        foreach ($results as $section => $sectionData) {
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...
14 1
            $sectionObj = $config->addChild('section');
15 1
            $sectionObj['identifier'] = $section;
16 1
            if (isset($sectionData['label'])) {
17 1
                $sectionObj['label'] = $sectionData['label'];
18
            }
19 1
            if (isset($sectionData['groups'])) {
20 1
                $this->processGroups($sectionObj, $sectionData['groups']);
21
            }
22
        }
23
24 1
        $doc = new \DOMDocument();
25 1
        $node = dom_import_simplexml($config);
26 1
        $newNode = $doc->importNode($node, true);
27 1
        $doc->appendChild($newNode);
28 1
        $this->validateSchema($doc);
29
30 1
        return $config;
31
    }
32
33 1
    protected function processGroups(\SimpleXMLElement $section, $groups)
34
    {
35 1 View Code Duplication
        foreach ($groups as $groupId => $groupData) {
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...
36 1
            $group = $section->addChild('group');
37 1
            $group['identifier'] = $groupId;
38 1
            if (isset($groupData['label'])) {
39 1
                $group['label'] = $groupData['label'];
40
            }
41 1
            if (isset($groupData['elements'])) {
42 1
                $this->processElements($group, $groupData['elements']);
43
            }
44
        }
45 1
    }
46
47 1
    protected function processElements(\SimpleXMLElement $group, $elements)
48
    {
49 1
        foreach ($elements as $id => $data) {
50 1
            $element = $group->addChild('element');
51 1
            $element['identifier'] = $id;
52 1
            if (isset($data['label'])) {
53 1
                $element['label'] = $data['label'];
54
            }
55 1
            if (isset($data['source'])) {
56 1
                $element['source'] = $data['source'];
57
            }
58 1
            if (isset($data['type'])) {
59 1
                $element['type'] = $data['type'];
60
            }
61
        }
62 1
    }
63
}
64