diff --git a/stubs/dom.stub b/stubs/dom.stub index df03926915..074bdd5102 100644 --- a/stubs/dom.stub +++ b/stubs/dom.stub @@ -36,7 +36,7 @@ class DOMNode public $attributes; /** - * @phpstan-assert-if-true !null $this->attributes + * @phpstan-assert-if-true =DOMNamedNodeMap $this->attributes * @return bool */ public function hasAttributes() {} @@ -46,6 +46,9 @@ class DOMNode class DOMElement extends DOMNode { + /** @var DOMNamedNodeMap */ + public $attributes; + /** @var DOMDocument */ public $ownerDocument; diff --git a/tests/PHPStan/Analyser/nsrt/bug-13076.php b/tests/PHPStan/Analyser/nsrt/bug-13076.php new file mode 100644 index 0000000000..dc6d25a8b6 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13076.php @@ -0,0 +1,26 @@ +hasAttributes()) { + assertType('DOMNamedNodeMap', $node->attributes); + } else { + assertType('DOMNamedNodeMap|null', $node->attributes); + } + } + + public function testElement(\DOMElement $node): void + { + if ($node->hasAttributes()) { + assertType('DOMNamedNodeMap', $node->attributes); + } else { + assertType('DOMNamedNodeMap', $node->attributes); + } + } +}