From 7b002571478fee611eee948c61d281beb8241ef3 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 8 Dec 2024 14:29:11 +0000 Subject: [PATCH] Add stuff --- stubs/dom.stub | 25 +++++++++++++++++-- .../Analyser/nsrt/DOMLegacyNamedNodeNap.php | 22 ++++++++++++++++ .../data/dom-legacy-ext-template-nodes.php | 4 +-- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php diff --git a/stubs/dom.stub b/stubs/dom.stub index ae1b31cbfd..3ab8f15c41 100644 --- a/stubs/dom.stub +++ b/stubs/dom.stub @@ -29,8 +29,11 @@ class DOMDocument extends DOMNode class DOMNode { - /** @var DOMNamedNodeMap|null */ - public readonly ?DOMNamedNodeMap $attributes; + /** + * @readonly + * @var DOMNamedNodeMap|null + */ + public $attributes; } class DOMElement extends DOMNode @@ -150,6 +153,24 @@ class DOMProcessingInstruction extends DOMNode class DOMNamedNodeMap implements Traversable, IteratorAggregate, Countable { + /** + * @return (TNode | null) + */ + public function getNamedItem(string $qualifiedName) + { + } + /** + * @return (TNode | null) + */ + public function getNamedItemNS(?string $namespace, string $localName) + { + } + /** + * @return (TNode | null) + */ + public function item(int $index) + { + } } class DOMText extends DOMCharacterData diff --git a/tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php b/tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php new file mode 100644 index 0000000000..542feeaf59 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php @@ -0,0 +1,22 @@ +', $node->attributes); + if ($node->hasAttribute('attr')) { + assertType('DOMAttr', $node->attributes->getNamedItem('attr')); + } else { + assertType('null', $node->attributes->getNamedItem('attr')); + } + } +} diff --git a/tests/PHPStan/Rules/Properties/data/dom-legacy-ext-template-nodes.php b/tests/PHPStan/Rules/Properties/data/dom-legacy-ext-template-nodes.php index ce722cc246..44f5e882f0 100644 --- a/tests/PHPStan/Rules/Properties/data/dom-legacy-ext-template-nodes.php +++ b/tests/PHPStan/Rules/Properties/data/dom-legacy-ext-template-nodes.php @@ -2,11 +2,11 @@ use function PHPStan\Testing\assertType; -function (\DOMNode $node): void { +function basic_node(\DOMNode $node): void { assertType(DOMNamedNodeMap::class . '<' . DOMAttr::class . '>', $node->attributes); }; -function parse(\DOMElement $node): void +function element_node(\DOMElement $node): void { assertType(DOMNamedNodeMap::class . '<' . DOMAttr::class . '>', $node->attributes); $attribute = $node->attributes->getNamedItem('class');