Skip to content

Commit

Permalink
Merge pull request #10619 from fluffycondor/fix-ownerdocument-null
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Jan 31, 2024
2 parents 04ba935 + 6aa2ddf commit abe7ae8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dictionaries/PropertyMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
'formatOutput' => 'bool',
'implementation' => 'DOMImplementation',
'lastElementChild' => 'DOMElement|null',
'ownerDocument' => 'null',
'preserveWhiteSpace' => 'bool',
'recover' => 'bool',
'resolveExternals' => 'bool',
Expand Down Expand Up @@ -173,7 +174,7 @@
'nodeName' => 'string',
'nodeType' => 'int',
'nodeValue' => 'string|null',
'ownerDocument' => 'DOMDocument|null',
'ownerDocument' => 'DOMDocument',
'parentNode' => 'DOMNode|null',
'prefix' => 'string',
'previousSibling' => 'DOMNode|null',
Expand Down
6 changes: 4 additions & 2 deletions stubs/extensions/dom.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class DOMNode
*/
public ?DOMNamedNodeMap $attributes;
/** @readonly */
public ?DOMDocument $ownerDocument;
public DOMDocument $ownerDocument;
/** @readonly */
public ?string $namespaceURI;
public string $prefix;
Expand Down Expand Up @@ -242,7 +242,7 @@ class DOMNameSpaceNode
/** @readonly */
public ?string $namespaceURI;
/** @readonly */
public ?DOMDocument $ownerDocument;
public DOMDocument $ownerDocument;
/** @readonly */
public ?DOMNode $parentNode;
}
Expand Down Expand Up @@ -281,6 +281,8 @@ class DOMDocument extends DOMNode implements DOMParentNode
public DOMImplementation $implementation;
/** @readonly */
public ?DOMElement $documentElement;
/** @readonly */
public null $ownerDocument;

/**
* @deprecated
Expand Down
14 changes: 14 additions & 0 deletions tests/CoreStubsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,20 @@ function takesList(array $list): void {}
$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
Expand Down
2 changes: 1 addition & 1 deletion tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ class Foo {
$a = new DOMElement("foo");
$owner = $a->ownerDocument;',
'assertions' => [
'$owner' => 'DOMDocument|null',
'$owner' => 'DOMDocument',
],
],
'propertyMapHydration' => [
Expand Down

0 comments on commit abe7ae8

Please sign in to comment.