1 | <?php |
||
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) { |
||
|
|||
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) |
||
49 | |||
50 | /** |
||
51 | * @param AbstractNode $block |
||
52 | */ |
||
53 | public function enterNode(AbstractNode $block) |
||
56 | } |
||
57 |
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.