[PHPStan 1.0] upgrade deprecated getNativeMethods() method (#1069)

This commit is contained in:
Tomas Votruba 2021-10-26 13:49:45 +02:00 committed by GitHub
parent ade120e97a
commit fbeecb22d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
@ -75,7 +76,9 @@ final class TypeProvidingExprFromClassResolver
ClassReflection $classReflection,
ObjectType $objectType
): ?MethodCall {
foreach ($classReflection->getNativeMethods() as $methodReflection) {
$methodReflections = $this->getClassMethodReflections($classReflection);
foreach ($methodReflections as $methodReflection) {
$functionVariant = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
$returnType = $functionVariant->getReturnType();
@ -142,4 +145,19 @@ final class TypeProvidingExprFromClassResolver
return $readableType->equals($objectType);
}
/**
* @return MethodReflection[]
*/
private function getClassMethodReflections(ClassReflection $classReflection): array
{
$nativeClassReflection = $classReflection->getNativeReflection();
$methodReflections = [];
foreach ($nativeClassReflection->getMethods() as $reflectionMethod) {
$methodReflections[] = $classReflection->getNativeMethod($reflectionMethod->getName());
}
return $methodReflections;
}
}