Failed Conditions
Pull Request — master (#7046)
by Gabriel
14:57
created

Node::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query\AST;
6
7
/**
8
 * Abstract class of an AST node.
9
 */
10
abstract class Node
11
{
12
    /**
13
     * Double-dispatch method, supposed to dispatch back to the walker.
14
     *
15
     * Implementation is not mandatory for all nodes.
16
     *
17
     * @param \Doctrine\ORM\Query\SqlWalker $walker
18
     *
19
     * @throws ASTException
20
     */
21
    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

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