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

BlockTraverser::traverse()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 8
nop 1
dl 0
loc 23
ccs 0
cts 17
cp 0
crap 42
rs 8.5906
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;
7
8
use PHPSA\ControlFlow\Visitor\AbstractVisitor;
9
10
class BlockTraverser
11
{
12
    /**
13
     * @var AbstractVisitor[]
14
     */
15
    protected $visitors = [];
16
17
    public function addVisitor(AbstractVisitor $visitor)
18
    {
19
        $this->visitors[] = $visitor;
20
    }
21
22
    public function traverse(ControlFlowGraph $cfg)
23
    {
24
        $rootBlock = $cfg->getRoot();
25
26
        /** @var AbstractVisitor $visitor */
27
        foreach ($this->visitors as $visitor) {
28
            $visitor->enterBlock($rootBlock);
29
        }
30
31
        $children = $rootBlock->getChildren();
32
        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...
33
            foreach ($children as $child) {
34
                foreach ($this->visitors as $visitor) {
35
                    $visitor->enterNode($child);
36
                }
37
            }
38
        }
39
40
        /** @var AbstractVisitor $visitor */
41
        foreach ($this->visitors as $visitor) {
42
            $visitor->leaveBlock($rootBlock);
43
        }
44
    }
45
}
46