XOrOperator::evaluate()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 1
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 5
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Aleksandar Panic
4
 * @license http://www.apache.org/licenses/LICENSE-2.0
5
 * @since 1.0.0
6
 **/
7
8
namespace ArekX\ArrayExpression\Operators;
9
10
11
use ArekX\ArrayExpression\Interfaces\Operator;
12
use ArekX\ArrayExpression\Interfaces\ExpressionParser;
13
use ArekX\ArrayExpression\Interfaces\ValueParser;
14
15
/**
16
 * Class XOrOperator
17
 * Operator for handling XOR function
18
 *
19
 * @package ArekX\ArrayExpression\Operators
20
 */
21
class XOrOperator extends BaseGroupOperator
22
{
23
    /**
24
     * Evaluates one value.
25
     *
26
     * @param ValueParser $value Value to be evaluated
27
     * @return mixed Evaluation result
28
     * @throws \ArekX\ArrayExpression\Exceptions\NotAnExpressionException
29
     */
30 5
    public function evaluate(ValueParser $value)
31
    {
32 5
        $previousValue = null;
33 5
        for ($i = 1; array_key_exists($i, $this->config); $i++) {
34 5
            if (empty($this->operators[$i])) {
35 5
                $this->assertIsExpression($this->config[$i]);
36 5
                $this->operators[$i] = $this->parser->parse($this->config[$i]);
37
            }
38
39 5
            $result = $this->operators[$i]->evaluate($value);
40
41 5
            if ($previousValue !== null && $result !== $previousValue) {
42 1
                return true;
43
            }
44
45 5
            $previousValue = $result;
46
        }
47
48 4
        return !$previousValue;
49
    }
50
}