PhpFile::toXml()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 24

Duplication

Lines 10
Ratio 41.67 %

Code Coverage

Tests 17
CRAP Score 4

Importance

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