Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider arrays with an unknown class string to be a callback #1404

Merged
merged 1 commit into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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';
}
}