Skip to content

Commit

Permalink
Non-static method DOMDocument::loadHTML() can be called statically
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Dec 4, 2022
1 parent 0f1bfb5 commit 66dc2ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Rules/Methods/StaticMethodCallCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Rules\Methods;

use DOMDocument;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PHPStan\Analyser\NullsafeOperatorHelper;
Expand Down Expand Up @@ -224,6 +225,11 @@ public function check(
&& !$scope->getClassReflection()->isSubclassOf($classType->getClassName())
)
) {
// per php-src docs, this method can be called statically, even if declared non-static
if (strtolower($method->getName()) === 'loadhtml' && $method->getDeclaringClass()->getName() === DOMDocument::class) {
return [[], null];
}

return [
array_merge($errors, [
RuleErrorBuilder::message(sprintf(
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Methods/data/call-static-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,11 @@ public function doBar()
}

}

class Bug2759 {
public function sayHello(string $html): void
{
$dom = \DOMDocument::loadHTML($html, LIBXML_NOWARNING | LIBXML_NONET | LIBXML_NOERROR);
}
}

0 comments on commit 66dc2ad

Please sign in to comment.