1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix ownerDocument type

This commit is contained in:
fluffycondor 2024-01-31 15:39:54 +06:00
parent 04ba9358e3
commit 6aa2ddfe1c
4 changed files with 21 additions and 4 deletions

View File

@ -113,6 +113,7 @@ return [
'formatOutput' => 'bool',
'implementation' => 'DOMImplementation',
'lastElementChild' => 'DOMElement|null',
'ownerDocument' => 'null',
'preserveWhiteSpace' => 'bool',
'recover' => 'bool',
'resolveExternals' => 'bool',
@ -173,7 +174,7 @@ return [
'nodeName' => 'string',
'nodeType' => 'int',
'nodeValue' => 'string|null',
'ownerDocument' => 'DOMDocument|null',
'ownerDocument' => 'DOMDocument',
'parentNode' => 'DOMNode|null',
'prefix' => 'string',
'previousSibling' => 'DOMNode|null',

View File

@ -154,7 +154,7 @@ class DOMNode
*/
public ?DOMNamedNodeMap $attributes;
/** @readonly */
public ?DOMDocument $ownerDocument;
public DOMDocument $ownerDocument;
/** @readonly */
public ?string $namespaceURI;
public string $prefix;
@ -242,7 +242,7 @@ class DOMNameSpaceNode
/** @readonly */
public ?string $namespaceURI;
/** @readonly */
public ?DOMDocument $ownerDocument;
public DOMDocument $ownerDocument;
/** @readonly */
public ?DOMNode $parentNode;
}
@ -281,6 +281,8 @@ class DOMDocument extends DOMNode implements DOMParentNode
public DOMImplementation $implementation;
/** @readonly */
public ?DOMElement $documentElement;
/** @readonly */
public null $ownerDocument;
/**
* @deprecated

View File

@ -424,6 +424,20 @@ class CoreStubsTest extends TestCase
$globBrace = glob('abc', GLOB_BRACE);
PHP,
];
yield "ownerDocument's type is non-nullable DOMDocument and always null on DOMDocument itself" => [
'code' => '<?php
$a = (new DOMDocument())->ownerDocument;
$b = (new DOMNode())->ownerDocument;
$c = (new DOMElement("p"))->ownerDocument;
$d = (new DOMNameSpaceNode())->ownerDocument;
',
'assertions' => [
'$a===' => 'null',
'$b===' => 'DOMDocument',
'$c===' => 'DOMDocument',
'$d===' => 'DOMDocument',
],
];
}
public function providerInvalidCodeParse(): iterable

View File

@ -718,7 +718,7 @@ class PropertyTypeTest extends TestCase
$a = new DOMElement("foo");
$owner = $a->ownerDocument;',
'assertions' => [
'$owner' => 'DOMDocument|null',
'$owner' => 'DOMDocument',
],
],
'propertyMapHydration' => [