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

AbstractCompiler::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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