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

ConfigurationRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 40
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasValue() 0 10 2
A getValue() 0 11 2
A getValueFlag() 0 10 3
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