Completed
Pull Request — master (#296)
by algo13
03:47
created

ContinueSt::compile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.1576

Importance

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