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

AbstractExpressionCompiler::compile()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
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