Narrow DOMDocument::createElement() return type and throw type for valid constant names#5192
Narrow DOMDocument::createElement() return type and throw type for valid constant names#5192janedbal wants to merge 5 commits intophpstan:2.1.xfrom
Conversation
|
You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x. |
|
|
||
| public function isMethodSupported(MethodReflection $methodReflection): bool | ||
| { | ||
| return extension_loaded('dom') && $methodReflection->getName() === 'createElement'; |
There was a problem hiding this comment.
I am not sure whether this kind of optional runtime dependency is a good thing to have.
would it make sense to hard-code a list of valid elements instead?
There was a problem hiding this comment.
This logic was basically copied from SimpleXMLElementXpathMethodReturnTypeExtension, so I just followed that one.
|
This pull request has been marked as ready for review. |
Removes the implicit DOMException throw point when all constant string arguments are valid XML element names.
tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRuleTest.php
Outdated
Show resolved
Hide resolved
| 122, | ||
| ]; | ||
| } | ||
| $errors[] = [ |
There was a problem hiding this comment.
I'm sorry I wasn't clear.
I wanted to split the data file, but it can still be in this TestCase by writing a new test here
public function testBug13792(): void
{
$this->analyse([__DIR__ . '/data/bug-13792.php'], [
[
'Method Bug13792\Foo::dynamicName() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
20,
],
[
'Method Bug13792\Foo::invalidConstantName() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
25,
],
[
'Method Bug13792\Foo::unions() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
35,
],
]);
}
Fixes phpstan/phpstan#13792