ValueOperator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 38
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 3 1
A configure() 0 9 2
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 ValueOperator
17
 * Operator for returning static values
18
 *
19
 * @package ArekX\ArrayExpression\Operators
20
 */
21
class ValueOperator extends BaseOperator
22
{
23
    /**
24
     * Value which will be returned.
25
     *
26
     * @var mixed
27
     */
28
    public $value;
29
30
    /**
31
     * Evaluates one value.
32
     *
33
     * @param ValueParser $value Value to be evaluated
34
     * @return mixed Evaluation result
35
     */
36 13
    public function evaluate(ValueParser $value)
37
    {
38 13
        return $this->value;
39
    }
40
41
    /**
42
     * Passes data from operator configuration.
43
     *
44
     * Depending on the operator this data can contain other sub-expressions which need to be parsed using
45
     * ExpressionParser
46
     *
47
     * @param array $config Expressions to be processed
48
     * @see ExpressionParser
49
     */
50 18
    public function configure(array $config)
51
    {
52 18
        $this->setName($config[0] ?? 'unknown');
53
54 18
        if (count($config) <= 1) {
55 1
            throw new \InvalidArgumentException("Minimum format must be satisfied: ['{$this->getName()}', <value>]");
56
        }
57
58 17
        $this->value = $config[1];
59
    }
60
}