BreakSt   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 16 4
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
    public function compile($stmt, Context $context)
19
    {
20
        $compiler = $context->getExpressionCompiler();
21
22
        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
    }
34
}
35