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

ExpressionLanguage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 3 1
A apply() 0 18 3
A getRuleCode() 0 3 1
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
}