Completed
Push — master ( 9bf369...6fddd2 )
by Дмитрий
12:54 queued 09:14
created

AbstractExpressionCompiler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 41
ccs 6
cts 9
cp 0.6667
rs 10
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 5 1
compile() 0 1 ?
A assertExpression() 0 6 2
A getName() 0 4 1
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler\Expression;
7
8
use Doctrine\Instantiator\Exception\InvalidArgumentException;
9
use PHPSA\CompiledExpression;
10
use PHPSA\Context;
11
use PHPSA\Compiler\ExpressionCompilerInterface;
12
13
abstract class AbstractExpressionCompiler implements ExpressionCompilerInterface
14
{
15
    /**
16
     * @abstract
17
     * @var string
18
     */
19
    protected $name = 'unknown';
20
21 11
    protected function assertExpression($expression)
22
    {
23 11
        if (!$expression instanceof $this->name) {
24
            throw new InvalidArgumentException('Passed $expression must be instance of ' . $this->name);
25
        }
26 11
    }
27
28
    /**
29
     * @param  $expr
30
     * @param Context $context
31
     * @return CompiledExpression
32
     */
33 11
    public function pass($expr, Context $context)
34
    {
35 11
        $this->assertExpression($expr);
36 11
        return $this->compile($expr, $context);
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getName()
43
    {
44
        return $this->name;
45
    }
46
47
    /**
48
     * @param $expr
49
     * @param Context $context
50
     * @return mixed
51
     */
52
    abstract protected function compile($expr, Context $context);
53
}
54