Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encourage using DOMDocument factory methods to prevent objects broken state #10620

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions stubs/extensions/dom.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand All @@ -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) {}
}

Expand Down Expand Up @@ -954,6 +974,9 @@ class DOMEntity extends DOMNode

class DOMEntityReference extends DOMNode
{
/**
* @psalm-internal DOMDocument::createEntityReference
*/
public function __construct(string $name) {}
}

Expand All @@ -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 = '') {}
}

Expand Down
1 change: 1 addition & 0 deletions tests/CoreStubsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ function takesList(array $list): void {}
'$c===' => 'DOMDocument',
'$d===' => 'DOMDocument',
],
'ignored_issues' => ['InternalMethod'],
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ class Foo {
'assertions' => [
'$owner' => 'DOMDocument',
],
'ignored_issues' => ['InternalMethod'],
],
'propertyMapHydration' => [
'code' => '<?php
Expand Down