ValueJudge::getValueRules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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