Passed
Pull Request — develop (#53)
by Kevin
08:43
created

ConfigurationRepository::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Magium\Configuration\Config\Repository;
4
5
class ConfigurationRepository extends \SimpleXMLElement implements ConfigInterface
6
{
7
8
    const CONTEXT_DEFAULT = 'default';
9
10 1
    public function hasValue($path)
11
    {
12 1
        list($section, $group, $element) = explode('/', $path);
13 1
        $xpath = sprintf('/*/%s/%s/%s', $section, $group, $element);
14 1
        $element = $this->xpath($xpath);
15 1
        if ($element) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $element of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
16 1
            return true;
17
        }
18 1
        return false;
19
    }
20
21 11
    public function getValue($path)
22
    {
23 11
        list($section, $group, $element) = explode('/', $path);
24 11
        $xpath = sprintf('/*/%s/%s/%s', $section, $group, $element);
25 11
        $element = $this->xpath($xpath);
26 11
        if (empty($element)) {
27 3
            return null;
28
        }
29 10
        $value = (string)$element[0];
30 10
        return $value;
31
    }
32
33 2
    public function getValueFlag($path)
34
    {
35 2
        $value = $this->getValue($path);
36 2
        foreach (self::ALLOWED_TRUES as $true) {
37 2
            if ($value === $true) {
38 2
                return true;
39
            }
40
        }
41 2
        return false;
42
    }
43
44
}
45