Completed
Push — master ( b7cb0e...ffcfdb )
by Дмитрий
02:53
created

AbstractCompiler::assertExpression()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler\Statement;
7
8
use PHPSA\CompiledExpression;
9
use PHPSA\Context;
10
use PHPSA\Compiler\StatementCompilerInterface;
11
use RuntimeException;
12
13
abstract class AbstractCompiler implements StatementCompilerInterface
14
{
15
    /**
16
     * @abstract
17
     * @var string
18
     */
19
    protected $name = 'unknown';
20
21 6
    protected function assertExpression($expression)
22
    {
23 6
        if (!$expression instanceof $this->name) {
24
            throw new RuntimeException('Passed $expression must be instance of ' . $this->name);
25
        }
26 6
    }
27
28
    /**
29
     * @param $stmt
30
     * @param Context $context
31
     * @return CompiledExpression
32
     */
33 6
    public function pass($stmt, Context $context)
34
    {
35 6
        $this->assertExpression($stmt);
36 6
        return $this->compile($stmt, $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