Completed
Push — master ( 9f1a25...922242 )
by De Cramer
10s
created

ExpressionLanguage::getRuleCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oliverde8\Component\RuleEngine\Rules;
4
5
/**
6
 * Class ExpressionLanguage
7
 *
8
 * @author    de Cramer Oliver<[email protected]>
9
 * @copyright 2018 Oliverde8
10
 * @package Oliverde8\Component\RuleEngine\Rules
11
 */
12
class ExpressionLanguage extends AbstractRule
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    public function apply($rowData, &$transformedData, $options = [])
18
    {
19
        $values = [
20
            'rowData' => $rowData,
21
            'transformedData' => $transformedData,
22
        ];
23
24
        if (isset($options['values'])) {
25
            $newOptions = $options;
26
            unset($newOptions['values']);
27
            foreach ($options['values'] as $valueKey => $value) {
28
                $values[$valueKey] = $this->ruleApplier->apply($rowData, $transformedData, $value, $newOptions);
29
            }
30
        } else {
31
        }
32
33
        $expressionLanguage = new \Symfony\Component\ExpressionLanguage\ExpressionLanguage();
34
        return $expressionLanguage->evaluate($options['expression'], $values);
35
    }
36
37
    /**
38
     * Get unique code that needs to be used to apply this rule.
39
     *
40
     * @return string
41
     */
42
    public function getRuleCode()
43
    {
44
        return 'expression_language';
45
    }
46
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function validate($options)
52
    {
53
        $this->requireOption('expression', $options);
54
    }
55
}