Node::dump()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 38
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 26
nc 5
nop 1
dl 0
loc 38
ccs 0
cts 26
cp 0
crap 56
rs 8.5706
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query\AST;
6
7
use Doctrine\ORM\Query\SqlWalker;
8
use const PHP_EOL;
9
use function get_class;
10
use function get_object_vars;
11
use function is_array;
12
use function is_object;
13
use function str_repeat;
14
use function var_export;
15
16
/**
17
 * Abstract class of an AST node.
18
 */
19
abstract class Node
20
{
21
    /**
22
     * Double-dispatch method, supposed to dispatch back to the walker.
23
     *
24
     * Implementation is not mandatory for all nodes.
25
     *
26
     * @param SqlWalker $walker
27
     *
28
     * @throws ASTException
29
     */
30
    public function dispatch($walker)
0 ignored issues
show
Unused Code introduced by
The parameter $walker is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function dispatch(/** @scrutinizer ignore-unused */ $walker)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        throw ASTException::noDispatchForNode($this);
33
    }
34
35
    /**
36
     * Dumps the AST Node into a string representation for information purpose only.
37
     *
38
     * @return string
39
     */
40
    public function __toString()
41
    {
42
        return $this->dump($this);
43
    }
44
45
    /**
46
     * @param object $obj
47
     *
48
     * @return string
49
     */
50
    public function dump($obj)
51
    {
52
        static $ident = 0;
53
54
        $str = '';
55
56
        if ($obj instanceof Node) {
57
            $str  .= get_class($obj) . '(' . PHP_EOL;
58
            $props = get_object_vars($obj);
59
60
            foreach ($props as $name => $prop) {
61
                $ident += 4;
62
                $str   .= str_repeat(' ', $ident) . '"' . $name . '": '
63
                      . $this->dump($prop) . ',' . PHP_EOL;
64
                $ident -= 4;
65
            }
66
67
            $str .= str_repeat(' ', $ident) . ')';
68
        } elseif (is_array($obj)) {
0 ignored issues
show
introduced by
The condition is_array($obj) is always false.
Loading history...
69
            $ident += 4;
70
            $str   .= 'array(';
71
            $some   = false;
72
73
            foreach ($obj as $k => $v) {
74
                $str .= PHP_EOL . str_repeat(' ', $ident) . '"'
75
                      . $k . '" => ' . $this->dump($v) . ',';
76
                $some = true;
77
            }
78
79
            $ident -= 4;
80
            $str   .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')';
81
        } elseif (is_object($obj)) {
82
            $str .= 'instanceof(' . get_class($obj) . ')';
83
        } else {
84
            $str .= var_export($obj, true);
85
        }
86
87
        return $str;
88
    }
89
}
90