mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-13 12:02:09 +02:00
Updated Rector to commit d8d4e8d0b244ba368e3ce8767343c71b108ec93c
d8d4e8d0b2
Revert removed ErrorType handling on NullToStrictStringFuncCallArgRector (#4793)
This commit is contained in:
parent
e2003ba7c5
commit
1f172665e6
@ -13,9 +13,10 @@ 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\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Type\ErrorType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
@ -24,6 +25,8 @@ use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -94,16 +97,20 @@ CODE_SAMPLE
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$scope instanceof Scope) {
|
||||
return null;
|
||||
}
|
||||
$args = $node->getArgs();
|
||||
$positions = $this->argsAnalyzer->hasNamedArg($args) ? $this->resolveNamedPositions($node, $args) : $this->resolveOriginalPositions($node);
|
||||
$positions = $this->argsAnalyzer->hasNamedArg($args) ? $this->resolveNamedPositions($node, $args) : $this->resolveOriginalPositions($node, $scope);
|
||||
if ($positions === []) {
|
||||
return null;
|
||||
}
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
|
||||
$classReflection = $scope->getClassReflection();
|
||||
$isTrait = $classReflection instanceof ClassReflection && $classReflection->isTrait();
|
||||
$isChanged = \false;
|
||||
foreach ($positions as $position) {
|
||||
$result = $this->processNullToStrictStringOnNodePosition($node, $args, $position, $isTrait);
|
||||
$result = $this->processNullToStrictStringOnNodePosition($node, $args, $position, $isTrait, $scope);
|
||||
if ($result instanceof Node) {
|
||||
$node = $result;
|
||||
$isChanged = \true;
|
||||
@ -142,7 +149,7 @@ CODE_SAMPLE
|
||||
* @param Arg[] $args
|
||||
* @param int|string $position
|
||||
*/
|
||||
private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position, bool $isTrait) : ?FuncCall
|
||||
private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position, bool $isTrait, Scope $scope) : ?FuncCall
|
||||
{
|
||||
if (!isset($args[$position])) {
|
||||
return null;
|
||||
@ -163,6 +170,9 @@ CODE_SAMPLE
|
||||
if ($argValue instanceof Encapsed) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isAnErrorTypeFromParentScope($argValue, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkipTrait($argValue, $type, $isTrait)) {
|
||||
return null;
|
||||
}
|
||||
@ -186,21 +196,29 @@ 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) : array
|
||||
private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope) : array
|
||||
{
|
||||
$functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($funcCall);
|
||||
if (!$functionReflection instanceof NativeFunctionReflection) {
|
||||
return [];
|
||||
}
|
||||
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::combineAcceptors($functionReflection->getVariants());
|
||||
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $funcCall, $scope);
|
||||
$functionName = $functionReflection->getName();
|
||||
$argNames = self::ARG_POSITION_NAME_NULL_TO_STRICT_STRING[$functionName];
|
||||
$positions = [];
|
||||
foreach ($parametersAcceptorWithPhpDocs->getParameters() as $position => $parameterReflectionWithPhpDoc) {
|
||||
if (\in_array($parameterReflectionWithPhpDoc->getName(), $argNames, \true)) {
|
||||
foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) {
|
||||
if (\in_array($parameterReflection->getName(), $argNames, \true)) {
|
||||
$positions[] = $position;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.17.13';
|
||||
public const PACKAGE_VERSION = 'd8d4e8d0b244ba368e3ce8767343c71b108ec93c';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-14 15:31:54';
|
||||
public const RELEASE_DATE = '2023-08-14 20:58:29';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit5fc3ac0281aa73843cd8c37bc1ce536a::getLoader();
|
||||
return ComposerAutoloaderInitac102f4955b679dbad1826e7ab76734d::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit5fc3ac0281aa73843cd8c37bc1ce536a
|
||||
class ComposerAutoloaderInitac102f4955b679dbad1826e7ab76734d
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5fc3ac0281aa73843cd8c37bc1ce536a
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5fc3ac0281aa73843cd8c37bc1ce536a', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitac102f4955b679dbad1826e7ab76734d', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5fc3ac0281aa73843cd8c37bc1ce536a', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitac102f4955b679dbad1826e7ab76734d', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitac102f4955b679dbad1826e7ab76734d::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitac102f4955b679dbad1826e7ab76734d::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a
|
||||
class ComposerStaticInitac102f4955b679dbad1826e7ab76734d
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2959,9 +2959,9 @@ class ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5fc3ac0281aa73843cd8c37bc1ce536a::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitac102f4955b679dbad1826e7ab76734d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitac102f4955b679dbad1826e7ab76734d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitac102f4955b679dbad1826e7ab76734d::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user