diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 439d0045..00ef5d23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: [push] jobs: composer: runs-on: ubuntu-latest + strategy: + matrix: + php: [ 8.1, 8.2 ] steps: - uses: actions/checkout@v3 @@ -18,7 +21,7 @@ jobs: - name: Composer install uses: php-actions/composer@v6 with: - php_version: 8.1 + php_version: ${{ matrix.php }} - name: Archive build run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./ @@ -32,6 +35,9 @@ jobs: phpunit: runs-on: ubuntu-latest needs: [ composer ] + strategy: + matrix: + php: [ 8.1, 8.2 ] outputs: coverage: ${{ steps.store-coverage.outputs.coverage_text }} @@ -50,7 +56,7 @@ jobs: env: XDEBUG_MODE: cover with: - php_version: 8.1 + php_version: ${{ matrix.php }} php_extensions: xdebug configuration: test/phpunit/phpunit.xml bootstrap: vendor/autoload.php @@ -84,6 +90,9 @@ jobs: phpstan: runs-on: ubuntu-latest needs: [ composer ] + strategy: + matrix: + php: [ 8.1, 8.2 ] steps: - uses: actions/download-artifact@v3 @@ -97,9 +106,8 @@ jobs: - name: PHP Static Analysis uses: php-actions/phpstan@v3 with: - php_version: 8.1 + php_version: ${{ matrix.php }} path: src/ - level: 4 remove_old_artifacts: runs-on: ubuntu-latest diff --git a/src/ChildNode.php b/src/ChildNode.php index 52e8d6c6..abe296a9 100644 --- a/src/ChildNode.php +++ b/src/ChildNode.php @@ -44,7 +44,7 @@ public function remove():void { * @link https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/before */ public function before(...$nodes):void { - $parent = $this->parentElement; + $parent = $this->parentNode; if(!$parent) { return; } @@ -67,7 +67,7 @@ public function before(...$nodes):void { * @link https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/after */ public function after(...$nodes):void { - $parent = $this->parentElement; + $parent = $this->parentNode; $nextSibling = $this->nextSibling; if(!$parent) { return; @@ -90,7 +90,7 @@ public function after(...$nodes):void { * @link https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith */ public function replaceWith(...$nodes):void { - $parent = $this->parentElement; + $parent = $this->parentNode; if(!$parent) { return; } diff --git a/src/HTMLDocument.php b/src/HTMLDocument.php index ffb0d2f6..f11049e1 100644 --- a/src/HTMLDocument.php +++ b/src/HTMLDocument.php @@ -61,7 +61,10 @@ public function __construct( } if($nonElementChildNodes) { - $this->documentElement->prepend(...$nonElementChildNodes); + call_user_func( + $this->documentElement->prepend(...), + ...$nonElementChildNodes, + ); } } diff --git a/src/ParentNode.php b/src/ParentNode.php index d3580e0d..70aa3e15 100644 --- a/src/ParentNode.php +++ b/src/ParentNode.php @@ -257,8 +257,6 @@ public function getElementsByTagName(string $qualifiedName):HTMLCollection { /** * The removeChild() method of the Node interface removes a child node * from the DOM and returns the removed node. - * - * @param Node|Element|Text|Comment $child */ public function removeChild(Node|Element|Text|Comment|DOMNode|ProcessingInstruction $child):Node|Element|Text|Comment|CdataSection|ProcessingInstruction { try { diff --git a/src/RegisteredNodeClass.php b/src/RegisteredNodeClass.php index b778ab37..8c5634f0 100644 --- a/src/RegisteredNodeClass.php +++ b/src/RegisteredNodeClass.php @@ -49,15 +49,15 @@ public function isEqualNode(Node|Element|Document|DocumentType|Attr|ProcessingIn } if($this instanceof Element - && $otherNode instanceof Element) { + && $otherNode instanceof Element) { $similar = $this->namespaceURI === $otherNode->namespaceURI && $this->localName === $otherNode->localName - && $this->attributes->length === $otherNode->attributes->length; + && count($this->attributes) === count($otherNode->attributes); if(!$similar) { return false; } - for($i = 0, $len = $this->attributes->length; $i < $len; $i++) { + for($i = 0, $len = count($this->attributes); $i < $len; $i++) { $attr = $this->attributes->item($i); $otherAttr = $otherNode->attributes->item($i); if(!$attr->isEqualNode($otherAttr)) { @@ -136,6 +136,7 @@ public function compareDocumentPosition(DOMNode|Node|Element $otherNode):int { $unionPath = "$thisNodePath | $otherNodePath"; $xpathResult = $this->ownerDocument->evaluate($unionPath); + /** @var Node|Element|Document|DocumentType|Attr|ProcessingInstruction|DOMNode $node */ foreach($xpathResult as $node) { if($node === $this) { $bits |= Node::DOCUMENT_POSITION_FOLLOWING; @@ -165,7 +166,7 @@ public function compareDocumentPosition(DOMNode|Node|Element $otherNode):int { * @return bool * @link https://developer.mozilla.org/en-US/docs/Web/API/Node/contains */ - public function contains(Node|Element $otherNode):bool { + public function contains(Node|Element|Text|ProcessingInstruction|DocumentType|DocumentFragment|Document|Comment|CdataSection|Attr $otherNode):bool { $context = $otherNode; while($context = $context->parentNode) { diff --git a/src/Traversal.php b/src/Traversal.php index 8dcc1269..abbecf70 100644 --- a/src/Traversal.php +++ b/src/Traversal.php @@ -102,7 +102,9 @@ public function parentNode():null|Node|Element|Text|Attr|ProcessingInstruction|C /** @var Element $node */ $node = $node->parentNode; + /** @phpstan-ignore-next-line */ if($node && $this->filter->acceptNode($node) === NodeFilter::FILTER_ACCEPT) { + /** @phpstan-ignore-next-line */ $this->pCurrentNode = $this->hintNullableNodeType($node); return $this->pCurrentNode; } @@ -182,14 +184,17 @@ public function previousNode():null|Node|Element|Text|Attr|ProcessingInstruction while(!is_null($sibling)) { /** @var null|Node|Element|Text|Attr|ProcessingInstruction|Comment|Document|DocumentType|DocumentFragment $node */ $node = $sibling; + /** @phpstan-ignore-next-line */ $result = $this->filter->acceptNode($node); while($result !== NodeFilter::FILTER_REJECT - && !is_null($node->lastChild)) { + && !is_null($node->lastChild)) { $node = $node->lastChild; + /** @phpstan-ignore-next-line */ $result = $this->filter->acceptNode($node); } if($result === NodeFilter::FILTER_ACCEPT) { + /** @phpstan-ignore-next-line */ $this->pCurrentNode = $this->hintNullableNodeType($node); return $this->pCurrentNode; } @@ -203,7 +208,10 @@ public function previousNode():null|Node|Element|Text|Attr|ProcessingInstruction /** @var null|Element|Node|Text $node */ $node = $node->parentNode; + + /** @phpstan-ignore-next-line */ if($this->filter->acceptNode($node) === NodeFilter::FILTER_ACCEPT) { + /** @phpstan-ignore-next-line */ $this->pCurrentNode = $this->hintNullableNodeType($node); return $this->pCurrentNode; } @@ -388,6 +396,7 @@ private function nextSkippingChildren( break; } if(!is_null($node->nextSibling)) { + /** @phpstan-ignore-next-line */ return $this->hintNodeType($node->nextSibling); } }