Completed
Pull Request — master (#149)
by Enrico
04:04
created

ForSt::compile()   D

Complexity

Conditions 9
Paths 24

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 9

Importance

Changes 0
Metric Value
cc 9
eloc 15
nc 24
nop 2
dl 0
loc 28
ccs 23
cts 23
cp 1
crap 9
rs 4.909
c 0
b 0
f 0
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
11
class ForSt extends AbstractCompiler
12
{
13
    protected $name = '\PhpParser\Node\Stmt\For_';
14
15
    /**
16
     * @param \PhpParser\Node\Stmt\For_ $stmt
17
     * @param Context $context
18
     * @return CompiledExpression
19
     */
20 4
    public function compile($stmt, Context $context)
21
    {
22 4
        if (count($stmt->init) > 0) {
23 1
            foreach ($stmt->init as $cond) {
24 1
                $context->getExpressionCompiler()->compile($cond);
25 1
            }
26 1
        }
27
28 4
        if (count($stmt->cond) > 0) {
29 1
            foreach ($stmt->cond as $cond) {
30 1
                $context->getExpressionCompiler()->compile($cond);
31 1
            }
32 1
        }
33
34 4
        if (count($stmt->loop) > 0) {
35 1
            foreach ($stmt->loop as $loop) {
36 1
                $context->getExpressionCompiler()->compile($loop);
37 1
            }
38 1
        }
39
40 4
        if (count($stmt->stmts) > 0) {
41 1
            foreach ($stmt->stmts as $statement) {
42 1
                \PHPSA\nodeVisitorFactory($statement, $context);
43 1
            }
44 1
        } else {
45 3
            return $context->notice('not-implemented-body', 'Missing body', $stmt);
46
        }
47 1
    }
48
}
49