[Reflection] Avoid error Call to a member function getType() on null on ReflectionResolver (#334)

This commit is contained in:
Abdul Malik Ikhsan 2021-06-30 03:29:49 +07:00 committed by GitHub
parent 9bd39bd18c
commit 8cdd122c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Fixture;
final class OnCannotGetScopeOfFunctionCall
{
public static function streamSupports(string $function, $ret, $resource): bool
{
define('ENVIRONMENT', 'testing');
if (ENVIRONMENT === 'testing') {
return false;
}
return function_exists($function, 'abc') && @$function($resource);
}
}
?>
-----
<?php
namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Fixture;
final class OnCannotGetScopeOfFunctionCall
{
public static function streamSupports(string $function, $ret, $resource): bool
{
define('ENVIRONMENT', 'testing');
if (ENVIRONMENT === 'testing') {
return false;
}
return function_exists($function) && @$function($resource);
}
}
?>

View File

@ -204,6 +204,10 @@ final class ReflectionResolver
return null;
}
if (! $scope instanceof Scope) {
return null;
}
// fallback to callable
$funcCallNameType = $scope->getType($funcCall->name);
return $this->typeToCallReflectionResolverRegistry->resolve($funcCallNameType, $scope);