Completed
Pull Request — master (#10)
by Todd
03:18
created

ExpressionLanguage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 72%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 36
ccs 18
cts 25
cp 0.72
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctionCompiler() 0 6 2
B __construct() 0 27 4
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2017 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Ebi;
9
10
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
11
use Symfony\Component\ExpressionLanguage\Node\GetAttrNode;
12
13
class ExpressionLanguage extends \Symfony\Component\ExpressionLanguage\ExpressionLanguage {
14 46
    public function __construct() {
15 46
        parent::__construct();
16
17 46
        $this->registerNodeFunction(GetAttrNode::class, function (\Symfony\Component\ExpressionLanguage\Compiler $compiler, GetAttrNode $node) {
18 7
                switch ($node->attributes['type']) {
19 7
                    case GetAttrNode::METHOD_CALL:
20
                        $compiler
21
                            ->compile($node->nodes['node'])
22
                            ->raw('->')
23
                            ->raw($node->nodes['attribute']->attributes['value'])
24
                            ->raw('(')
25
                            ->compile($node->nodes['arguments'])
26
                            ->raw(')')
27
                        ;
28
                        break;
29
30 7
                    case GetAttrNode::PROPERTY_CALL:
31 7
                    case GetAttrNode::ARRAY_CALL:
32
                        $compiler
33 7
                            ->compile($node->nodes['node'])
34 7
                            ->raw('[')
35 7
                            ->compile($node->nodes['attribute'])->raw(']')
36
                        ;
37 7
                        break;
38 7
                }
39 46
        });
40 46
    }
41
42 10
    public function getFunctionCompiler($name) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43 10
        if (isset($this->functions[$name])) {
44 4
            return $this->functions[$name]['compiler'];
45
        }
46 10
        return null;
47
    }
48
}
49