Completed
Push — master ( 662a49...9d1eac )
by Дмитрий
9s
created

UnreachableVisitor::enterBlock()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 5
nop 1
dl 0
loc 17
ccs 0
cts 13
cp 0
crap 42
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\ControlFlow\Visitor;
7
8
use PHPSA\ControlFlow\Block;
9
use PHPSA\ControlFlow\Node\AbstractNode;
10
11
/**
12
 *
13
 * function test($a) {
14
 *     return $a;
15
 *
16
 *     $a = 1; // Unreachable node!
17
 * }
18
 *
19
 */
20
class UnreachableVisitor extends AbstractVisitor
21
{
22
    /**
23
     * @param Block $block
24
     */
25
    public function enterBlock(Block $block)
26
    {
27
        $children = $block->getChildren();
28
        if ($children) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $children of type PHPSA\ControlFlow\Node\AbstractNode[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
29
            $childrenCount = count($children);
30
            if ($childrenCount <= 1) {
31
                return;
32
            }
33
34
            foreach ($children as $index => $child) {
35
                // Check that exit node is not the latest
36
                if ($child->willExit() && ($index + 1) != $childrenCount) {
37
                    echo 'Unreacheable block ' . $block->getId() . PHP_EOL;
38
                }
39
            }
40
        }
41
    }
42
43
    /**
44
     * @param Block $block
45
     */
46
    public function leaveBlock(Block $block)
47
    {
48
    }
49
50
    /**
51
     * @param AbstractNode $block
52
     */
53
    public function enterNode(AbstractNode $block)
54
    {
55
    }
56
}
57