Completed
Pull Request — master (#293)
by Дмитрий
03:16
created

UnreachableVisitor::leaveBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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
10
/**
11
 *
12
 * function test($a) {
13
 *     return $a;
14
 *
15
 *     $a = 1; // Unreachable node!
16
 * }
17
 *
18
 */
19
class UnreachableVisitor extends AbstractVisitor
20
{
21
    /**
22
     * @param Block $block
23
     */
24
    public function enterBlock(Block $block)
25
    {
26
        $childrens = $block->getChildrens();
27
        if ($childrens) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $childrens 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...
28
            $childrensCount = count($childrens);
29
            if ($childrensCount <= 1) {
30
                return;
31
            }
32
33
            foreach ($childrens as $index => $children) {
34
                // Check that exit node is not the latest
35
                if ($children->willExit() && ($index + 1) != $childrensCount) {
36
                    echo 'Unreacheable block ' . $block->getId() . PHP_EOL;
37
                }
38
            }
39
        }
40
    }
41
42
    /**
43
     * @param Block $block
44
     */
45
    public function leaveBlock(Block $block)
46
    {
47
    }
48
}
49