Completed
Push — master ( 48745e...b53abb )
by Zoltán
02:36
created

StandardXMLDefinitionParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php namespace BuildR\TestTools\DataSetLoader\XML\Parser;
2
3
use BuildR\TestTools\DataSetLoader\XML\Helper\SimpleXMLNodeTypedAttributeGetter;
4
use BuildR\TestTools\Exception\XMLDataSetParsingException;
5
use SimpleXMLElement;
6
7
class StandardXMLDefinitionParser implements XMLDefinitionParserInterface {
8
9
    private $groupName;
10
11
    public function setTestGroup($groupName) {
12
        $this->groupName = $groupName;
13
    }
14
15
    private function getXPathQuery() {
16
        if($this->groupName === NULL) {
17
            return '/testGroups/testGroup[1]';
18
        }
19
20
        return '/testGroups/testGroup[@name="' . $this->groupName . '"]';
21
    }
22
23
    private function createTestArrayFromXmlElement(SimpleXMLElement $element) {
24
        $result = [];
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
        $dataSets = $element->xpath('*');
26
27
        foreach($dataSets as $dataSet) {
28
            $values = [];
0 ignored issues
show
Unused Code introduced by
$values is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
29
            $properties = $dataSet->xpath('*');
30
31
            foreach($properties as $property) {
32
                $typedGetter = new SimpleXMLNodeTypedAttributeGetter($property);
33
                die(var_dump($typedGetter->value));
0 ignored issues
show
Security Debugging Code introduced by
var_dump($typedGetter->value); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
Coding Style Compatibility introduced by
The method createTestArrayFromXmlElement() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
34
            }
35
        }
36
    }
37
38
    public function parse(SimpleXMLElement $root) {
39
        $result = $root->xpath($this->getXPathQuery());
40
        
41
        if(empty($result)) {
42
            throw XMLDataSetParsingException::noResult($this->getXPathQuery());
43
        }
44
45
        return $this->createTestArrayFromXmlElement($result[0]);
46
    }
47
    
48
}
49