Skip to content

Commit

Permalink
Do not consider arrays with an unknown class string to be a callback
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Jun 8, 2022
1 parent db3863a commit 0b5253d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/Constant/ConstantArrayType.php
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnusedPrivateMethodRuleTest.php
Expand Up @@ -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,
],
]);
}

}
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-7389.php
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace Bug7389;

class HelloWorld
{
/**
* @param string $test test
* @return array<string>
*/
private function getTest(string $test): array
{
return [
'',
'',
];
}

/**
* @param string $test test
* @return string
*/
private function getTest1(string $test): string
{
return 'test1';
}
}

0 comments on commit 0b5253d

Please sign in to comment.