@@ -58,6 +58,9 @@ abstract class AbstractNode {
5858 */
5959 protected $ encode ;
6060
61+ /**
62+ * Creates a unique spl hash for this node.
63+ */
6164 public function __construct ()
6265 {
6366 $ this ->id = spl_object_hash ($ this );
@@ -179,7 +182,9 @@ public function propagateEncoding(Encode $encode)
179182 // check children
180183 foreach ($ this ->children as $ id => $ child )
181184 {
182- $ child ['node ' ]->propagateEncoding ($ encode );
185+ /** @var AbstractNode $node */
186+ $ node = $ child ['node ' ];
187+ $ node ->propagateEncoding ($ encode );
183188 }
184189 }
185190
@@ -378,7 +383,7 @@ public function isChild ($id)
378383 }
379384
380385 /**
381- * Checks if the given node id is a decendant of the
386+ * Checks if the given node id is a descendant of the
382387 * current node.
383388 *
384389 * @param int $id
@@ -393,12 +398,12 @@ public function isDescendant($id)
393398
394399 foreach ($ this ->children as $ childId => $ child )
395400 {
396- if ($ child ['node ' ]->hasChildren ())
401+ /** @var AbstractNode $node */
402+ $ node = $ child ['node ' ];
403+ if ($ node ->hasChildren () &&
404+ $ node ->isDescendant ($ id ))
397405 {
398- if ($ child ['node ' ]->isDescendant ($ id ))
399- {
400- return true ;
401- }
406+ return true ;
402407 }
403408 }
404409
@@ -591,7 +596,7 @@ public function ancestorByTag($tag)
591596 *
592597 * @param string $selector
593598 * @param int $nth
594- * @return array
599+ * @return array|AbstractNode
595600 */
596601 public function find ($ selector , $ nth = null )
597602 {
@@ -619,10 +624,10 @@ public function find($selector, $nth = null)
619624 *
620625 * Far future enhancement
621626 * Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width
622- * Note that in this case, the class or id will have the img subselector for it to apply to the image.
627+ * Note that in this case, the class or id will have the img sub-selector for it to apply to the image.
623628 *
624629 * ridiculously far future development
625- * If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page.
630+ * If the class or id is specified in a SEPARATE css file that's not on the page, go get it and do what we were just doing for the ones on the page.
626631 *
627632 * @author John Schlick
628633 * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out.
@@ -651,9 +656,9 @@ public function get_display_size()
651656 // Now look for an inline style.
652657 if ( ! is_null ($ this ->tag ->getAttribute ('style ' )))
653658 {
654- // Thanks to user gnarf from stackoverflow for this regular expression.
659+ // Thanks to user ' gnarf' from stackoverflow for this regular expression.
655660 $ attributes = [];
656- preg_match_all ("/([\w-]+)\s*:\s*([^;]+)\s*;?/ " , $ this ->tag ->getAttribute [ 'style ' ] , $ matches , PREG_SET_ORDER );
661+ preg_match_all ("/([\w-]+)\s*:\s*([^;]+)\s*;?/ " , $ this ->tag ->getAttribute ( 'style ' ) , $ matches , PREG_SET_ORDER );
657662 foreach ($ matches as $ match )
658663 {
659664 $ attributes [$ match [1 ]] = $ match [2 ];
0 commit comments