Complex classes like DomNode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DomNode, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class DomNode implements IQuery { |
||
18 | |||
19 | /** |
||
20 | * Element Node, used for regular elements |
||
21 | */ |
||
22 | const NODE_ELEMENT = 0; |
||
23 | /** |
||
24 | * Text Node |
||
25 | */ |
||
26 | const NODE_TEXT = 1; |
||
27 | /** |
||
28 | * Comment Node |
||
29 | */ |
||
30 | const NODE_COMMENT = 2; |
||
31 | /** |
||
32 | * Conditional Node (<![if]> <![endif]) |
||
33 | */ |
||
34 | const NODE_CONDITIONAL = 3; |
||
35 | /** |
||
36 | * CDATA Node (<![CDATA[]]> |
||
37 | */ |
||
38 | const NODE_CDATA = 4; |
||
39 | /** |
||
40 | * Doctype Node |
||
41 | */ |
||
42 | const NODE_DOCTYPE = 5; |
||
43 | /** |
||
44 | * XML Node, used for tags that start with ?, like <?xml and <?php |
||
45 | */ |
||
46 | const NODE_XML = 6; |
||
47 | /** |
||
48 | * ASP Node |
||
49 | */ |
||
50 | const NODE_ASP = 7; |
||
51 | |||
52 | #php4 Compatibility with PHP4, this gets changed to a regular var in release tool |
||
53 | #static $NODE_TYPE = self::NODE_ELEMENT; |
||
|
|||
54 | #php4e |
||
55 | #php5 |
||
56 | /** |
||
57 | * Node type of class |
||
58 | */ |
||
59 | const NODE_TYPE = self::NODE_ELEMENT; |
||
60 | #php5e |
||
61 | |||
62 | |||
63 | /** |
||
64 | * Name of the selector class |
||
65 | * @var string |
||
66 | * @see select() |
||
67 | */ |
||
68 | var $selectClass = 'pQuery\\HtmlSelector'; |
||
69 | /** |
||
70 | * Name of the parser class |
||
71 | * @var string |
||
72 | * @see setOuterText() |
||
73 | * @see setInnerText() |
||
74 | */ |
||
75 | var $parserClass = 'pQuery\\Html5Parser'; |
||
76 | |||
77 | /** |
||
78 | * Name of the class used for {@link addChild()} |
||
79 | * @var string |
||
80 | */ |
||
81 | var $childClass = __CLASS__; |
||
82 | /** |
||
83 | * Name of the class used for {@link addText()} |
||
84 | * @var string |
||
85 | */ |
||
86 | var $childClass_Text = 'pQuery\\TextNode'; |
||
87 | /** |
||
88 | * Name of the class used for {@link addComment()} |
||
89 | * @var string |
||
90 | */ |
||
91 | var $childClass_Comment = 'pQuery\\CommentNode'; |
||
92 | /** |
||
93 | * Name of the class used for {@link addContional()} |
||
94 | * @var string |
||
95 | */ |
||
96 | var $childClass_Conditional = 'pQuery\\ConditionalTagNode'; |
||
97 | /** |
||
98 | * Name of the class used for {@link addCDATA()} |
||
99 | * @var string |
||
100 | */ |
||
101 | var $childClass_CDATA = 'pQuery\\CdataNode'; |
||
102 | /** |
||
103 | * Name of the class used for {@link addDoctype()} |
||
104 | * @var string |
||
105 | */ |
||
106 | var $childClass_Doctype = 'pQuery\\DoctypeNode'; |
||
107 | /** |
||
108 | * Name of the class used for {@link addXML()} |
||
109 | * @var string |
||
110 | */ |
||
111 | var $childClass_XML = 'pQuery\\XmlNode'; |
||
112 | /** |
||
113 | * Name of the class used for {@link addASP()} |
||
114 | * @var string |
||
115 | */ |
||
116 | var $childClass_ASP = 'pQuery\\AspEmbeddedNode'; |
||
117 | |||
118 | /** |
||
119 | * Parent node, null if none |
||
120 | * @var DomNode |
||
121 | * @see changeParent() |
||
122 | */ |
||
123 | var $parent = null; |
||
124 | |||
125 | /** |
||
126 | * Attributes of node |
||
127 | * @var array |
||
128 | * @internal array('attribute' => 'value') |
||
129 | * @internal Public for faster access! |
||
130 | * @see getAttribute() |
||
131 | * @see setAttribute() |
||
132 | * @access private |
||
133 | */ |
||
134 | var $attributes = array(); |
||
135 | |||
136 | /** |
||
137 | * Namespace info for attributes |
||
138 | * @var array |
||
139 | * @internal array('tag' => array(array('ns', 'tag', 'ns:tag', index))) |
||
140 | * @internal Public for easy outside modifications! |
||
141 | * @see findAttribute() |
||
142 | * @access private |
||
143 | */ |
||
144 | var $attributes_ns = null; |
||
145 | |||
146 | /** |
||
147 | * Array of child nodes |
||
148 | * @var array |
||
149 | * @internal Public for faster access! |
||
150 | * @see childCount() |
||
151 | * @see getChild() |
||
152 | * @see addChild() |
||
153 | * @see deleteChild() |
||
154 | * @access private |
||
155 | */ |
||
156 | var $children = array(); |
||
157 | |||
158 | /** |
||
159 | * Full tag name (including namespace) |
||
160 | * @var string |
||
161 | * @see getTagName() |
||
162 | * @see getNamespace() |
||
163 | */ |
||
164 | var $tag = ''; |
||
165 | |||
166 | /** |
||
167 | * Namespace info for tag |
||
168 | * @var array |
||
169 | * @internal array('namespace', 'tag') |
||
170 | * @internal Public for easy outside modifications! |
||
171 | * @access private |
||
172 | */ |
||
173 | var $tag_ns = null; |
||
174 | |||
175 | /** |
||
176 | * Is node a self closing node? No closing tag if true. |
||
177 | * @var bool |
||
178 | */ |
||
179 | var $self_close = false; |
||
180 | |||
181 | /** |
||
182 | * If self close, then this will be used to close the tag |
||
183 | * @var string |
||
184 | * @see $self_close |
||
185 | */ |
||
186 | var $self_close_str = ' /'; |
||
187 | |||
188 | /** |
||
189 | * Use short tags for attributes? If true, then attributes |
||
190 | * with values equal to the attribute name will not output |
||
191 | * the value, e.g. selected="selected" will be selected. |
||
192 | * @var bool |
||
193 | */ |
||
194 | var $attribute_shorttag = true; |
||
195 | |||
196 | /** |
||
197 | * Function map used for the selector filter |
||
198 | * @var array |
||
199 | * @internal array('root' => 'filter_root') will cause the |
||
200 | * selector to call $this->filter_root at :root |
||
201 | * @access private |
||
202 | */ |
||
203 | var $filter_map = array( |
||
204 | 'root' => 'filter_root', |
||
205 | 'nth-child' => 'filter_nchild', |
||
206 | 'eq' => 'filter_nchild', //jquery (naming) compatibility |
||
207 | 'gt' => 'filter_gt', |
||
208 | 'lt' => 'filter_lt', |
||
209 | 'nth-last-child' => 'filter_nlastchild', |
||
210 | 'nth-of-type' => 'filter_ntype', |
||
211 | 'nth-last-of-type' => 'filter_nlastype', |
||
212 | 'odd' => 'filter_odd', |
||
213 | 'even' => 'filter_even', |
||
214 | 'every' => 'filter_every', |
||
215 | 'first-child' => 'filter_first', |
||
216 | 'last-child' => 'filter_last', |
||
217 | 'first-of-type' => 'filter_firsttype', |
||
218 | 'last-of-type' => 'filter_lasttype', |
||
219 | 'only-child' => 'filter_onlychild', |
||
220 | 'only-of-type' => 'filter_onlytype', |
||
221 | 'empty' => 'filter_empty', |
||
222 | 'not-empty' => 'filter_notempty', |
||
223 | 'has-text' => 'filter_hastext', |
||
224 | 'no-text' => 'filter_notext', |
||
225 | 'lang' => 'filter_lang', |
||
226 | 'contains' => 'filter_contains', |
||
227 | 'has' => 'filter_has', |
||
228 | 'not' => 'filter_not', |
||
229 | 'element' => 'filter_element', |
||
230 | 'text' => 'filter_text', |
||
231 | 'comment' => 'filter_comment', |
||
232 | 'checked' => 'filter_checked', |
||
233 | 'selected' => 'filter_selected', |
||
234 | ); |
||
235 | |||
236 | /** |
||
237 | * Class constructor |
||
238 | * @param string|array $tag Name of the tag, or array with taginfo (array( |
||
239 | * 'tag_name' => 'tag', |
||
240 | * 'self_close' => false, |
||
241 | * 'attributes' => array('attribute' => 'value'))) |
||
242 | * @param DomNode $parent Parent of node, null if none |
||
243 | */ |
||
244 | 37 | function __construct($tag, $parent) { |
|
255 | |||
256 | #php4 PHP4 class constructor compatibility |
||
257 | #function DomNode($tag, $parent) {return $this->__construct($tag, $parent);} |
||
258 | #php4e |
||
259 | |||
260 | /** |
||
261 | * Class destructor |
||
262 | * @access private |
||
263 | */ |
||
264 | 15 | function __destruct() { |
|
267 | |||
268 | /** |
||
269 | * Class toString, outputs {@link $tag} |
||
270 | * @return string |
||
271 | * @access private |
||
272 | */ |
||
273 | function __toString() { |
||
276 | |||
277 | /** |
||
278 | * Class magic get method, outputs {@link getAttribute()} |
||
279 | * @return string |
||
280 | * @access private |
||
281 | */ |
||
282 | 4 | function __get($attribute) { |
|
285 | |||
286 | /** |
||
287 | * Class magic set method, performs {@link setAttribute()} |
||
288 | * @access private |
||
289 | */ |
||
290 | 4 | function __set($attribute, $value) { |
|
293 | |||
294 | /** |
||
295 | * Class magic isset method, returns {@link hasAttribute()} |
||
296 | * @return bool |
||
297 | * @access private |
||
298 | */ |
||
299 | function __isset($attribute) { |
||
302 | |||
303 | /** |
||
304 | * Class magic unset method, performs {@link deleteAttribute()} |
||
305 | * @access private |
||
306 | */ |
||
307 | 1 | function __unset($attribute) { |
|
310 | |||
311 | /** |
||
312 | * Class magic invoke method, performs {@link query()}. |
||
313 | * @param string $query The css query to run on the nodes. |
||
314 | * @return \pQuery |
||
315 | */ |
||
316 | 3 | function __invoke($query = '*') { |
|
319 | |||
320 | /** |
||
321 | * Returns place in document |
||
322 | * @return string |
||
323 | */ |
||
324 | function dumpLocation() { |
||
327 | |||
328 | /** |
||
329 | * Returns all the attributes and their values |
||
330 | * @return string |
||
331 | * @access private |
||
332 | */ |
||
333 | 20 | protected function toString_attributes() { |
|
344 | |||
345 | /** |
||
346 | * Returns the content of the node (child tags and text) |
||
347 | * @param bool $attributes Print attributes of child tags |
||
348 | * @param bool|int $recursive How many sublevels of childtags to print. True for all. |
||
349 | * @param bool $content_only Only print text, false will print tags too. |
||
350 | * @return string |
||
351 | * @access private |
||
352 | */ |
||
353 | 23 | protected function toString_content($attributes = true, $recursive = true, $content_only = false) { |
|
360 | |||
361 | /** |
||
362 | * Returns the node as string |
||
363 | * @param bool $attributes Print attributes (of child tags) |
||
364 | * @param bool|int $recursive How many sub-levels of child tags to print. True for all. |
||
365 | * @param bool|int $content_only Only print text, false will print tags too. |
||
366 | * @return string |
||
367 | */ |
||
368 | 23 | function toString($attributes = true, $recursive = true, $content_only = false) { |
|
391 | |||
392 | /** |
||
393 | * Similar to JavaScript outerText, will return full (html formatted) node |
||
394 | * @return string |
||
395 | */ |
||
396 | function getOuterText() { |
||
399 | |||
400 | /** |
||
401 | * Similar to JavaScript outerText, will replace node (and child nodes) with new text |
||
402 | * @param string $text |
||
403 | * @param HtmlParserBase $parser Null to auto create instance |
||
404 | * @return bool|array True on succeed, array with errors on failure |
||
405 | */ |
||
406 | function setOuterText($text, $parser = null) { |
||
419 | |||
420 | /** |
||
421 | * Return html code of node |
||
422 | * @internal jquery (naming) compatibility |
||
423 | * @param string|null $value The value to set or null to get the value. |
||
424 | * @see toString() |
||
425 | * @return string |
||
426 | */ |
||
427 | 20 | function html($value = null) { |
|
433 | |||
434 | /** |
||
435 | * Similar to JavaScript innerText, will return (html formatted) content |
||
436 | * @return string |
||
437 | */ |
||
438 | 21 | function getInnerText() { |
|
441 | |||
442 | /** |
||
443 | * Similar to JavaScript innerText, will replace child nodes with new text |
||
444 | * @param string $text |
||
445 | * @param HtmlParserBase $parser Null to auto create instance |
||
446 | * @return bool|array True on succeed, array with errors on failure |
||
447 | */ |
||
448 | 2 | function setInnerText($text, $parser = null) { |
|
460 | |||
461 | /** |
||
462 | * Similar to JavaScript plainText, will return text in node (and subnodes) |
||
463 | * @return string |
||
464 | */ |
||
465 | 2 | function getPlainText() { |
|
468 | |||
469 | /** |
||
470 | * Return plaintext taking document encoding into account |
||
471 | * @return string |
||
472 | */ |
||
473 | function getPlainTextUTF8() { |
||
481 | |||
482 | /** |
||
483 | * Similar to JavaScript plainText, will replace child nodes with new text (literal) |
||
484 | * @param string $text |
||
485 | */ |
||
486 | 1 | function setPlainText($text) { |
|
492 | |||
493 | /** |
||
494 | * Delete node from parent and clear node |
||
495 | */ |
||
496 | 15 | function delete() { |
|
504 | |||
505 | /** |
||
506 | * Detach node from parent |
||
507 | * @param bool $move_children_up Only detach current node and replace it with child nodes |
||
508 | * @internal jquery (naming) compatibility |
||
509 | * @see delete() |
||
510 | */ |
||
511 | 1 | function detach($move_children_up = false) { |
|
522 | |||
523 | /** |
||
524 | * Deletes all child nodes from node |
||
525 | */ |
||
526 | 15 | function clear() { |
|
533 | |||
534 | /** |
||
535 | * Get top parent |
||
536 | * @return DomNode Root, null if node has no parent |
||
537 | */ |
||
538 | function getRoot() { |
||
548 | |||
549 | /** |
||
550 | * Change parent |
||
551 | * @param null|DomNode $to New parent, null if none |
||
552 | * @param false|int $index Add child to parent if not present at index, false to not add, negative to count from end, null to append |
||
553 | */ |
||
554 | #php4 |
||
555 | #function changeParent($to, &$index) { |
||
556 | #php4e |
||
557 | #php5 |
||
558 | 10 | function changeParent($to, &$index = null) { |
|
571 | |||
572 | /** |
||
573 | * Find out if node has (a certain) parent |
||
574 | * @param DomNode|string $tag Match against parent, string to match tag, object to fully match node, null to return if node has parent |
||
575 | * @param bool $recursive |
||
576 | * @return bool |
||
577 | */ |
||
578 | function hasParent($tag = null, $recursive = false) { |
||
591 | |||
592 | /** |
||
593 | * Find out if node is parent of a certain tag |
||
594 | * @param DomNode|string $tag Match against parent, string to match tag, object to fully match node |
||
595 | * @param bool $recursive |
||
596 | * @return bool |
||
597 | * @see hasParent() |
||
598 | */ |
||
599 | function isParent($tag, $recursive = false) { |
||
602 | |||
603 | /** |
||
604 | * Find out if node is text |
||
605 | * @return bool |
||
606 | */ |
||
607 | function isText() { |
||
610 | |||
611 | /** |
||
612 | * Find out if node is comment |
||
613 | * @return bool |
||
614 | */ |
||
615 | function isComment() { |
||
618 | |||
619 | /** |
||
620 | * Find out if node is text or comment node |
||
621 | * @return bool |
||
622 | */ |
||
623 | function isTextOrComment() { |
||
626 | |||
627 | /** |
||
628 | * Move node to other node |
||
629 | * @param DomNode $to New parent, null if none |
||
630 | * @param int $new_index Add child to parent at index if not present, null to not add, negative to count from end |
||
631 | * @internal Performs {@link changeParent()} |
||
632 | */ |
||
633 | #php4 |
||
634 | #function move($to, &$new_index) { |
||
635 | #php4e |
||
636 | #php5 |
||
637 | function move($to, &$new_index = -1) { |
||
641 | |||
642 | /** |
||
643 | * Move child nodes to other node |
||
644 | * @param DomNode $to New parent, null if none |
||
645 | * @param int $new_index Add child to new node at index if not present, null to not add, negative to count from end |
||
646 | * @param int $start Index from child node where to start wrapping, 0 for first element |
||
647 | * @param int $end Index from child node where to end wrapping, -1 for last element |
||
648 | */ |
||
649 | #php4 |
||
650 | #function moveChildren($to, &$new_index, $start = 0, $end = -1) { |
||
651 | #php4e |
||
652 | #php5 |
||
653 | 2 | function moveChildren($to, &$new_index = -1, $start = 0, $end = -1) { |
|
662 | |||
663 | /** |
||
664 | * Index of node in parent |
||
665 | * @param bool $count_all True to count all tags, false to ignore text and comments |
||
666 | * @return int -1 if not found |
||
667 | */ |
||
668 | 10 | function index($count_all = true) { |
|
695 | |||
696 | /** |
||
697 | * Change index of node in parent |
||
698 | * @param int $index New index |
||
699 | */ |
||
700 | function setIndex($index) { |
||
709 | |||
710 | /** |
||
711 | * Index of all similar nodes in parent |
||
712 | * @return int -1 if not found |
||
713 | */ |
||
714 | function typeIndex() { |
||
739 | |||
740 | /** |
||
741 | * Calculate indent of node (number of parent tags - 1) |
||
742 | * @return int |
||
743 | */ |
||
744 | function indent() { |
||
747 | |||
748 | /** |
||
749 | * Get sibling node |
||
750 | * @param int $offset Offset from current node |
||
751 | * @return DomNode Null if not found |
||
752 | */ |
||
753 | function getSibling($offset = 1) { |
||
761 | |||
762 | /** |
||
763 | * Get node next to current |
||
764 | * @param bool $skip_text_comments |
||
765 | * @return DomNode Null if not found |
||
766 | * @see getSibling() |
||
767 | * @see getPreviousSibling() |
||
768 | */ |
||
769 | function getNextSibling($skip_text_comments = true) { |
||
781 | |||
782 | /** |
||
783 | * Get node previous to current |
||
784 | * @param bool $skip_text_comments |
||
785 | * @return DomNode Null if not found |
||
786 | * @see getSibling() |
||
787 | * @see getNextSibling() |
||
788 | */ |
||
789 | function getPreviousSibling($skip_text_comments = true) { |
||
801 | |||
802 | /** |
||
803 | * Get namespace of node |
||
804 | * @return string |
||
805 | * @see setNamespace() |
||
806 | */ |
||
807 | 2 | function getNamespace() { |
|
819 | |||
820 | /** |
||
821 | * Set namespace of node |
||
822 | * @param string $ns |
||
823 | * @see getNamespace() |
||
824 | */ |
||
825 | function setNamespace($ns) { |
||
831 | |||
832 | /** |
||
833 | * Get tagname of node (without namespace) |
||
834 | * @return string |
||
835 | * @see setTag() |
||
836 | */ |
||
837 | 2 | function getTag() { |
|
844 | |||
845 | /** |
||
846 | * Set tag (with or without namespace) |
||
847 | * @param string $tag |
||
848 | * @param bool $with_ns Does $tag include namespace? |
||
849 | * @see getTag() |
||
850 | */ |
||
851 | 2 | function setTag($tag, $with_ns = false) { |
|
861 | |||
862 | /** |
||
863 | * Try to determine the encoding of the current tag |
||
864 | * @return string|bool False if encoding could not be found |
||
865 | */ |
||
866 | function getEncoding() { |
||
881 | |||
882 | /** |
||
883 | * Number of children in node |
||
884 | * @param bool $ignore_text_comments Ignore text/comments with calculation |
||
885 | * @return int |
||
886 | */ |
||
887 | 37 | function childCount($ignore_text_comments = false) { |
|
906 | |||
907 | /** |
||
908 | * Find node in children |
||
909 | * @param DomNode $child |
||
910 | * @return int False if not found |
||
911 | */ |
||
912 | 12 | function findChild($child) { |
|
915 | |||
916 | /** |
||
917 | * Checks if node has another node as child |
||
918 | * @param DomNode $child |
||
919 | * @return bool |
||
920 | */ |
||
921 | function hasChild($child) { |
||
924 | |||
925 | /** |
||
926 | * Get childnode |
||
927 | * @param int|DomNode $child Index, negative to count from end |
||
928 | * @param bool $ignore_text_comments Ignore text/comments with index calculation |
||
929 | * @return DomNode |
||
930 | */ |
||
931 | function &getChild($child, $ignore_text_comments = false) { |
||
963 | |||
964 | /** |
||
965 | * Add child node |
||
966 | * @param string|DomNode $tag Tag name or object |
||
967 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
968 | * @return DomNode Added node |
||
969 | */ |
||
970 | #php4 |
||
971 | #function &addChild($tag, &$offset) { |
||
972 | #php4e |
||
973 | #php5 |
||
974 | 37 | function &addChild($tag, &$offset = null) { |
|
1002 | |||
1003 | /** |
||
1004 | * First child node |
||
1005 | * @param bool $ignore_text_comments Ignore text/comments with index calculation |
||
1006 | * @return DomNode |
||
1007 | */ |
||
1008 | function &firstChild($ignore_text_comments = false) { |
||
1011 | |||
1012 | /** |
||
1013 | * Last child node |
||
1014 | * @param bool $ignore_text_comments Ignore text/comments with index calculation |
||
1015 | * @return DomNode |
||
1016 | */ |
||
1017 | function &lastChild($ignore_text_comments = false) { |
||
1020 | |||
1021 | /** |
||
1022 | * Insert childnode |
||
1023 | * @param string|DomNode $tag Tagname or object |
||
1024 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1025 | * @return DomNode Added node |
||
1026 | * @see addChild(); |
||
1027 | */ |
||
1028 | function &insertChild($tag, $index) { |
||
1031 | |||
1032 | /** |
||
1033 | * Add text node |
||
1034 | * @param string $text |
||
1035 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1036 | * @return DomNode Added node |
||
1037 | * @see addChild(); |
||
1038 | */ |
||
1039 | #php4 |
||
1040 | #function &addText($text, &$offset) { |
||
1041 | #php4e |
||
1042 | #php5 |
||
1043 | 37 | function &addText($text, &$offset = null) { |
|
1047 | |||
1048 | /** |
||
1049 | * Add comment node |
||
1050 | * @param string $text |
||
1051 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1052 | * @return DomNode Added node |
||
1053 | * @see addChild(); |
||
1054 | */ |
||
1055 | #php4 |
||
1056 | #function &addComment($text, &$offset) { |
||
1057 | #php4e |
||
1058 | #php5 |
||
1059 | 9 | function &addComment($text, &$offset = null) { |
|
1063 | |||
1064 | /** |
||
1065 | * Add conditional node |
||
1066 | * @param string $condition |
||
1067 | * @param bool True for <!--[if, false for <![if |
||
1068 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1069 | * @return DomNode Added node |
||
1070 | * @see addChild(); |
||
1071 | */ |
||
1072 | #php4 |
||
1073 | #function &addConditional($condition, $hidden = true, &$offset) { |
||
1074 | #php4e |
||
1075 | #php5 |
||
1076 | function &addConditional($condition, $hidden = true, &$offset = null) { |
||
1080 | |||
1081 | /** |
||
1082 | * Add CDATA node |
||
1083 | * @param string $text |
||
1084 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1085 | * @return DomNode Added node |
||
1086 | * @see addChild(); |
||
1087 | */ |
||
1088 | #php4 |
||
1089 | #function &addCDATA($text, &$offset) { |
||
1090 | #php4e |
||
1091 | #php5 |
||
1092 | function &addCDATA($text, &$offset = null) { |
||
1096 | |||
1097 | /** |
||
1098 | * Add doctype node |
||
1099 | * @param string $dtd |
||
1100 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1101 | * @return DomNode Added node |
||
1102 | * @see addChild(); |
||
1103 | */ |
||
1104 | #php4 |
||
1105 | #function &addDoctype($dtd, &$offset) { |
||
1106 | #php4e |
||
1107 | #php5 |
||
1108 | 9 | function &addDoctype($dtd, &$offset = null) { |
|
1112 | |||
1113 | /** |
||
1114 | * Add xml node |
||
1115 | * @param string $tag Tag name after "?", e.g. "php" or "xml" |
||
1116 | * @param string $text |
||
1117 | * @param array $attributes Array of attributes (array('attribute' => 'value')) |
||
1118 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1119 | * @return DomNode Added node |
||
1120 | * @see addChild(); |
||
1121 | */ |
||
1122 | #php4 |
||
1123 | #function &addXML($tag = 'xml', $text = '', $attributes = array(), &$offset) { |
||
1124 | #php4e |
||
1125 | #php5 |
||
1126 | function &addXML($tag = 'xml', $text = '', $attributes = array(), &$offset = null) { |
||
1130 | |||
1131 | /** |
||
1132 | * Add ASP node |
||
1133 | * @param string $tag Tag name after "%" |
||
1134 | * @param string $text |
||
1135 | * @param array $attributes Array of attributes (array('attribute' => 'value')) |
||
1136 | * @param int $offset Position to insert node, negative to count from end, null to append |
||
1137 | * @return DomNode Added node |
||
1138 | * @see addChild(); |
||
1139 | */ |
||
1140 | #php4 |
||
1141 | #function &addASP($tag = '', $text = '', $attributes = array(), &$offset) { |
||
1142 | #php4e |
||
1143 | #php5 |
||
1144 | function &addASP($tag = '', $text = '', $attributes = array(), &$offset = null) { |
||
1148 | |||
1149 | /** |
||
1150 | * Delete a child node |
||
1151 | * @param int|DomNode $child Child(index) to delete, negative to count from end |
||
1152 | * @param bool $soft_delete False to call {@link delete()} from child |
||
1153 | */ |
||
1154 | 12 | function deleteChild($child, $soft_delete = false) { |
|
1177 | |||
1178 | /** |
||
1179 | * Wrap node |
||
1180 | * @param string|DomNode $node Wrapping node, string to create new element node |
||
1181 | * @param int $wrap_index Index to insert current node in wrapping node, -1 to append |
||
1182 | * @param int $node_index Index to insert wrapping node, null to keep at same position |
||
1183 | * @return DomNode Wrapping node |
||
1184 | */ |
||
1185 | 2 | function wrap($node, $wrap_index = -1, $node_index = null) { |
|
1199 | |||
1200 | /** |
||
1201 | * Wrap child nodes |
||
1202 | * @param string|DomNode $node Wrapping node, string to create new element node |
||
1203 | * @param int $start Index from child node where to start wrapping, 0 for first element |
||
1204 | * @param int $end Index from child node where to end wrapping, -1 for last element |
||
1205 | * @param int $wrap_index Index to insert in wrapping node, -1 to append |
||
1206 | * @param int $node_index Index to insert current node, null to keep at same position |
||
1207 | * @return DomNode Wrapping node |
||
1208 | */ |
||
1209 | 1 | function wrapInner($node, $start = 0, $end = -1, $wrap_index = -1, $node_index = null) { |
|
1226 | |||
1227 | /** |
||
1228 | * Number of attributes |
||
1229 | * @return int |
||
1230 | */ |
||
1231 | function attributeCount() { |
||
1234 | |||
1235 | /** |
||
1236 | * Find attribute using namespace, name or both |
||
1237 | * @param string|int $attr Negative int to count from end |
||
1238 | * @param string $compare "namespace", "name" or "total" |
||
1239 | * @param bool $case_sensitive Compare with case sensitivity |
||
1240 | * @return array array('ns', 'attr', 'ns:attr', index) |
||
1241 | * @access private |
||
1242 | */ |
||
1243 | 27 | protected function findAttribute($attr, $compare = 'total', $case_sensitive = false) { |
|
1316 | |||
1317 | /** |
||
1318 | * Checks if node has attribute |
||
1319 | * @param string|int$attr Negative int to count from end |
||
1320 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1321 | * @param bool $case_sensitive Compare with case sensitivity |
||
1322 | * @return bool |
||
1323 | */ |
||
1324 | function hasAttribute($attr, $compare = 'total', $case_sensitive = false) { |
||
1327 | |||
1328 | /** |
||
1329 | * Gets namespace of attribute(s) |
||
1330 | * @param string|int $attr Negative int to count from end |
||
1331 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1332 | * @param bool $case_sensitive Compare with case sensitivity |
||
1333 | * @return string|array False if not found |
||
1334 | */ |
||
1335 | function getAttributeNS($attr, $compare = 'name', $case_sensitive = false) { |
||
1351 | |||
1352 | /** |
||
1353 | * Sets namespace of attribute(s) |
||
1354 | * @param string|int $attr Negative int to count from end |
||
1355 | * @param string $namespace |
||
1356 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1357 | * @param bool $case_sensitive Compare with case sensitivity |
||
1358 | * @return bool |
||
1359 | */ |
||
1360 | function setAttributeNS($attr, $namespace, $compare = 'name', $case_sensitive = false) { |
||
1377 | |||
1378 | /** |
||
1379 | * Gets value(s) of attribute(s) |
||
1380 | * @param string|int $attr Negative int to count from end |
||
1381 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1382 | * @param bool $case_sensitive Compare with case sensitivity |
||
1383 | * @return string|array |
||
1384 | */ |
||
1385 | 12 | function getAttribute($attr, $compare = 'total', $case_sensitive = false) { |
|
1401 | |||
1402 | /** |
||
1403 | * Sets value(s) of attribute(s) |
||
1404 | * @param string|int $attr Negative int to count from end |
||
1405 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1406 | * @param bool $case_sensitive Compare with case sensitivity |
||
1407 | */ |
||
1408 | 9 | function setAttribute($attr, $val, $compare = 'total', $case_sensitive = false) { |
|
1422 | |||
1423 | /** |
||
1424 | * Add new attribute |
||
1425 | * @param string $attr |
||
1426 | * @param string $val |
||
1427 | */ |
||
1428 | function addAttribute($attr, $val) { |
||
1431 | |||
1432 | /** |
||
1433 | * Delete attribute(s) |
||
1434 | * @param string|int $attr Negative int to count from end |
||
1435 | * @param string $compare Find node using "namespace", "name" or "total" |
||
1436 | * @param bool $case_sensitive Compare with case sensitivity |
||
1437 | */ |
||
1438 | 5 | function deleteAttribute($attr, $compare = 'total', $case_sensitive = false) { |
|
1449 | |||
1450 | /** |
||
1451 | * Determine if node has a certain class |
||
1452 | * @param string $className |
||
1453 | * @return bool |
||
1454 | */ |
||
1455 | 2 | function hasClass($className) { |
|
1458 | |||
1459 | /** |
||
1460 | * Add new class(es) |
||
1461 | * @param string|array $className |
||
1462 | */ |
||
1463 | 4 | function addClass($className) { |
|
1475 | |||
1476 | /** |
||
1477 | * Remove clas(ses) |
||
1478 | * @param string|array $className |
||
1479 | */ |
||
1480 | 2 | function removeClass($className) { |
|
1494 | |||
1495 | /** |
||
1496 | * Finds children using a callback function |
||
1497 | * @param callable $callback Function($node) that returns a bool |
||
1498 | * @param bool|int $recursive Check recursively |
||
1499 | * @param bool $check_self Include this node in search? |
||
1500 | * @return array |
||
1501 | */ |
||
1502 | function getChildrenByCallback($callback, $recursive = true, $check_self = false) { |
||
1527 | |||
1528 | /** |
||
1529 | * Finds children using the {$link match()} function |
||
1530 | * @param $conditions See {$link match()} |
||
1531 | * @param $custom_filters See {$link match()} |
||
1532 | * @param bool|int $recursive Check recursively |
||
1533 | * @param bool $check_self Include this node in search? |
||
1534 | * @return array |
||
1535 | */ |
||
1536 | 37 | function getChildrenByMatch($conditions, $recursive = true, $check_self = false, $custom_filters = array()) { |
|
1561 | |||
1562 | /** |
||
1563 | * Checks if tag matches certain conditions |
||
1564 | * @param array $tags array('tag1', 'tag2') or array(array( |
||
1565 | * 'tag' => 'tag1', |
||
1566 | * 'operator' => 'or'/'and', |
||
1567 | * 'compare' => 'total'/'namespace'/'name', |
||
1568 | * 'case_sensitive' => true)) |
||
1569 | * @return bool |
||
1570 | * @internal Used by selector class |
||
1571 | * @see match() |
||
1572 | * @access private |
||
1573 | */ |
||
1574 | 23 | protected function match_tags($tags) { |
|
1624 | |||
1625 | /** |
||
1626 | * Checks if attributes match certain conditions |
||
1627 | * @param array $attributes array('attr' => 'val') or array(array( |
||
1628 | * 'operator_value' => 'equals'/'='/'contains_regex'/etc |
||
1629 | * 'attribute' => 'attr', |
||
1630 | * 'value' => 'val', |
||
1631 | * 'match' => true, |
||
1632 | * 'operator_result' => 'or'/'and', |
||
1633 | * 'compare' => 'total'/'namespace'/'name', |
||
1634 | * 'case_sensitive' => true)) |
||
1635 | * @return bool |
||
1636 | * @internal Used by selector class |
||
1637 | * @see match() |
||
1638 | * @access private |
||
1639 | */ |
||
1640 | 19 | protected function match_attributes($attributes) { |
|
1752 | |||
1753 | /** |
||
1754 | * Checks if node matches certain filters |
||
1755 | * @param array $tags array(array( |
||
1756 | * 'filter' => 'last-child', |
||
1757 | * 'params' => '123')) |
||
1758 | * @param array $custom_filters Custom map next to {@link $filter_map} |
||
1759 | * @return bool |
||
1760 | * @internal Used by selector class |
||
1761 | * @see match() |
||
1762 | * @access private |
||
1763 | */ |
||
1764 | 3 | protected function match_filters($conditions, $custom_filters = array()) { |
|
1783 | |||
1784 | /** |
||
1785 | * Checks if node matches certain conditions |
||
1786 | * @param array $tags array('tags' => array(tag_conditions), 'attributes' => array(attr_conditions), 'filters' => array(filter_conditions)) |
||
1787 | * @param array $match Should conditions evaluate to true? |
||
1788 | * @param array $custom_filters Custom map next to {@link $filter_map} |
||
1789 | * @return bool |
||
1790 | * @internal Used by selector class |
||
1791 | * @see match_tags(); |
||
1792 | * @see match_attributes(); |
||
1793 | * @see match_filters(); |
||
1794 | * @access private |
||
1795 | */ |
||
1796 | 37 | function match($conditions, $match = true, $custom_filters = array()) { |
|
1827 | |||
1828 | /** |
||
1829 | * Finds children that match a certain attribute |
||
1830 | * @param string $attribute |
||
1831 | * @param string $value |
||
1832 | * @param string $mode Compare mode, "equals", "|=", "contains_regex", etc. |
||
1833 | * @param string $compare "total"/"namespace"/"name" |
||
1834 | * @param bool|int $recursive |
||
1835 | * @return array |
||
1836 | */ |
||
1837 | function getChildrenByAttribute($attribute, $value, $mode = 'equals', $compare = 'total', $recursive = true) { |
||
1859 | |||
1860 | /** |
||
1861 | * Finds children that match a certain tag |
||
1862 | * @param string $tag |
||
1863 | * @param string $compare "total"/"namespace"/"name" |
||
1864 | * @param bool|int $recursive |
||
1865 | * @return array |
||
1866 | */ |
||
1867 | function getChildrenByTag($tag, $compare = 'total', $recursive = true) { |
||
1887 | |||
1888 | /** |
||
1889 | * Finds all children using ID attribute |
||
1890 | * @param string $id |
||
1891 | * @param bool|int $recursive |
||
1892 | * @return array |
||
1893 | */ |
||
1894 | function getChildrenByID($id, $recursive = true) { |
||
1897 | |||
1898 | /** |
||
1899 | * Finds all children using class attribute |
||
1900 | * @param string $class |
||
1901 | * @param bool|int $recursive |
||
1902 | * @return array |
||
1903 | */ |
||
1904 | function getChildrenByClass($class, $recursive = true) { |
||
1907 | |||
1908 | /** |
||
1909 | * Finds all children using name attribute |
||
1910 | * @param string $name |
||
1911 | * @param bool|int $recursive |
||
1912 | * @return array |
||
1913 | */ |
||
1914 | function getChildrenByName($name, $recursive = true) { |
||
1917 | |||
1918 | /** |
||
1919 | * Performs a css query on the node. |
||
1920 | * @param string $query |
||
1921 | * @return IQuery Returns the matching nodes from the query. |
||
1922 | */ |
||
1923 | 36 | public function query($query = '*') { |
|
1928 | |||
1929 | /** |
||
1930 | * Performs css query on node |
||
1931 | * @param string $query |
||
1932 | * @param int|bool $index True to return node instead of array if only 1 match, |
||
1933 | * false to return array, int to return match at index, negative int to count from end |
||
1934 | * @param bool|int $recursive |
||
1935 | * @param bool $check_self Include this node in search or only search child nodes |
||
1936 | * @return DomNode[]|DomNode Returns an array of matching {@link DomNode} objects |
||
1937 | * or a single {@link DomNode} if `$index` is not false. |
||
1938 | */ |
||
1939 | 37 | function select($query = '*', $index = false, $recursive = true, $check_self = false) { |
|
1954 | |||
1955 | /** |
||
1956 | * Checks if node matches css query filter ":root" |
||
1957 | * @return bool |
||
1958 | * @see match() |
||
1959 | * @access private |
||
1960 | */ |
||
1961 | protected function filter_root() { |
||
1964 | |||
1965 | /** |
||
1966 | * Checks if node matches css query filter ":nth-child(n)" |
||
1967 | * @param string $n 1-based index |
||
1968 | * @return bool |
||
1969 | * @see match() |
||
1970 | * @access private |
||
1971 | */ |
||
1972 | protected function filter_nchild($n) { |
||
1975 | |||
1976 | /** |
||
1977 | * Checks if node matches css query filter ":gt(n)" |
||
1978 | * @param string $n 0-based index |
||
1979 | * @return bool |
||
1980 | * @see match() |
||
1981 | * @access private |
||
1982 | */ |
||
1983 | protected function filter_gt($n) { |
||
1986 | |||
1987 | /** |
||
1988 | * Checks if node matches css query filter ":lt(n)" |
||
1989 | * @param string $n 0-based index |
||
1990 | * @return bool |
||
1991 | * @see match() |
||
1992 | * @access private |
||
1993 | */ |
||
1994 | protected function filter_lt($n) { |
||
1997 | |||
1998 | /** |
||
1999 | * Checks if node matches css query filter ":nth-last-child(n)" |
||
2000 | * @param string $n 1-based index |
||
2001 | * @return bool |
||
2002 | * @see match() |
||
2003 | * @access private |
||
2004 | */ |
||
2005 | protected function filter_nlastchild($n) { |
||
2012 | |||
2013 | /** |
||
2014 | * Checks if node matches css query filter ":nth-of-type(n)" |
||
2015 | * @param string $n 1-based index |
||
2016 | * @return bool |
||
2017 | * @see match() |
||
2018 | * @access private |
||
2019 | */ |
||
2020 | protected function filter_ntype($n) { |
||
2023 | |||
2024 | /** |
||
2025 | * Checks if node matches css query filter ":nth-last-of-type(n)" |
||
2026 | * @param string $n 1-based index |
||
2027 | * @return bool |
||
2028 | * @see match() |
||
2029 | * @access private |
||
2030 | */ |
||
2031 | protected function filter_nlastype($n) { |
||
2038 | |||
2039 | /** |
||
2040 | * Checks if node matches css query filter ":odd" |
||
2041 | * @return bool |
||
2042 | * @see match() |
||
2043 | * @access private |
||
2044 | */ |
||
2045 | protected function filter_odd() { |
||
2048 | |||
2049 | /** |
||
2050 | * Checks if node matches css query filter ":even" |
||
2051 | * @return bool |
||
2052 | * @see match() |
||
2053 | * @access private |
||
2054 | */ |
||
2055 | protected function filter_even() { |
||
2058 | |||
2059 | /** |
||
2060 | * Checks if node matches css query filter ":every(n)" |
||
2061 | * @return bool |
||
2062 | * @see match() |
||
2063 | * @access private |
||
2064 | */ |
||
2065 | protected function filter_every($n) { |
||
2068 | |||
2069 | /** |
||
2070 | * Checks if node matches css query filter ":first" |
||
2071 | * @return bool |
||
2072 | * @see match() |
||
2073 | * @access private |
||
2074 | */ |
||
2075 | protected function filter_first() { |
||
2078 | |||
2079 | /** |
||
2080 | * Checks if node matches css query filter ":last" |
||
2081 | * @return bool |
||
2082 | * @see match() |
||
2083 | * @access private |
||
2084 | */ |
||
2085 | protected function filter_last() { |
||
2092 | |||
2093 | /** |
||
2094 | * Checks if node matches css query filter ":first-of-type" |
||
2095 | * @return bool |
||
2096 | * @see match() |
||
2097 | * @access private |
||
2098 | */ |
||
2099 | protected function filter_firsttype() { |
||
2102 | |||
2103 | /** |
||
2104 | * Checks if node matches css query filter ":last-of-type" |
||
2105 | * @return bool |
||
2106 | * @see match() |
||
2107 | * @access private |
||
2108 | */ |
||
2109 | protected function filter_lasttype() { |
||
2116 | |||
2117 | /** |
||
2118 | * Checks if node matches css query filter ":only-child" |
||
2119 | * @return bool |
||
2120 | * @see match() |
||
2121 | * @access private |
||
2122 | */ |
||
2123 | protected function filter_onlychild() { |
||
2130 | |||
2131 | /** |
||
2132 | * Checks if node matches css query filter ":only-of-type" |
||
2133 | * @return bool |
||
2134 | * @see match() |
||
2135 | * @access private |
||
2136 | */ |
||
2137 | protected function filter_onlytype() { |
||
2144 | |||
2145 | /** |
||
2146 | * Checks if node matches css query filter ":empty" |
||
2147 | * @return bool |
||
2148 | * @see match() |
||
2149 | * @access private |
||
2150 | */ |
||
2151 | protected function filter_empty() { |
||
2154 | |||
2155 | /** |
||
2156 | * Checks if node matches css query filter ":not-empty" |
||
2157 | * @return bool |
||
2158 | * @see match() |
||
2159 | * @access private |
||
2160 | */ |
||
2161 | protected function filter_notempty() { |
||
2164 | |||
2165 | /** |
||
2166 | * Checks if node matches css query filter ":has-text" |
||
2167 | * @return bool |
||
2168 | * @see match() |
||
2169 | * @access private |
||
2170 | */ |
||
2171 | protected function filter_hastext() { |
||
2174 | |||
2175 | /** |
||
2176 | * Checks if node matches css query filter ":no-text" |
||
2177 | * @return bool |
||
2178 | * @see match() |
||
2179 | * @access private |
||
2180 | */ |
||
2181 | protected function filter_notext() { |
||
2184 | |||
2185 | /** |
||
2186 | * Checks if node matches css query filter ":lang(s)" |
||
2187 | * @param string $lang |
||
2188 | * @return bool |
||
2189 | * @see match() |
||
2190 | * @access private |
||
2191 | */ |
||
2192 | protected function filter_lang($lang) { |
||
2195 | |||
2196 | /** |
||
2197 | * Checks if node matches css query filter ":contains(s)" |
||
2198 | * @param string $text |
||
2199 | * @return bool |
||
2200 | * @see match() |
||
2201 | * @access private |
||
2202 | */ |
||
2203 | protected function filter_contains($text) { |
||
2206 | |||
2207 | /** |
||
2208 | * Checks if node matches css query filter ":has(s)" |
||
2209 | * @param string $selector |
||
2210 | * @return bool |
||
2211 | * @see match() |
||
2212 | * @access private |
||
2213 | */ |
||
2214 | protected function filter_has($selector) { |
||
2218 | |||
2219 | /** |
||
2220 | * Checks if node matches css query filter ":not(s)" |
||
2221 | * @param string $selector |
||
2222 | * @return bool |
||
2223 | * @see match() |
||
2224 | * @access private |
||
2225 | */ |
||
2226 | protected function filter_not($selector) { |
||
2230 | |||
2231 | /** |
||
2232 | * Checks if node matches css query filter ":element" |
||
2233 | * @return bool |
||
2234 | * @see match() |
||
2235 | * @access private |
||
2236 | */ |
||
2237 | protected function filter_element() { |
||
2240 | |||
2241 | /** |
||
2242 | * Checks if node matches css query filter ":text" |
||
2243 | * @return bool |
||
2244 | * @see match() |
||
2245 | * @access private |
||
2246 | */ |
||
2247 | protected function filter_text() { |
||
2250 | |||
2251 | /** |
||
2252 | * Checks if a node matches css query filter ":checked" |
||
2253 | * @return bool |
||
2254 | * @see match() |
||
2255 | */ |
||
2256 | 1 | protected function filter_checked() { |
|
2262 | |||
2263 | /** |
||
2264 | * Checks if node matches css query filter ":comment" |
||
2265 | * @return bool |
||
2266 | * @see match() |
||
2267 | * @access private |
||
2268 | */ |
||
2269 | protected function filter_comment() { |
||
2272 | |||
2273 | /** |
||
2274 | * Checks if a node matches css query filter ":selected" |
||
2275 | * @return bool |
||
2276 | * @see match() |
||
2277 | */ |
||
2278 | 2 | protected function filter_selected() { |
|
2285 | |||
2286 | 1 | public function after($content) { |
|
2296 | |||
2297 | |||
2298 | /** |
||
2299 | * Create a {@link DomNode} from its string representation. |
||
2300 | * @param string|DomNode $content |
||
2301 | * @return DomNode |
||
2302 | */ |
||
2303 | 2 | protected function createNode($content) { |
|
2307 | |||
2308 | /** |
||
2309 | * Create an array of {@link DomNode} objects from their string representation. |
||
2310 | * @param string|DomNode $content |
||
2311 | * @return DomNode[] |
||
2312 | */ |
||
2313 | 9 | protected function createNodes($content) { |
|
2326 | |||
2327 | 1 | public function append($content) { |
|
2334 | |||
2335 | 9 | public function attr($name, $value = null) { |
|
2342 | |||
2343 | 1 | public function before($content) { |
|
2354 | |||
2355 | public function count() { |
||
2358 | |||
2359 | // public function css($name, $value = null) { |
||
2360 | // |
||
2361 | // } |
||
2362 | |||
2363 | 1 | public function prepend($content = null) { |
|
2374 | |||
2375 | 4 | public function prop($name, $value = null) { |
|
2398 | |||
2399 | 4 | public function remove($selector = null) { |
|
2409 | |||
2410 | 3 | public function removeAttr($name) { |
|
2415 | |||
2416 | 2 | function replaceWith($content) { |
|
2428 | |||
2429 | /** |
||
2430 | * @param type $value |
||
2431 | * @return string|DomNode |
||
2432 | */ |
||
2433 | 2 | public function tagName($value = null) { |
|
2440 | |||
2441 | 2 | public function text($value = null) { |
|
2448 | |||
2449 | 1 | public function toggleClass($classname, $switch = null) { |
|
2462 | |||
2463 | 1 | public function unwrap() { |
|
2467 | |||
2468 | 5 | public function val($value = null) { |
|
2518 | |||
2519 | } |
||
2520 | |||
2855 | ?> |
||
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.