These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of PDepend. |
||
4 | * |
||
5 | * PHP Version 5 |
||
6 | * |
||
7 | * Copyright (c) 2008-2017 Manuel Pichler <[email protected]>. |
||
8 | * All rights reserved. |
||
9 | * |
||
10 | * Redistribution and use in source and binary forms, with or without |
||
11 | * modification, are permitted provided that the following conditions |
||
12 | * are met: |
||
13 | * |
||
14 | * * Redistributions of source code must retain the above copyright |
||
15 | * notice, this list of conditions and the following disclaimer. |
||
16 | * |
||
17 | * * Redistributions in binary form must reproduce the above copyright |
||
18 | * notice, this list of conditions and the following disclaimer in |
||
19 | * the documentation and/or other materials provided with the |
||
20 | * distribution. |
||
21 | * |
||
22 | * * Neither the name of Manuel Pichler nor the names of his |
||
23 | * contributors may be used to endorse or promote products derived |
||
24 | * from this software without specific prior written permission. |
||
25 | * |
||
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||
29 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||
30 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||
32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
33 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||
35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||
36 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
37 | * POSSIBILITY OF SUCH DAMAGE. |
||
38 | * |
||
39 | * @copyright 2008-2017 Manuel Pichler. All rights reserved. |
||
40 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
||
41 | * @since 2.3 |
||
42 | */ |
||
43 | |||
44 | namespace PDepend\Source\AST; |
||
45 | |||
46 | use PDepend\Source\ASTVisitor\ASTVisitor; |
||
47 | |||
48 | /** |
||
49 | * Represents a php class node. |
||
50 | * |
||
51 | * @copyright 2008-2017 Manuel Pichler. All rights reserved. |
||
52 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
||
53 | * @since 2.3 |
||
54 | */ |
||
55 | class ASTAnonymousClass extends ASTClass implements ASTNode |
||
56 | { |
||
57 | /** |
||
58 | * The parent node of this node or <b>null</b> when this node is the root |
||
59 | * of a node tree. |
||
60 | * |
||
61 | * @var \PDepend\Source\AST\ASTNode |
||
62 | */ |
||
63 | protected $parent = null; |
||
64 | |||
65 | /** |
||
66 | * Metadata for this node instance, serialized in a string. This string |
||
67 | * contains the start, end line, and the start, end column and the node |
||
68 | * image in a colon separated string. |
||
69 | * |
||
70 | * @var string |
||
71 | * @since 0.10.4 |
||
72 | */ |
||
73 | protected $metadata = ':::'; |
||
74 | |||
75 | /** |
||
76 | * @param string $image |
||
77 | * @return void |
||
78 | */ |
||
79 | 2 | public function setImage($image) |
|
80 | { |
||
81 | 2 | $this->setName($image); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Returns the source image of this ast node. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | 2 | public function getImage() |
|
90 | { |
||
91 | 2 | return $this->getName(); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Returns the start line for this ast node. |
||
96 | * |
||
97 | * @return integer |
||
98 | */ |
||
99 | 2 | public function getStartLine() |
|
100 | { |
||
101 | 2 | return $this->getMetadataInteger(0); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Returns the start column for this ast node. |
||
106 | * |
||
107 | * @return integer |
||
108 | */ |
||
109 | 2 | public function getStartColumn() |
|
110 | { |
||
111 | 2 | return $this->getMetadataInteger(2); |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * Returns the end line for this ast node. |
||
116 | * |
||
117 | * @return integer |
||
118 | */ |
||
119 | 2 | public function getEndLine() |
|
120 | { |
||
121 | 2 | return $this->getMetadataInteger(1); |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * Returns the end column for this ast node. |
||
126 | * |
||
127 | * @return integer |
||
128 | */ |
||
129 | 2 | public function getEndColumn() |
|
130 | { |
||
131 | 2 | return $this->getMetadataInteger(3); |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * For better performance we have moved the single setter methods for the |
||
136 | * node columns and lines into this configure method. |
||
137 | * |
||
138 | * @param integer $startLine |
||
139 | * @param integer $endLine |
||
140 | * @param integer $startColumn |
||
141 | * @param integer $endColumn |
||
142 | * @return void |
||
143 | * @since 0.9.10 |
||
144 | */ |
||
145 | 8 | View Code Duplication | public function configureLinesAndColumns($startLine, $endLine, $startColumn, $endColumn) |
146 | { |
||
147 | 8 | $this->setMetadataInteger(0, $startLine); |
|
148 | 8 | $this->setMetadataInteger(1, $endLine); |
|
149 | 8 | $this->setMetadataInteger(2, $startColumn); |
|
150 | 8 | $this->setMetadataInteger(3, $endColumn); |
|
151 | } |
||
152 | |||
153 | /** |
||
154 | * Returns the parent node of this node or <b>null</b> when this node is |
||
155 | * the root of a node tree. |
||
156 | * |
||
157 | * @return \PDepend\Source\AST\ASTNode |
||
158 | */ |
||
159 | 4 | public function getParent() |
|
160 | { |
||
161 | 4 | return $this->parent; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * Sets the parent node of this node. |
||
166 | * |
||
167 | * @param \PDepend\Source\AST\ASTNode $node |
||
168 | * @return void |
||
169 | */ |
||
170 | 12 | public function setParent(ASTNode $node) |
|
171 | { |
||
172 | 12 | $this->parent = $node; |
|
173 | } |
||
174 | |||
175 | /** |
||
176 | * Traverses up the node tree and finds all parent nodes that are instances |
||
177 | * of <b>$parentType</b>. |
||
178 | * |
||
179 | * @param string $parentType |
||
180 | * @return \PDepend\Source\AST\ASTNode[] |
||
181 | */ |
||
182 | 4 | View Code Duplication | public function getParentsOfType($parentType) |
183 | { |
||
184 | 4 | $parents = array(); |
|
185 | |||
186 | 4 | $parentNode = $this->parent; |
|
187 | 4 | while (is_object($parentNode)) { |
|
188 | 2 | if ($parentNode instanceof $parentType) { |
|
189 | 2 | array_unshift($parents, $parentNode); |
|
190 | } |
||
191 | 2 | $parentNode = $parentNode->getParent(); |
|
192 | } |
||
193 | 4 | return $parents; |
|
194 | } |
||
195 | |||
196 | /** |
||
197 | * This method adds a new child node at the first position of the children. |
||
198 | * |
||
199 | * @param \PDepend\Source\AST\ASTNode $node |
||
200 | * @return void |
||
201 | */ |
||
202 | 8 | public function prependChild(ASTNode $node) |
|
203 | { |
||
204 | 8 | array_unshift($this->nodes, $node); |
|
205 | 8 | $node->setParent($this); |
|
206 | } |
||
207 | |||
208 | /** |
||
209 | * Will return <b>true</b> if this class was declared anonymous in an |
||
210 | * allocation expression. |
||
211 | * |
||
212 | * @return boolean |
||
213 | */ |
||
214 | public function isAnonymous() |
||
215 | { |
||
216 | return true; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @param \PDepend\Source\ASTVisitor\ASTVisitor $visitor |
||
221 | * @param mixed $data |
||
222 | * @return integer |
||
223 | */ |
||
224 | 4 | public function accept(ASTVisitor $visitor, $data = null) |
|
225 | { |
||
226 | 4 | return $visitor->visitAnonymousClass($this, $data); |
|
227 | } |
||
228 | |||
229 | /** |
||
230 | * The magic sleep method will be called by PHP's runtime environment right |
||
231 | * before an instance of this class gets serialized. It should return an |
||
232 | * array with those property names that should be serialized for this class. |
||
233 | * |
||
234 | * @return array |
||
235 | * @since 0.10.0 |
||
236 | */ |
||
237 | 2 | public function __sleep() |
|
238 | { |
||
239 | 2 | return array_merge(array('metadata'), parent::__sleep()); |
|
240 | } |
||
241 | |||
242 | /** |
||
243 | * The magic wakeup method will be called by PHP's runtime environment when |
||
244 | * a serialized instance of this class was unserialized. This implementation |
||
245 | * of the wakeup method will register this object in the the global class |
||
246 | * context. |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | public function __wakeup() |
||
251 | { |
||
252 | $this->methods = null; |
||
0 ignored issues
–
show
|
|||
253 | |||
254 | foreach ($this->nodes as $node) { |
||
255 | $node->setParent($this); |
||
256 | } |
||
257 | |||
258 | parent::__wakeup(); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Returns an integer value that was stored under the given index. |
||
263 | * |
||
264 | * @param integer $index |
||
265 | * @return integer |
||
266 | * @since 0.10.4 |
||
267 | */ |
||
268 | 8 | protected function getMetadataInteger($index) |
|
269 | { |
||
270 | 8 | return (int) $this->getMetadata($index); |
|
271 | } |
||
272 | |||
273 | /** |
||
274 | * Stores an integer value under the given index in the internally used data |
||
275 | * string. |
||
276 | * |
||
277 | * @param integer $index |
||
278 | * @param integer $value |
||
279 | * @return void |
||
280 | * @since 0.10.4 |
||
281 | */ |
||
282 | 8 | protected function setMetadataInteger($index, $value) |
|
283 | { |
||
284 | 8 | $this->setMetadata($index, $value); |
|
285 | } |
||
286 | |||
287 | /** |
||
288 | * Returns the value that was stored under the given index. |
||
289 | * |
||
290 | * @param integer $index |
||
291 | * @return mixed |
||
292 | * @since 0.10.4 |
||
293 | */ |
||
294 | 8 | protected function getMetadata($index) |
|
295 | { |
||
296 | 8 | $metadata = explode(':', $this->metadata, $this->getMetadataSize()); |
|
297 | 8 | return $metadata[$index]; |
|
298 | } |
||
299 | |||
300 | /** |
||
301 | * Stores the given value under the given index in an internal storage |
||
302 | * container. |
||
303 | * |
||
304 | * @param integer $index |
||
305 | * @param mixed $value |
||
306 | * @return void |
||
307 | * @since 0.10.4 |
||
308 | */ |
||
309 | 8 | View Code Duplication | protected function setMetadata($index, $value) |
310 | { |
||
311 | 8 | $metadata = explode(':', $this->metadata, $this->getMetadataSize()); |
|
312 | 8 | $metadata[$index] = $value; |
|
313 | |||
314 | 8 | $this->metadata = join(':', $metadata); |
|
315 | } |
||
316 | |||
317 | /** |
||
318 | * Returns the total number of the used property bag. |
||
319 | * |
||
320 | * @return integer |
||
321 | * @since 0.10.4 |
||
322 | */ |
||
323 | 8 | protected function getMetadataSize() |
|
324 | { |
||
325 | 8 | return 4; |
|
326 | } |
||
327 | } |
||
328 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..