Dumper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getAst() 0 24 6
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
namespace Zicht\Tool\Script;
9
10
use Zicht\Tool\Util;
11
12
/**
13
 * Dumps a compiled node AST as an array
14
 */
15
class Dumper
16
{
17
    /**
18
     * Returns the AST for a specified node as an array representation
19
     *
20
     * @param Node\Node $b
21
     * @param string $path
22
     * @return array
23
     */
24 13
    public function getAst(Node\Node $b, $path = '')
25
    {
26
        $ret = array(
27 13
            'type' => str_replace('Zicht\Tool\Script\Node\\', '', get_class($b))
28 13
        );
29 13
        if ($b instanceof Node\Branch) {
30 12
            if (count($b->nodes)) {
31 11
                $ret['nodes'] = array();
32
33 11
                foreach ($b->nodes as $n) {
34 11
                    if (null === $n) {
35 2
                        $ret['nodes'][] = $n;
36 2
                    } else {
37 11
                        if (!$n instanceof Node\Node) {
38
                            throw new \InvalidArgumentException("Invalid child node in " . Util::toPhp($path));
39
                        }
40 11
                        $ret['nodes'][] = $this->getAst($n);
41
                    }
42 11
                }
43 11
            }
44 12
        }
45
46 13
        return $ret;
47
    }
48
}
49