Passed
Push — master ( bafcc7...55396a )
by Aleksandar
02:08 queued 11s
created

BetweenOperator::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 6
rs 9.9666
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
     * @var Operator
23
     */
24
    public $operandA;
25
26
    /**
27
     * @var Operator
28
     */
29
    public $operandB;
30
31
    /**
32
     * @var Operator
33
     */
34
    public $operandC;
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function configure(array $config)
40
    {
41
        $this->setName($config[0] ?? 'unknown');
42
43
        if (count($config) < 4) {
44
            throw new \InvalidArgumentException("No matching minimum format: ['' expression operator");
45
        }
46
47
        $this->assertIsExpression($config[1]);
48
        $this->assertIsExpression($config[2]);
49
        $this->assertIsExpression($config[3]);
50
51
        $this->operandA = $this->parser->parse($config[1]);
0 ignored issues
show
Bug introduced by
The method parse() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        /** @scrutinizer ignore-call */ $this->operandA = $this->parser->parse($config[1]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
        $this->operandB = $this->parser->parse($config[2]);
53
        $this->operandC = $this->parser->parse($config[3]);
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function evaluate(ValueParser $value)
60
    {
61
        $resultA = $this->operandA->evaluate($value);
62
        $resultB = $this->operandB->evaluate($value);
63
        $resultC = $this->operandC->evaluate($value);
64
65
        return $resultA >= $resultB && $resultA <= $resultC;
66
    }
67
}