diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index d393ef0898..5c019f1396 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -395,7 +395,7 @@ public function findTypeAndMethodName(): ?ConstantArrayTypeAndMethod if ($classOrObject instanceof ConstantStringType) { $reflectionProvider = ReflectionProviderStaticAccessor::getInstance(); if (!$reflectionProvider->hasClass($classOrObject->getValue())) { - return ConstantArrayTypeAndMethod::createUnknown(); + return null; } $type = new ObjectType($reflectionProvider->getClass($classOrObject->getValue())->getName()); } elseif ($classOrObject instanceof GenericClassStringType) { diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php index fdef75b3fc..60fe27b782 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php @@ -76,4 +76,18 @@ public function testEnums(): void ]); } + public function testBug7389(): void + { + $this->analyse([__DIR__ . '/data/bug-7389.php'], [ + [ + 'Method Bug7389\HelloWorld::getTest() is unused.', + 11, + ], + [ + 'Method Bug7389\HelloWorld::getTest1() is unused.', + 23, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-7389.php b/tests/PHPStan/Rules/DeadCode/data/bug-7389.php new file mode 100644 index 0000000000..ff778fcbe1 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-7389.php @@ -0,0 +1,27 @@ + + */ + private function getTest(string $test): array + { + return [ + '', + '', + ]; + } + + /** + * @param string $test test + * @return string + */ + private function getTest1(string $test): string + { + return 'test1'; + } +}