widening - skip if no method is present (#5898)

This commit is contained in:
Tomas Votruba 2021-03-18 14:48:00 +01:00 committed by GitHub
parent 33daf1de2e
commit 1bdc6e588a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\Fixture;
use PhpParser\Node\Param;
use PHPStan\Type\Type;
use Rector\TypeDeclaration\Contract\TypeInferer\ParamTypeInfererInterface;
final class SkipRequiredRemoval implements ParamTypeInfererInterface
{
public function autowireSomething(\PHPStan\Type\Type $input)
{
}
public function inferParam(Param $param): Type
{
}
}

View File

@ -38,9 +38,6 @@ final class NativeTypeClassTreeResolver
int $position
): Type {
$nativeReflectionClass = $classReflection->getNativeReflection();
if (! $nativeReflectionClass->hasMethod($methodName)) {
return new MixedType();
}
$reflectionMethod = $nativeReflectionClass->getMethod($methodName);
$parameterReflection = $reflectionMethod->getParameters()[$position] ?? null;

View File

@ -236,6 +236,10 @@ CODE_SAMPLE
$parameterTypesByParentClassLikes = [];
foreach ($classReflection->getAncestors() as $ancestorClassReflection) {
if (! $ancestorClassReflection->hasMethod($methodName)) {
continue;
}
$parameterType = $this->nativeTypeClassTreeResolver->resolveParameterReflectionType(
$ancestorClassReflection,
$methodName,