Completed
Pull Request — master (#85)
by Kévin
18:16 queued 14:06
created

ForeachSt::compile()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 12
nop 2
dl 0
loc 20
ccs 12
cts 15
cp 0.8
crap 5.2
rs 8.8571
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 ForeachSt extends AbstractCompiler
12
{
13
    protected $name = '\PhpParser\Node\Stmt\Foreach_';
14
15
    /**
16
     * @param \PhpParser\Node\Stmt\Foreach_ $stmt
17
     * @param Context $context
18
     * @return null|boolean
19
     */
20 1
    public function compile($stmt, Context $context)
21
    {
22 1
        $context->getExpressionCompiler()->compile($stmt->expr);
23
24 1
        if ($stmt->keyVar) {
25
            $context->getExpressionCompiler()->declareVariable($stmt->keyVar);
0 ignored issues
show
Compatibility introduced by
$stmt->keyVar of type object<PhpParser\Node\Expr> is not a sub-type of object<PhpParser\Node\Expr\Variable>. It seems like you assume a child class of the class PhpParser\Node\Expr to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
26
        }
27
28 1
        if ($stmt->valueVar) {
29 1
            $context->getExpressionCompiler()->declareVariable($stmt->valueVar);
0 ignored issues
show
Compatibility introduced by
$stmt->valueVar of type object<PhpParser\Node\Expr> is not a sub-type of object<PhpParser\Node\Expr\Variable>. It seems like you assume a child class of the class PhpParser\Node\Expr to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
30 1
        }
31
32 1
        if (count($stmt->stmts) > 0) {
33 1
            foreach ($stmt->stmts as $statement) {
34 1
                \PHPSA\nodeVisitorFactory($statement, $context);
35 1
            }
36 1
        } else {
37
            return $context->notice('not-implemented-body', 'Missing body', $stmt);
38
        }
39 1
    }
40
}
41