Skip to content

Commit

Permalink
Encourage using DOMDocument factory methods to prevent objects broken…
Browse files Browse the repository at this point in the history
… state
  • Loading branch information
fluffycondor committed Jan 31, 2024
1 parent abe7ae8 commit 7cc526d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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

0 comments on commit 7cc526d

Please sign in to comment.