Skip to content

Commit

Permalink
Updated Rector to commit 514df0a319b75f86b9b381ee0db7f95aadca32fb
Browse files Browse the repository at this point in the history
rectorphp/rector-src@514df0a Make NullToStrictStringFuncCallArgRector run without scope (#4792)
  • Loading branch information
TomasVotruba committed Aug 14, 2023
1 parent 5b1b83e commit 426abe1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
37 changes: 12 additions & 25 deletions rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
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
Expand Down Expand Up @@ -91,21 +89,21 @@ public function getNodeTypes() : array
/**
* @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;
Expand Down Expand Up @@ -144,7 +142,7 @@ private function resolveNamedPositions(FuncCall $funcCall, array $args) : array
* @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;
Expand All @@ -165,9 +163,6 @@ private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, arr
if ($argValue instanceof Encapsed) {
return null;
}
if ($this->isAnErrorTypeFromParentScope($argValue, $scope)) {
return null;
}
if ($this->shouldSkipTrait($argValue, $type, $isTrait)) {
return null;
}
Expand All @@ -191,29 +186,21 @@ private function shouldSkipTrait(Expr $expr, Type $type, bool $isTrait) : bool
}
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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239::getLoader();
return ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit9c580ee581ac8dff49b345ac114fb239
class ComposerAutoloaderInitaa971efa9f36d87324e7db1e8e2d26df
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit9c580ee581ac8dff49b345ac114fb239
class ComposerStaticInitaa971efa9f36d87324e7db1e8e2d26df
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 426abe1

Please sign in to comment.