AndOperator::evaluate()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 5
nop 1
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 4
rs 10
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
use ArekX\ArrayExpression\Interfaces\ValueParser;
11
12
/**
13
 * Class AndOperator
14
 * Operator for handling AND function
15
 *
16
 * @package ArekX\ArrayExpression\Operators
17
 */
18
class AndOperator extends BaseGroupOperator
19
{
20
    /**
21
     * Evaluates one value.
22
     *
23
     * @param ValueParser $value Value to be evaluated
24
     * @return bool Evaluation result
25
     * @throws \ArekX\ArrayExpression\Exceptions\NotAnExpressionException
26
     */
27 6
    public function evaluate(ValueParser $value)
28
    {
29 6
        for ($i = 1; array_key_exists($i, $this->config); $i++) {
30 6
            if (empty($this->operators[$i])) {
31 6
                $this->assertIsExpression($this->config[$i]);
32 6
                $this->operators[$i] = $this->parser->parse($this->config[$i]);
33
            }
34
35 6
            if (!$this->operators[$i]->evaluate($value)) {
36 2
                return false;
37
            }
38
        }
39
40 4
        return true;
41
    }
42
}