Completed
Push — master ( c13fe7...3200a4 )
by Дмитрий
03:22
created

ForeachSt::compile()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.343

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
nc 8
nop 2
dl 0
loc 24
ccs 13
cts 18
cp 0.7221
crap 4.343
rs 8.6845
c 1
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\Context;
9
use PHPSA\CompiledExpression;
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 2
    public function compile($stmt, Context $context)
21
    {
22 2
        $context->getExpressionCompiler()->compile($stmt->expr);
23
24 2
        if ($stmt->keyVar) {
25
            $context->getExpressionCompiler()->declareVariable(
26
                $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...
27
                null,
28
                CompiledExpression::UNKNOWN
29
            );
30
        }
31
32 2
        if ($stmt->valueVar) {
33 2
            $context->getExpressionCompiler()->declareVariable(
34 2
                $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...
35 2
                null,
36
                CompiledExpression::UNKNOWN
37 2
            );
38 2
        }
39
40 2
        foreach ($stmt->stmts as $statement) {
41 2
            \PHPSA\nodeVisitorFactory($statement, $context);
42 2
        }
43 2
    }
44
}
45