1 | <?php |
||
26 | abstract class AbstractNode |
||
27 | { |
||
28 | /** |
||
29 | * |
||
30 | * @var \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node |
||
31 | */ |
||
32 | private $node = null; |
||
33 | |||
34 | /** |
||
35 | * The collected metrics for this node. |
||
36 | * |
||
37 | * @var array(string=>mixed) $_metrics |
||
|
|||
38 | */ |
||
39 | private $metrics = null; |
||
40 | |||
41 | /** |
||
42 | * Constructs a new PHPMD node. |
||
43 | * |
||
44 | * @param \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node |
||
45 | */ |
||
46 | 50 | public function __construct($node) |
|
50 | |||
51 | /** |
||
52 | * The magic call method is used to pipe requests from rules direct |
||
53 | * to the underlying PDepend ast node. |
||
54 | * |
||
55 | * @param string $name |
||
56 | * @param array $args |
||
57 | * @return mixed |
||
58 | * @throws \BadMethodCallException When the underlying PDepend node |
||
59 | * does not contain a method named <b>$name</b>. |
||
60 | */ |
||
61 | 34 | public function __call($name, array $args) |
|
70 | |||
71 | /** |
||
72 | * Returns the parent of this node or <b>null</b> when no parent node |
||
73 | * exists. |
||
74 | * |
||
75 | * @return ASTNode |
||
76 | */ |
||
77 | 9 | public function getParent() |
|
84 | |||
85 | /** |
||
86 | * Returns a child node at the given index. |
||
87 | * |
||
88 | * @param integer $index The child offset. |
||
89 | * @return \PHPMD\Node\ASTNode |
||
90 | */ |
||
91 | 11 | public function getChild($index) |
|
98 | |||
99 | /** |
||
100 | * Returns the first child of the given type or <b>null</b> when this node |
||
101 | * has no child of the given type. |
||
102 | * |
||
103 | * @param string $type The searched child type. |
||
104 | * @return \PHPMD\AbstractNode |
||
105 | */ |
||
106 | 9 | public function getFirstChildOfType($type) |
|
107 | { |
||
108 | 9 | $node = $this->node->getFirstChildOfType('PDepend\Source\AST\AST' . $type); |
|
109 | 9 | if ($node === null) { |
|
110 | 2 | return null; |
|
111 | } |
||
112 | 7 | return new ASTNode($node, $this->getFileName()); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Searches recursive for all children of this node that are of the given |
||
117 | * type. |
||
118 | * |
||
119 | * @param string $type The searched child type. |
||
120 | * @return \PHPMD\AbstractNode[] |
||
121 | */ |
||
122 | 48 | public function findChildrenOfType($type) |
|
132 | |||
133 | /** |
||
134 | * Tests if this node represents the the given type. |
||
135 | * |
||
136 | * @param string $type The expected node type. |
||
137 | * @return boolean |
||
138 | */ |
||
139 | 2 | public function isInstanceOf($type) |
|
144 | |||
145 | /** |
||
146 | * Returns the image of the underlying node. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 2 | public function getImage() |
|
154 | |||
155 | /** |
||
156 | * Returns the source name for this node, maybe a class or interface name, |
||
157 | * or a package, method, function name. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 15 | public function getName() |
|
165 | |||
166 | /** |
||
167 | * Returns the begin line for this node in the php source code file. |
||
168 | * |
||
169 | * @return integer |
||
170 | */ |
||
171 | 6 | public function getBeginLine() |
|
175 | |||
176 | /** |
||
177 | * Returns the end line for this node in the php source code file. |
||
178 | * |
||
179 | * @return integer |
||
180 | */ |
||
181 | public function getEndLine() |
||
185 | |||
186 | /** |
||
187 | * Returns the name of the declaring source file. |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | 47 | public function getFileName() |
|
195 | |||
196 | /** |
||
197 | * Returns the wrapped PDepend node instance. |
||
198 | * |
||
199 | * @return \PDepend\Source\AST\ASTArtifact |
||
200 | */ |
||
201 | 44 | public function getNode() |
|
205 | |||
206 | /** |
||
207 | * Returns a textual representation/name for the concrete node type. |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | 3 | public function getType() |
|
216 | |||
217 | /** |
||
218 | * This method will return the metric value for the given identifier or |
||
219 | * <b>null</b> when no such metric exists. |
||
220 | * |
||
221 | * @param string $name The metric name or abbreviation. |
||
222 | * @return mixed |
||
223 | */ |
||
224 | 3 | public function getMetric($name) |
|
231 | |||
232 | /** |
||
233 | * This method will set the metrics for this node. |
||
234 | * |
||
235 | * @param array(string=>mixed) $metrics The collected node metrics. |
||
236 | * @return void |
||
237 | */ |
||
238 | 6 | public function setMetrics(array $metrics) |
|
244 | |||
245 | /** |
||
246 | * Checks if this node has a suppressed annotation for the given rule |
||
247 | * instance. |
||
248 | * |
||
249 | * @param \PHPMD\Rule $rule |
||
250 | * @return boolean |
||
251 | */ |
||
252 | abstract public function hasSuppressWarningsAnnotationFor(Rule $rule); |
||
253 | |||
254 | /** |
||
255 | * Returns the full qualified name of a class, an interface, a method or |
||
256 | * a function. |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | abstract public function getFullQualifiedName(); |
||
261 | |||
262 | /** |
||
263 | * Returns the name of the parent type or <b>null</b> when this node has no |
||
264 | * parent type. |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | abstract public function getParentName(); |
||
269 | |||
270 | /** |
||
271 | * Returns the name of the parent package. |
||
272 | * |
||
273 | * @return string |
||
274 | */ |
||
275 | abstract public function getNamespaceName(); |
||
276 | } |
||
277 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.