1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Annotations\Parser\Visitor; |
6
|
|
|
|
7
|
|
|
use Doctrine\Annotations\Parser\Ast\Annotation; |
8
|
|
|
use Doctrine\Annotations\Parser\Ast\Annotations; |
9
|
|
|
use Doctrine\Annotations\Parser\Ast\ClassConstantFetch; |
10
|
|
|
use Doctrine\Annotations\Parser\Ast\Collection\ListCollection; |
11
|
|
|
use Doctrine\Annotations\Parser\Ast\Collection\MapCollection; |
12
|
|
|
use Doctrine\Annotations\Parser\Ast\ConstantFetch; |
13
|
|
|
use Doctrine\Annotations\Parser\Ast\Node; |
14
|
|
|
use Doctrine\Annotations\Parser\Ast\Pair; |
15
|
|
|
use Doctrine\Annotations\Parser\Ast\Parameter\NamedParameter; |
16
|
|
|
use Doctrine\Annotations\Parser\Ast\Parameter\UnnamedParameter; |
17
|
|
|
use Doctrine\Annotations\Parser\Ast\Parameters; |
18
|
|
|
use Doctrine\Annotations\Parser\Ast\Reference; |
19
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\BooleanScalar; |
20
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\FloatScalar; |
21
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\Identifier; |
22
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\IntegerScalar; |
23
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\NullScalar; |
24
|
|
|
use Doctrine\Annotations\Parser\Ast\Scalar\StringScalar; |
25
|
|
|
use const JSON_PRESERVE_ZERO_FRACTION; |
26
|
|
|
use const JSON_UNESCAPED_UNICODE; |
27
|
|
|
use function count; |
28
|
|
|
use function json_encode; |
29
|
|
|
use function str_repeat; |
30
|
|
|
use function strlen; |
31
|
|
|
use function substr; |
32
|
|
|
|
33
|
|
|
final class Dumper implements Visitor |
34
|
|
|
{ |
35
|
|
|
private const INDENT = '> '; |
36
|
|
|
|
37
|
|
|
/** @var int */ |
38
|
|
|
private $depth = 0; |
39
|
|
|
|
40
|
|
|
public function visit(Node $node) : void |
41
|
|
|
{ |
42
|
|
|
$node->dispatch($this); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function visitAnnotations(Annotations $annotations) : void |
46
|
|
|
{ |
47
|
|
|
$this->print(Annotations::class); |
48
|
|
|
|
49
|
|
|
$this->depth++; |
50
|
|
|
foreach ($annotations as $annotation) { |
51
|
|
|
$annotation->dispatch($this); |
52
|
|
|
} |
53
|
|
|
$this->depth--; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function visitAnnotation(Annotation $annotation) : void |
57
|
|
|
{ |
58
|
|
|
$this->print(Annotation::class); |
59
|
|
|
|
60
|
|
|
$this->depth++; |
61
|
|
|
$annotation->getName()->dispatch($this); |
62
|
|
|
$annotation->getParameters()->dispatch($this); |
63
|
|
|
$this->depth--; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function visitReference(Reference $reference) : void |
67
|
|
|
{ |
68
|
|
|
$this->print( |
69
|
|
|
Reference::class, |
70
|
|
|
['identifier' => $reference->getIdentifier(), 'fully_qualified' => $reference->isFullyQualified()] |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function visitParameters(Parameters $parameters) : void |
75
|
|
|
{ |
76
|
|
|
$this->print(Parameters::class); |
77
|
|
|
|
78
|
|
|
$this->depth++; |
79
|
|
|
foreach ($parameters as $parameter) { |
80
|
|
|
$parameter->dispatch($this); |
81
|
|
|
} |
82
|
|
|
$this->depth--; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function visitNamedParameter(NamedParameter $parameter) : void |
86
|
|
|
{ |
87
|
|
|
$this->print(NamedParameter::class); |
88
|
|
|
|
89
|
|
|
$this->depth++; |
90
|
|
|
$parameter->getName()->dispatch($this); |
91
|
|
|
$parameter->getValue()->dispatch($this); |
92
|
|
|
$this->depth--; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function visitUnnamedParameter(UnnamedParameter $parameter) : void |
96
|
|
|
{ |
97
|
|
|
$this->print(UnnamedParameter::class); |
98
|
|
|
|
99
|
|
|
$this->depth++; |
100
|
|
|
$parameter->getValue()->dispatch($this); |
101
|
|
|
$this->depth--; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function visitListCollection(ListCollection $listCollection) : void |
105
|
|
|
{ |
106
|
|
|
$this->print(ListCollection::class); |
107
|
|
|
|
108
|
|
|
$this->depth++; |
109
|
|
|
foreach ($listCollection as $item) { |
110
|
|
|
$item->dispatch($this); |
111
|
|
|
} |
112
|
|
|
$this->depth--; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function visitMapCollection(MapCollection $mapCollection) : void |
116
|
|
|
{ |
117
|
|
|
$this->print(MapCollection::class); |
118
|
|
|
|
119
|
|
|
$this->depth++; |
120
|
|
|
foreach ($mapCollection as $item) { |
121
|
|
|
$item->dispatch($this); |
122
|
|
|
} |
123
|
|
|
$this->depth--; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function visitPair(Pair $pair) : void |
127
|
|
|
{ |
128
|
|
|
$this->print(Pair::class); |
129
|
|
|
|
130
|
|
|
$this->depth++; |
131
|
|
|
$pair->getKey()->dispatch($this); |
132
|
|
|
$pair->getValue()->dispatch($this); |
133
|
|
|
$this->depth--; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function visitIdentifier(Identifier $identifier) : void |
137
|
|
|
{ |
138
|
|
|
$this->print(Identifier::class, ['value' => $identifier->getValue()]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function visitConstantFetch(ConstantFetch $constantFetch) : void |
142
|
|
|
{ |
143
|
|
|
$this->print(ConstantFetch::class); |
144
|
|
|
|
145
|
|
|
$this->depth++; |
146
|
|
|
$constantFetch->getName()->dispatch($this); |
147
|
|
|
$this->depth--; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function visitClassConstantFetch(ClassConstantFetch $classConstantFetch) : void |
151
|
|
|
{ |
152
|
|
|
$this->print(ClassConstantFetch::class); |
153
|
|
|
|
154
|
|
|
$this->depth++; |
155
|
|
|
$classConstantFetch->getClass()->dispatch($this); |
156
|
|
|
$classConstantFetch->getName()->dispatch($this); |
157
|
|
|
$this->depth--; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function visitNullScalar(NullScalar $nullScalar) : void |
161
|
|
|
{ |
162
|
|
|
$this->print(NullScalar::class, ['value' => $nullScalar->getValue()]); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function visitBooleanScalar(BooleanScalar $booleanScalar) : void |
166
|
|
|
{ |
167
|
|
|
$this->print(BooleanScalar::class, ['value' => $booleanScalar->getValue()]); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function visitIntegerScalar(IntegerScalar $integerScalar) : void |
171
|
|
|
{ |
172
|
|
|
$this->print(IntegerScalar::class, ['value' => $integerScalar->getValue()]); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function visitFloatScalar(FloatScalar $floatScalar) : void |
176
|
|
|
{ |
177
|
|
|
$this->print(FloatScalar::class, ['value' => $floatScalar->getValue()]); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function visitStringScalar(StringScalar $stringScalar) : void |
181
|
|
|
{ |
182
|
|
|
$this->print(StringScalar::class, ['value' => $stringScalar->getValue()]); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param mixed[] $data |
187
|
|
|
*/ |
188
|
|
|
private function print(string $name, array $data = []) : void |
189
|
|
|
{ |
190
|
|
|
echo str_repeat(self::INDENT, $this->depth + 1); |
191
|
|
|
echo substr($name, strlen(Node::class) - 4); |
192
|
|
|
|
193
|
|
|
if (count($data) !== 0) { |
194
|
|
|
echo ' ', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
echo "\n"; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.