Completed
Push — master ( 8f0d0f...15736a )
by Дмитрий
06:53
created

BreakSt::compile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 7.456

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 2
dl 0
loc 16
ccs 4
cts 10
cp 0.4
crap 7.456
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Compiler\Statement;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PhpParser\Node\Scalar\LNumber;
8
9
class BreakSt extends AbstractCompiler
10
{
11
    protected $name = '\PhpParser\Node\Stmt\Break_';
12
13
    /**
14
     * @param \PhpParser\Node\Stmt\Break_ $stmt
15
     * @param Context $context
16
     * @return CompiledExpression
17
     */
18 3
    public function compile($stmt, Context $context)
19
    {
20 3
        $compiler = $context->getExpressionCompiler();
21
22 3
        if ($stmt->num !== null) {
23
            $compiled = $compiler->compile($stmt->num);
24
            
25
            if (!($stmt->num instanceof LNumber) || $compiled->getValue() == 0) {
26
                $context->notice(
27
                    'language_error',
28
                    'Break only supports positive integers.',
29
                    $stmt
30
                );
31
            }
32
        }
33 3
    }
34
}
35