BetweenOperator::evaluate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
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\Operator;
11
use ArekX\ArrayExpression\Interfaces\ValueParser;
12
13
/**
14
 * Class BetweenOperator
15
 * Operator for between operation.
16
 *
17
 * @package ArekX\ArrayExpression\Operators
18
 */
19
class BetweenOperator extends BaseOperator
20
{
21
    /**
22
     * Operator result which will be checked.
23
     *
24
     * @var Operator
25
     */
26
    public $operandA;
27
28
    /**
29
     * Operator result which will be used for minimum.
30
     *
31
     * @var Operator
32
     */
33
    public $operandB;
34
35
    /**
36
     * Operator result which will be used for maximum.
37
     *
38
     * @var Operator
39
     */
40
    public $operandC;
41
42
    /**
43
     * @inheritDoc
44
     */
45 5
    public function configure(array $config)
46
    {
47 5
        $this->setName($config[0] ?? 'unknown');
48
49 5
        if (count($config) < 4) {
50 3
            throw new \InvalidArgumentException("No matching minimum format: ['{$this->getName()}', <valueExpression>, <minExpression>, <maxExpression>");
51
        }
52
53 2
        $this->assertIsExpression($config[1]);
54 2
        $this->assertIsExpression($config[2]);
55 2
        $this->assertIsExpression($config[3]);
56
57 2
        $this->operandA = $this->parser->parse($config[1]);
58 2
        $this->operandB = $this->parser->parse($config[2]);
59 2
        $this->operandC = $this->parser->parse($config[3]);
60 2
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 1
    public function evaluate(ValueParser $value)
66
    {
67 1
        $resultA = $this->operandA->evaluate($value);
68 1
        $resultB = $this->operandB->evaluate($value);
69 1
        $resultC = $this->operandC->evaluate($value);
70
71 1
        return $resultA >= $resultB && $resultA <= $resultC;
72
    }
73
}