Skip to content

Commit

Permalink
Native method reflection - look in stubs first, then into native runt…
Browse files Browse the repository at this point in the history
…ime PHP reflection
  • Loading branch information
ondrejmirtes committed Jun 16, 2020
1 parent 43ee94a commit 09f0beb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ private function createMethod(
$stubPhpDocString = null;
$variants = [];
$reflectionMethod = null;
if (class_exists($classReflection->getName(), false)) {
if ($classReflection->getNativeReflection()->hasMethod($methodReflection->getName())) {
$reflectionMethod = $classReflection->getNativeReflection()->getMethod($methodReflection->getName());
} elseif (class_exists($classReflection->getName(), false)) {
$reflectionClass = new \ReflectionClass($classReflection->getName());
if ($reflectionClass->hasMethod($methodReflection->getName())) {
$reflectionMethod = $reflectionClass->getMethod($methodReflection->getName());
}
} else {
$reflectionMethod = $classReflection->getNativeReflection()->getMethod($methodReflection->getName());
}
foreach ($variantNames as $innerVariantName) {
$methodSignature = $this->signatureMapProvider->getFunctionSignature($innerVariantName, $declaringClassName);
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,10 @@ public function testBug3443(): void
$this->analyse([__DIR__ . '/data/bug-3443.php'], []);
}

public function testBug3478(): void
{
$this->phpVersionId = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/bug-3478.php'], []);
}

}
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3478.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bug3478;

class ExtendedDocument extends \DOMDocument
{
public function saveHTML(\DOMNode $node = null)
{
return parent::saveHTML($node);
}
}

0 comments on commit 09f0beb

Please sign in to comment.