Skip to content

Commit

Permalink
Fix issues by copying code from Ondrej
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Dec 8, 2024
1 parent a261621 commit ca3e5d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
12 changes: 9 additions & 3 deletions stubs/dom.stub
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class DOMNode

/**
* @phpstan-assert-if-true DOMNamedNodeMap<DOMAttr> $this->attributes
* @phpstan-assert-if-false null $this->attributes
*/
public function hasAttributes(): bool {}
}
Expand All @@ -48,6 +47,12 @@ class DOMElement extends DOMNode
/** @var DOMDocument */
public $ownerDocument;

/**
* @readonly
* @var DOMNamedNodeMap<DOMAttr>|null
*/
public $attributes;

/**
* @param string $name
* @return DOMNodeList<DOMElement>
Expand All @@ -64,11 +69,12 @@ class DOMElement extends DOMNode
/**
* @template-covariant T of string
* @param T $qualifiedName
* @phpstan-assert-if-true DOMAttr|DOMNameSpaceNode $this->getAttributeNode($qualifiedName)
* @phpstan-assert-if-true =DOMAttr $this->getAttributeNode($qualifiedName)

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug10449 ../../bin/phpstan analyze git apply patch.diff rm phpstan...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / E2E tests (bin/phpstan analyse e2e/only-files-not-analysed-trait/src -c e2e/only-files-not-analys...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug10449b ../../bin/phpstan analyze git apply patch.diff rm phpsta...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-1 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-9622 echo -n > phpstan-baseline.neon ../../bin/phpstan -vvv pa...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-2 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-11857 composer install ../../bin/phpstan )

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-5 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-3 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / E2E tests (cd e2e/baseline-uninit-prop-trait ../../bin/phpstan analyse --debug --configuration te...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-9622-trait echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Compiler Tests

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-4 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-7 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-6 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-8 composer install ../../bin/phpstan echo -en '\n' >>...

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Integration tests (windows-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 132 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4

Check failure on line 72 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

PHPDoc tag @phpstan-assert-if-true has invalid value (=DOMAttr $this->getAttributeNode($qualifiedName)): Unexpected token "$qualifiedName", expected ')' at offset 129 on line 4
* @phpstan-assert-if-true =DOMNamedNodeMap<DOMAttr> $this->attributes
*/
public function hasAttribute(string $qualifiedName): bool {}

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug10449 ../../bin/phpstan analyze git apply patch.diff rm phpstan...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / E2E tests (bin/phpstan analyse e2e/only-files-not-analysed-trait/src -c e2e/only-files-not-analys...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug10449b ../../bin/phpstan analyze git apply patch.diff rm phpsta...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-1 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-9622 echo -n > phpstan-baseline.neon ../../bin/phpstan -vvv pa...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-2 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-11857 composer install ../../bin/phpstan )

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-5 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-3 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / E2E tests (cd e2e/baseline-uninit-prop-trait ../../bin/phpstan analyse --debug --configuration te...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/bug-9622-trait echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Compiler Tests

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-4 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-7 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-6 echo -n > phpstan-baseline.neon ../../bin/phpstan -...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Result cache E2E tests (cd e2e/result-cache-8 composer install ../../bin/phpstan echo -en '\n' >>...

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / Integration tests (windows-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

Check failure on line 75 in stubs/dom.stub

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Variance annotation is only allowed for type parameters of classes and interfaces, but occurs in template type T in in method DOMElement::hasAttribute().

public function getAttributeNode(string $qualifiedName): DOMAttr|DOMNameSpaceNode|false {}
public function getAttributeNode(string $qualifiedName): DOMAttr|false {}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function basic_node(DOMNode $node): void {

public function element_node(DOMElement $element): void
{
assertType('DOMNamedNodeMap<DOMAttr>|null', $element->attributes);
if ($element->hasAttribute('class')) {
assertType('DOMNamedNodeMap<DOMAttr>', $element->attributes);
$attribute = $element->getAttributeNode('class');
Expand All @@ -34,6 +35,7 @@ public function element_node(DOMElement $element): void

public function element_node_attribute_fetch_via_attributes_property(DOMElement $element): void
{
assertType('DOMNamedNodeMap<DOMAttr>|null', $element->attributes);
if ($element->hasAttribute('class')) {
assertType('DOMNamedNodeMap<DOMAttr>', $element->attributes);
$attribute = $element->attributes->getNamedItem('class');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
<?php

use function PHPStan\Testing\assertType;
namespace DOMNodeStubsAccessProperties;

function basic_node(\DOMNode $node): void {
if ($node->hasAttributes()) {
assertType(DOMNamedNodeMap::class . '<' . DOMAttr::class . '>', $node->attributes);
} else {
assertType('null', $node->attributes);
}
var_dump($node->attributes);
}

function element_node(\DOMElement $element): void
{
if ($element->hasAttribute('class')) {
assertType(DOMNamedNodeMap::class . '<' . DOMAttr::class . '>', $element->attributes);
$attribute = $element->getAttributeNode('class');
assertType(DOMAttr::class, $attribute);
assertType('string', $attribute->value);
} else {
assertType('DOMNamedNodeMap::class . '<' . DOMAttr::class . '>'|null', $element->attributes);
echo $attribute->value;
}
}

function element_node_attribute_fetch_via_attributes_property(\DOMElement $element): void
{
if ($element->hasAttribute('class')) {
assertType(DOMNamedNodeMap::class . '<' . DOMAttr::class . '>', $element->attributes);
$attribute = $element->attributes->getNamedItem('class');
if ($attribute === null) {
return;
}
assertType(DOMAttr::class, $attribute);
assertType('string', $attribute->value);
} else {
assertType('DOMNamedNodeMap::class . '<' . DOMAttr::class . '>'|null', $element->attributes);
$attribute = $element->attributes->getNamedItem('class');
if ($attribute === null) {
return;
}
echo $attribute->value;
}

0 comments on commit ca3e5d2

Please sign in to comment.