FeatureJudge   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
c 0
b 0
f 0
wmc 13
lcom 2
cbo 2
ccs 22
cts 22
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B decide() 0 20 5
A featureExists() 0 4 2
A getFeature() 0 4 1
A getFeatures() 0 4 1
A isTrue() 0 6 4
1
<?php
2
3
namespace Jlis\Judge\Judges;
4
5
/**
6
 * @author Julius Ehrlich <[email protected]>
7
 */
8
class FeatureJudge extends AbstractFeatureJudge
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 33
    public function decide($feature, $user = null, $defaultIfNotFound = false)
14
    {
15 33
        if (! $this->featureExists($feature)) {
16 2
            return $defaultIfNotFound;
17
        }
18
19 31
        $rules = $this->getFeature($feature);
20 31
        if (! is_array($rules)) {
21 1
            return (bool) $rules;
22
        }
23
24 30
        $enabled = false;
25 30
        foreach ($rules as $rule) {
26 30
            if (true === self::isTrue($this->decideRules($rule, $user))) {
27 14
                $enabled = true;
28 14
            }
29 30
        }
30
31 30
        return $enabled;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 33
    public function featureExists($feature)
38
    {
39 33
        return isset($this->features[$feature]) && false !== $this->features[$feature];
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 31
    public function getFeature($feature)
46
    {
47 31
        return $this->features[$feature];
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 35
    public function getFeatures()
54
    {
55 35
        return $this->adapter->getFeatures();
56
    }
57
58
    /**
59
     * @see http://php.net/manual/de/function.boolval.php#116547
60
     *
61
     * @param mixed      $val
62
     * @param bool|false $returnNull
63
     *
64
     * @return bool|mixed|null
65
     */
66 35
    public static function isTrue($val, $returnNull = false)
67
    {
68 35
        $boolVal = (is_string($val) ? filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : (bool) $val);
69
70 35
        return $boolVal === null && ! $returnNull ? false : $boolVal;
71
    }
72
}
73