Updated Rector to commit 514df0a319b75f86b9b381ee0db7f95aadca32fb

514df0a319 Make NullToStrictStringFuncCallArgRector run without scope (#4792)
This commit is contained in:
Tomas Votruba 2023-08-14 14:35:49 +00:00
parent 5b1b83ed61
commit 426abe14c5
5 changed files with 24 additions and 37 deletions

View File

@ -13,26 +13,24 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Native\NativeFunctionReflection;
use PHPStan\Type\ErrorType;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\NullToStrictStringFuncCallArgRectorTest
*/
final class NullToStrictStringFuncCallArgRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
final class NullToStrictStringFuncCallArgRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
@ -91,21 +89,21 @@ CODE_SAMPLE
/**
* @param FuncCall $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
public function refactor(Node $node) : ?Node
{
if ($this->shouldSkip($node)) {
return null;
}
$args = $node->getArgs();
$positions = $this->argsAnalyzer->hasNamedArg($args) ? $this->resolveNamedPositions($node, $args) : $this->resolveOriginalPositions($node, $scope);
$positions = $this->argsAnalyzer->hasNamedArg($args) ? $this->resolveNamedPositions($node, $args) : $this->resolveOriginalPositions($node);
if ($positions === []) {
return null;
}
$classReflection = $scope->getClassReflection();
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
$isTrait = $classReflection instanceof ClassReflection && $classReflection->isTrait();
$isChanged = \false;
foreach ($positions as $position) {
$result = $this->processNullToStrictStringOnNodePosition($node, $args, $position, $isTrait, $scope);
$result = $this->processNullToStrictStringOnNodePosition($node, $args, $position, $isTrait);
if ($result instanceof Node) {
$node = $result;
$isChanged = \true;
@ -144,7 +142,7 @@ CODE_SAMPLE
* @param Arg[] $args
* @param int|string $position
*/
private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position, bool $isTrait, Scope $scope) : ?FuncCall
private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position, bool $isTrait) : ?FuncCall
{
if (!isset($args[$position])) {
return null;
@ -165,9 +163,6 @@ CODE_SAMPLE
if ($argValue instanceof Encapsed) {
return null;
}
if ($this->isAnErrorTypeFromParentScope($argValue, $scope)) {
return null;
}
if ($this->shouldSkipTrait($argValue, $type, $isTrait)) {
return null;
}
@ -191,29 +186,21 @@ CODE_SAMPLE
}
return \true;
}
private function isAnErrorTypeFromParentScope(Expr $expr, Scope $scope) : bool
{
$parentScope = $scope->getParentScope();
if ($parentScope instanceof Scope) {
return $parentScope->getType($expr) instanceof ErrorType;
}
return \false;
}
/**
* @return int[]|string[]
*/
private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope) : array
private function resolveOriginalPositions(FuncCall $funcCall) : array
{
$functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($funcCall);
if (!$functionReflection instanceof NativeFunctionReflection) {
return [];
}
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $funcCall, $scope);
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::combineAcceptors($functionReflection->getVariants());
$functionName = $functionReflection->getName();
$argNames = self::ARG_POSITION_NAME_NULL_TO_STRICT_STRING[$functionName];
$positions = [];
foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) {
if (\in_array($parameterReflection->getName(), $argNames, \true)) {
foreach ($parametersAcceptorWithPhpDocs->getParameters() as $position => $parameterReflectionWithPhpDoc) {
if (\in_array($parameterReflectionWithPhpDoc->getName(), $argNames, \true)) {
$positions[] = $position;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '685fe90cb8752c2a288ee982d03d15d8df6b59f2';
public const PACKAGE_VERSION = '514df0a319b75f86b9b381ee0db7f95aadca32fb';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-14 15:27:05';
public const RELEASE_DATE = '2023-08-14 15:31:54';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239::getLoader();
return ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239
class ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit9c580ee581ac8dff49b345ac114fb239::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit9c580ee581ac8dff49b345ac114fb239::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit9c580ee581ac8dff49b345ac114fb239
class ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2959,9 +2959,9 @@ class ComposerStaticInit9c580ee581ac8dff49b345ac114fb239
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit9c580ee581ac8dff49b345ac114fb239::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9c580ee581ac8dff49b345ac114fb239::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9c580ee581ac8dff49b345ac114fb239::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df::$classMap;
}, null, ClassLoader::class);
}