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

UnreachableVisitor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 30
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0
wmc 7
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B enterBlock() 0 17 6
A leaveBlock() 0 3 1
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