From 3268164d92cbd6fdf4a9b00a4ad35c97563af81e Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Wed, 31 Jan 2024 17:23:06 +0600 Subject: [PATCH] Encourage using DOMDocument factory methods to prevent objects broken state --- stubs/extensions/dom.phpstub | 26 ++++++++++++++++++++++++++ tests/CoreStubsTest.php | 1 + 2 files changed, 27 insertions(+) diff --git a/stubs/extensions/dom.phpstub b/stubs/extensions/dom.phpstub index b240a8d143d..64959ee0fa7 100644 --- a/stubs/extensions/dom.phpstub +++ b/stubs/extensions/dom.phpstub @@ -256,6 +256,9 @@ class DOMDocumentFragment extends DOMNode implements DOMParentNode /** @readonly */ public int $childElementCount; + /** + * @psalm-internal DOMDocument::createDocumentFragment + */ public function __construct() {} public function appendXML(string $data): bool {} @@ -729,6 +732,10 @@ class DOMAttr extends DOMNode */ public string $localName; + /** + * @psalm-internal DOMDocument::createAttribute + * @psalm-internal DOMDocument::createAttributeNS + */ public function __construct(string $name, string $value = '') {} public function isId(): bool {} @@ -765,6 +772,10 @@ class DOMElement extends DOMNode implements DOMParentNode, DOMChildNode */ public string $localName; + /** + * @psalm-internal DOMDocument::createElement + * @psalm-internal DOMDocument::createElementNS + */ public function __construct(string $qualifiedName, ?string $value = null, string $namespace = '') {} public function getAttribute(string $qualifiedName): string {} @@ -874,6 +885,9 @@ class DOMText extends DOMCharacterData /** @readonly */ public string $wholeText; + /** + * @psalm-internal DOMDocument::createTextNode + */ public function __construct(string $data = '') {} public function isWhitespaceInElementContent(): bool {} @@ -892,11 +906,17 @@ class DOMText extends DOMCharacterData class DOMComment extends DOMCharacterData { + /** + * @psalm-internal DOMDocument::createComment + */ public function __construct(string $data = '') {} } class DOMCdataSection extends DOMText { + /** + * @psalm-internal DOMDocument::createCDATASection + */ public function __construct(string $data) {} } @@ -954,6 +974,9 @@ class DOMEntity extends DOMNode class DOMEntityReference extends DOMNode { + /** + * @psalm-internal DOMDocument::createEntityReference + */ public function __construct(string $name) {} } @@ -963,6 +986,9 @@ class DOMProcessingInstruction extends DOMNode public string $target; public string $data; + /** + * @psalm-internal DOMDocument::createProcessingInstruction + */ public function __construct(string $name, string $value = '') {} } diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index 142be4a3e8a..529ffaddbd1 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -437,6 +437,7 @@ function takesList(array $list): void {} '$c===' => 'DOMDocument', '$d===' => 'DOMDocument', ], + 'ignored_issues' => ['InternalMethod'], ]; }