Skip to content

Commit

Permalink
Add stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Dec 8, 2024
1 parent 32bd5cf commit 7b00257
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
25 changes: 23 additions & 2 deletions stubs/dom.stub
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ class DOMDocument extends DOMNode

class DOMNode
{
/** @var DOMNamedNodeMap<DOMAttr>|null */
public readonly ?DOMNamedNodeMap $attributes;
/**
* @readonly
* @var DOMNamedNodeMap<DOMAttr>|null
*/
public $attributes;
}

class DOMElement extends DOMNode
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Analyser/nsrt/DOMLegacyNamedNodeNap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types = 1);

namespace DOMLegacyNamedNodeMap;

use DOMAttr;
use DOMNode;
use DOMNamedNodeMap;
use function PHPStan\Testing\assertType;

class Foo
{
public function checkAttributes(DOMNode $node): void {
assertType('DOMNamedNodeMap<DOMAttr>', $node->attributes);
if ($node->hasAttribute('attr')) {
assertType('DOMAttr', $node->attributes->getNamedItem('attr'));
} else {
assertType('null', $node->attributes->getNamedItem('attr'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7b00257

Please sign in to comment.