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
|
|||
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 | 3 | public function __toString() |
|
32 | { |
||
33 | 3 | return $this->dump($this); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param object $obj |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 3 | public function dump($obj) |
|
42 | { |
||
43 | 3 | static $ident = 0; |
|
44 | |||
45 | 3 | $str = ''; |
|
46 | |||
47 | 3 | if ($obj instanceof Node) { |
|
48 | 3 | $str .= get_class($obj) . '(' . PHP_EOL; |
|
49 | 3 | $props = get_object_vars($obj); |
|
50 | |||
51 | 3 | foreach ($props as $name => $prop) { |
|
52 | 3 | $ident += 4; |
|
53 | 3 | $str .= str_repeat(' ', $ident) . '"' . $name . '": ' |
|
54 | 3 | . $this->dump($prop) . ',' . PHP_EOL; |
|
55 | 3 | $ident -= 4; |
|
56 | } |
||
57 | |||
58 | 3 | $str .= str_repeat(' ', $ident) . ')'; |
|
59 | 3 | } elseif (is_array($obj)) { |
|
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 | 3 | } elseif (is_object($obj)) { |
|
73 | $str .= 'instanceof(' . get_class($obj) . ')'; |
||
74 | } else { |
||
75 | 3 | $str .= var_export($obj, true); |
|
76 | } |
||
77 | |||
78 | 3 | return $str; |
|
79 | } |
||
80 | } |
||
81 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.