Completed
Push — master ( 19c440...922200 )
by Дмитрий
06:07 queued 02:02
created

AbstractExpressionCompiler::assertExpression()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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 369
    protected function assertExpression($expression)
22
    {
23 369
        if (!$expression instanceof $this->name) {
24 1
            throw new InvalidArgumentException('Passed $expression must be instance of ' . $this->name);
25
        }
26 368
    }
27
28
    /**
29
     * @param  $expr
30
     * @param Context $context
31
     * @return CompiledExpression
32
     */
33 369
    public function pass($expr, Context $context)
34
    {
35 369
        $this->assertExpression($expr);
36 368
        return $this->compile($expr, $context);
37
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function getName()
43
    {
44 1
        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