@@ -80,7 +80,7 @@ public function getNodesByName(string $name, ?string $checkInstance = null): arr
8080 $ nodes = array ();
8181 if ($ this ->domDocument ->getElementsByTagName ($ name )->length > 0 ) {
8282 foreach ($ this ->domDocument ->getElementsByTagName ($ name ) as $ node ) {
83- if ($ checkInstance === null || $ node instanceof $ checkInstance ) {
83+ if (is_null ( $ checkInstance) || $ node instanceof $ checkInstance ) {
8484 $ nodes [] = $ this ->getHandler ($ node , count ($ nodes ));
8585 }
8686 }
@@ -91,14 +91,15 @@ public function getNodesByName(string $name, ?string $checkInstance = null): arr
9191
9292 public function getElementsByName (string $ name ): array
9393 {
94- return $ this ->getNodesByName ($ name , ' DOMElement ' );
94+ return $ this ->getNodesByName ($ name , DOMElement::class );
9595 }
9696
9797 public function getElementsByNameAndAttributes (string $ name , array $ attributes , ?DOMNode $ node = null ): array
9898 {
9999 $ matchingElements = $ this ->getElementsByName ($ name );
100100 if ((!empty ($ attributes ) || $ node instanceof DOMNode) && !empty ($ matchingElements )) {
101101 $ nodes = $ this ->searchTagsByXpath ($ name , $ attributes , $ node );
102+
102103 if (!empty ($ nodes )) {
103104 $ matchingElements = $ this ->getElementsHandlers ($ nodes );
104105 }
@@ -125,7 +126,7 @@ public function getElementsHandlers(DOMNodeList $nodeList): array
125126
126127 public function searchTagsByXpath (string $ name , array $ attributes , ?DOMNode $ node = null ): DOMNodeList
127128 {
128- $ xpath = new DOMXPath ($ this ->domDocument );
129+ $ xpath = new DOMXPath ($ node ? $ node -> ownerDocument : $ this ->domDocument );
129130 $ xQuery = sprintf ("%s//*[local-name()='%s'] " , $ node instanceof DOMNode ? '. ' : '' , $ name );
130131 foreach ($ attributes as $ attributeName => $ attributeValue ) {
131132 if (strpos ($ attributeValue , '* ' ) !== false ) {
@@ -142,6 +143,6 @@ public function getElementByNameAndAttributes(string $name, array $attributes):
142143 {
143144 $ elements = $ this ->getElementsByNameAndAttributes ($ name , $ attributes );
144145
145- return empty ( $ elements ) ? null : array_shift ($ elements );
146+ return array_shift ($ elements );
146147 }
147148}
0 commit comments