ExpressionLanguage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A register() 0 5 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