ValueJudge   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 51
c 0
b 0
f 0
wmc 8
lcom 2
cbo 2
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B decide() 0 19 5
A valueExists() 0 4 1
A getValues() 0 4 1
A getValueRules() 0 4 1
1
<?php
2
3
namespace Jlis\Judge\Judges;
4
5
/**
6
 * @author Julius Ehrlich <[email protected]>
7
 */
8
class ValueJudge extends AbstractValueJudge
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 24
    public function decide($value, $user = null, $defaultValue = false)
14
    {
15 24
        if (! $this->valueExists($value)) {
16 2
            return $defaultValue;
17
        }
18
19 22
        $rules = $this->getValueRules($value);
20 22
        if (! is_array($rules)) {
21 1
            return $rules;
22
        }
23
24 21
        foreach ($rules as $rule) {
25 21
            if (false !== $value = $this->decideRules($rule, $user)) {
26 14
                return $value;
27
            }
28 13
        }
29
30 7
        return $defaultValue;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 24
    public function valueExists($value)
37
    {
38 24
        return isset($this->values[$value]);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 26
    public function getValues()
45
    {
46 26
        return $this->adapter->getValues();
47
    }
48
49
    /**
50
     * @param $value
51
     *
52
     * @return mixed
53
     */
54 22
    private function getValueRules($value)
55
    {
56 22
        return $this->values[$value];
57
    }
58
}
59