BaseOperator::isExpression()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 1
nc 3
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 3
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
11
use ArekX\ArrayExpression\Exceptions\NotAnExpressionException;
12
use ArekX\ArrayExpression\Interfaces\ExpressionParser;
13
use ArekX\ArrayExpression\Interfaces\Operator;
14
15
/**
16
 * Class BaseOperator
17
 * Base class for all operators
18
 *
19
 * @package ArekX\ArrayExpression\Operators
20
 */
21
abstract class BaseOperator implements Operator
22
{
23
    /**
24
     * Name of the operator.
25
     *
26
     * @var string
27
     */
28
    protected $name;
29
30
    /**
31
     * Parser used for expression parsing.
32
     *
33
     * @var ExpressionParser
34
     */
35
    protected $parser;
36
37
    /**
38
     * @inheritDoc
39
     */
40 75
    public function setParser(ExpressionParser $parser)
41
    {
42 75
        $this->parser = $parser;
43 75
    }
44
45 65
    protected function setName($name)
46
    {
47 65
        $this->name = $name;
48 65
    }
49
50 22
    public function getName(): string
51
    {
52 22
        return $this->name;
53
    }
54
55 40
    protected function isExpression($value)
56
    {
57 40
        return is_array($value) && count($value) >= 1 && is_string($value[0]);
58
    }
59
60 40
    protected function assertIsExpression($value)
61
    {
62 40
        if (!$this->isExpression($value)) {
63 4
            throw new NotAnExpressionException($value);
64
        }
65
    }
66
}