Failed Conditions
Pull Request — 2.6 (#7882)
by
unknown
06:45
created

Node::__toString()   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 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Query\AST;
21
22
/**
23
 * Abstract class of an AST node.
24
 *
25
 * @link    www.doctrine-project.org
26
 * @since   2.0
27
 * @author  Guilherme Blanco <[email protected]>
28
 * @author  Jonathan Wage <[email protected]>
29
 * @author  Roman Borschel <[email protected]>
30
 */
31
abstract class Node
32
{
33
    /**
34
     * Double-dispatch method, supposed to dispatch back to the walker.
35
     *
36
     * Implementation is not mandatory for all nodes.
37
     *
38
     * @param \Doctrine\ORM\Query\SqlWalker $walker
39
     *
40
     * @return string
41
     *
42
     * @throws ASTException
43
     */
44
    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

44
    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...
45
    {
46
        throw ASTException::noDispatchForNode($this);
47
    }
48
49
    /**
50
     * Dumps the AST Node into a string representation for information purpose only.
51
     *
52
     * @return string
53
     */
54
    public function __toString()
55
    {
56
        return $this->dump($this);
57
    }
58
59
    /**
60
     * @param object $obj
61
     *
62
     * @return string
63
     */
64
    public function dump($obj)
65
    {
66
        static $ident = 0;
67
68
        $str = '';
69
70
        if ($obj instanceof Node) {
71
            $str .= get_class($obj) . '(' . PHP_EOL;
72
            $props = get_object_vars($obj);
73
74
            foreach ($props as $name => $prop) {
75
                $ident += 4;
76
                $str .= str_repeat(' ', $ident) . '"' . $name . '": '
77
                      . $this->dump($prop) . ',' . PHP_EOL;
78
                $ident -= 4;
79
            }
80
81
            $str .= str_repeat(' ', $ident) . ')';
82
        } else if (is_array($obj)) {
0 ignored issues
show
introduced by
The condition is_array($obj) is always false.
Loading history...
83
            $ident += 4;
84
            $str .= 'array(';
85
            $some = false;
86
87
            foreach ($obj as $k => $v) {
88
                $str .= PHP_EOL . str_repeat(' ', $ident) . '"'
89
                      . $k . '" => ' . $this->dump($v) . ',';
90
                $some = true;
91
            }
92
93
            $ident -= 4;
94
            $str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')';
95
        } else if (is_object($obj)) {
96
            $str .= 'instanceof(' . get_class($obj) . ')';
97
        } else {
98
            $str .= var_export($obj, true);
99
        }
100
101
        return $str;
102
    }
103
}
104