Skip to content

Commit c6b3f38

Browse files
Use DOMNodeList with array syntax
This is not only more readable, but even faster [1] (though I doubt this code is a bottleneck anywhere either way). [1]: https://3v4l.org/NGEKe
1 parent 7cc0a7c commit c6b3f38

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Component.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ private function getRootNode( DOMDocument $document ) {
9999
throw new Exception( 'Empty document' );
100100
}
101101

102-
$rootNodes = $document->documentElement->childNodes->item( 0 )->childNodes;
102+
$rootNodes = $document->documentElement->childNodes[0]->childNodes;
103103

104104
if ( $rootNodes->length > 1 ) {
105105
throw new Exception( 'Template should have only one root node' );
106106
}
107107

108-
return $rootNodes->item( 0 );
108+
return $rootNodes[0];
109109
}
110110

111111
/**
@@ -250,7 +250,7 @@ private function handleFor( DOMNode $node, array $data ) {
250250

251251
private function appendHTML( DOMNode $parent, $source ) {
252252
$tmpDoc = $this->parseHtml( $source );
253-
foreach ( $tmpDoc->getElementsByTagName( 'body' )->item( 0 )->childNodes as $node ) {
253+
foreach ( $tmpDoc->getElementsByTagName( 'body' )[0]->childNodes as $node ) {
254254
$node = $parent->ownerDocument->importNode( $node, true );
255255
$parent->appendChild( $node );
256256
}

0 commit comments

Comments
 (0)