Passed
Push — develop ( 16aa6b...1646d8 )
by Kevin
06:20 queued 02:58
created

ConfigurationRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

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;
4
5
class ConfigurationRepository extends \SimpleXMLElement implements ConfigInterface
6
{
7
8
    const CONTEXT_DEFAULT = 'default';
9
10
    protected static $allowedTrues = [
11
        true, 'true', 1, '1', 'on', 'yes'
12
    ];
13
14 1
    public function hasValue($path)
15
    {
16 1
        list($section, $group, $element) = explode('/', $path);
17 1
        $xpath = sprintf('/*/%s/%s/%s', $section, $group, $element);
18 1
        $element = $this->xpath($xpath);
19 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...
20 1
            return true;
21
        }
22 1
        return false;
23
    }
24
25 10
    public function getValue($path)
26
    {
27 10
        list($section, $group, $element) = explode('/', $path);
28 10
        $xpath = sprintf('/*/%s/%s/%s', $section, $group, $element);
29 10
        $element = $this->xpath($xpath);
30 10
        if (empty($element)) {
31 3
            return null;
32
        }
33 9
        $value = (string)$element[0];
34 9
        return $value;
35
    }
36
37 2
    public function getValueFlag($path)
38
    {
39 2
        $value = $this->getValue($path);
40 2
        foreach (self::$allowedTrues as $true) {
41 2
            if ($value === $true) {
42 2
                return true;
43
            }
44
        }
45 2
        return false;
46
    }
47
}
48