From 09f0bebde608fe7976eaef6a40f543de8464a8a4 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 16 Jun 2020 15:10:59 +0200 Subject: [PATCH] Native method reflection - look in stubs first, then into native runtime PHP reflection --- src/Reflection/Php/PhpClassReflectionExtension.php | 6 +++--- .../Rules/Methods/OverridingMethodRuleTest.php | 6 ++++++ tests/PHPStan/Rules/Methods/data/bug-3478.php | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-3478.php diff --git a/src/Reflection/Php/PhpClassReflectionExtension.php b/src/Reflection/Php/PhpClassReflectionExtension.php index b75e4eac94..e143300028 100644 --- a/src/Reflection/Php/PhpClassReflectionExtension.php +++ b/src/Reflection/Php/PhpClassReflectionExtension.php @@ -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); diff --git a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php index cdde0eaa67..bc10a2709a 100644 --- a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php +++ b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php @@ -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'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-3478.php b/tests/PHPStan/Rules/Methods/data/bug-3478.php new file mode 100644 index 0000000000..68b6993ec5 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-3478.php @@ -0,0 +1,11 @@ +