ExpressionLanguage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace uuf6429\ExpressionLanguage;
4
5
use ReflectionClass;
6
use ReflectionException;
7
use Symfony\Component\ExpressionLanguage\ExpressionLanguage as SymfonyExpressionLanguage;
8
9
class ExpressionLanguage extends SymfonyExpressionLanguage
10
{
11
    /** @var Parser */
12
    protected $parser;
13
14
    /**
15 1
     * {@inheritdoc}
16
     * @throws ReflectionException
17 1
     */
18
    public function __construct($cache = null, array $providers = array())
19 1
    {
20
        $this->parser = new Parser(array());
21 1
22
        parent::__construct($cache, $providers);
23 1
24 1
        $reflection = new ReflectionClass(SymfonyExpressionLanguage::class);
25 1
26 1
        $prop = $reflection->getProperty('lexer');
27
        $prop->setAccessible(true);
28 1
        $prop->setValue($this, new Lexer());
29 1
        $prop->setAccessible(false);
30 1
31 1
        $prop = $reflection->getProperty('parser');
32 1
        $prop->setAccessible(true);
33
        $prop->setValue($this, $this->parser);
34
        $prop->setAccessible(false);
35
    }
36
37
    /**
38
     * Hack to keep functions in parser up to date.
39 1
     *
40
     * {@inheritdoc}
41 1
     */
42 1
    public function register($name, callable $compiler, callable $evaluator): void
43 1
    {
44
        $this->functions[$name] = ['compiler' => $compiler, 'evaluator' => $evaluator];
45
        $this->parser->setFunctions($this->functions);
46
    }
47
}
48