mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit 1e052f588331717f87a8d610db6eb7f89f8690d3
1e052f5883
[cleanup] Make use of getArgs(), remove ignored from phpstan (#3771)
This commit is contained in:
parent
af500df8f4
commit
8af1a1213f
@ -85,11 +85,11 @@ final class ArgumentDefaultValueReplacer
|
||||
if (!$expr->args[$position] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
$argValue = $this->valueResolver->getValue($expr->args[$position]->value);
|
||||
$argValue = $this->valueResolver->getValue($expr->getArgs()[$position]->value);
|
||||
if (\is_scalar($replaceArgumentDefaultValue->getValueBefore()) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
|
||||
$expr->args[$position] = $this->normalizeValueToArgument($replaceArgumentDefaultValue->getValueAfter());
|
||||
} elseif (\is_array($replaceArgumentDefaultValue->getValueBefore())) {
|
||||
$newArgs = $this->processArrayReplacement($expr->args, $replaceArgumentDefaultValue);
|
||||
$newArgs = $this->processArrayReplacement($expr->getArgs(), $replaceArgumentDefaultValue);
|
||||
if (\is_array($newArgs)) {
|
||||
$expr->args = $newArgs;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\BooleanAnd;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
@ -53,11 +52,10 @@ final class SimplifyEmptyArrayCheckRector extends AbstractRector
|
||||
}
|
||||
/** @var FuncCall $isArrayExpr */
|
||||
$isArrayExpr = $twoNodeMatch->getFirstExpr();
|
||||
/** @var Expr $firstArgValue */
|
||||
$firstArgValue = $isArrayExpr->args[0]->value;
|
||||
$firstArgValue = $isArrayExpr->getArgs()[0]->value;
|
||||
/** @var Empty_ $emptyOrNotIdenticalNode */
|
||||
$emptyOrNotIdenticalNode = $twoNodeMatch->getSecondExpr();
|
||||
if ($emptyOrNotIdenticalNode->expr instanceof FuncCall && $this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr->args[0]->value, $firstArgValue)) {
|
||||
if ($emptyOrNotIdenticalNode->expr instanceof FuncCall && $this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr->getArgs()[0]->value, $firstArgValue)) {
|
||||
return new Identical($emptyOrNotIdenticalNode->expr, new Array_());
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr, $firstArgValue)) {
|
||||
|
@ -159,7 +159,7 @@ CODE_SAMPLE
|
||||
*/
|
||||
private function resolveCount(bool $isNegated, FuncCall $funcCall)
|
||||
{
|
||||
$countedType = $this->getType($funcCall->args[0]->value);
|
||||
$countedType = $this->getType($funcCall->getArgs()[0]->value);
|
||||
if ($countedType->isArray()->yes()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -20,9 +20,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/symplify/phpstan-rules/blob/main/docs/rules_overview.md#explicitmethodcallovermagicgetsetrule
|
||||
*
|
||||
* @inspired by \Rector\Transform\Rector\Assign\GetAndSetToMethodCallRector
|
||||
* @phpstan-rule https://github.com/symplify/phpstan-rules/blob/main/src/Rules/Explicit/ExplicitMethodCallOverMagicGetSetRule.php
|
||||
*
|
||||
* @see \Rector\Tests\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector\ExplicitMethodCallOverMagicGetSetRectorTest
|
||||
*/
|
||||
final class ExplicitMethodCallOverMagicGetSetRector extends AbstractScopeAwareRector
|
||||
|
@ -58,8 +58,10 @@ CODE_SAMPLE
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
$args = $node->getArgs();
|
||||
$firstArg = $args[0];
|
||||
$node->name = new Name('mysqli_connect');
|
||||
$node->args[0]->value = $this->joinStringWithNode('p:', $node->getArgs()[0]->value);
|
||||
$args[0]->value = $this->joinStringWithNode('p:', $firstArg->value);
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ CODE_SAMPLE
|
||||
if (!$this->isName($node, $oldFunction)) {
|
||||
continue;
|
||||
}
|
||||
$args = $node->args;
|
||||
$args = $node->getArgs();
|
||||
if ($args === [] || !$this->isProbablyMysql($args[0]->value)) {
|
||||
$connectionVariable = $this->findConnectionVariable($node);
|
||||
$this->removeExistingConnectionParameter($node);
|
||||
|
@ -71,7 +71,7 @@ final class MultiDirnameRector extends AbstractRector implements MinPhpVersionIn
|
||||
if (!$this->isName($funcCall, self::DIRNAME)) {
|
||||
return null;
|
||||
}
|
||||
$args = $funcCall->args;
|
||||
$args = $funcCall->getArgs();
|
||||
if (\count($args) >= 3) {
|
||||
return null;
|
||||
}
|
||||
|
@ -167,7 +167,8 @@ CODE_SAMPLE
|
||||
if ($trait instanceof Trait_) {
|
||||
return \true;
|
||||
}
|
||||
if (!$funcCall->args[0]->value instanceof Variable) {
|
||||
$firstArg = $funcCall->getArgs()[0];
|
||||
if (!$firstArg->value instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
@ -177,7 +178,7 @@ CODE_SAMPLE
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return $this->variableAnalyzer->isStaticOrGlobal($funcCall->args[0]->value);
|
||||
return $this->variableAnalyzer->isStaticOrGlobal($firstArg->value);
|
||||
}
|
||||
private function castToArray(Expr $countedExpr, FuncCall $funcCall) : FuncCall
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ CODE_SAMPLE
|
||||
if (!isset($eachFuncCall->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
$firstArg = $eachFuncCall->args[0];
|
||||
$firstArg = $eachFuncCall->getArgs()[0];
|
||||
$foreachedExpr = \count($listNode->items) === 1 ? $this->nodeFactory->createFuncCall('array_keys', [$firstArg]) : $firstArg->value;
|
||||
$arrayItem = \array_pop($listNode->items);
|
||||
$isTrailingCommaLast = \false;
|
||||
|
@ -152,7 +152,7 @@ CODE_SAMPLE
|
||||
if ($subNode->isFirstClassCallable()) {
|
||||
return \true;
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($subNode->args[0]->value, $funcCall->args[0]->value);
|
||||
return $this->nodeComparator->areNodesEqual($subNode->getArgs()[0]->value, $funcCall->getArgs()[0]->value);
|
||||
});
|
||||
if ($hasPrevCallNext) {
|
||||
return \true;
|
||||
|
@ -119,7 +119,7 @@ CODE_SAMPLE
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return \false;
|
||||
}
|
||||
$firstArg = $funcCall->args[0];
|
||||
$firstArg = $funcCall->getArgs()[0];
|
||||
$value = $this->valueResolver->getValue($firstArg->value);
|
||||
if (\is_string($value)) {
|
||||
return \true;
|
||||
|
@ -10,7 +10,6 @@ use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\VariadicPlaceholder;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
@ -86,17 +85,15 @@ CODE_SAMPLE
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @return Arg[]|VariadicPlaceholder[]
|
||||
* @return Arg[]
|
||||
*/
|
||||
private function composeNewArgs(FuncCall $funcCall) : array
|
||||
{
|
||||
$items = [];
|
||||
$args = $funcCall->args;
|
||||
$newArgs = [];
|
||||
$newArgs[] = $args[0];
|
||||
$newArgs[] = $args[1];
|
||||
$args = $funcCall->getArgs();
|
||||
$newArgs = [$args[0], $args[1]];
|
||||
unset($args[0]);
|
||||
unset($args[1]);
|
||||
$items = [];
|
||||
foreach ($args as $idx => $arg) {
|
||||
$newKey = new String_(self::KNOWN_OPTIONS[$idx]);
|
||||
$items[] = new ArrayItem($arg->value, $newKey);
|
||||
|
@ -76,8 +76,8 @@ final class ResourceReturnToObject
|
||||
if ($objectInstanceCheck === null) {
|
||||
return null;
|
||||
}
|
||||
/** @var Expr $argResourceValue */
|
||||
$argResourceValue = $funcCall->args[0]->value;
|
||||
$firstArg = $funcCall->getArgs()[0];
|
||||
$argResourceValue = $firstArg->value;
|
||||
return new Instanceof_($argResourceValue, new FullyQualified($objectInstanceCheck));
|
||||
}
|
||||
/**
|
||||
@ -85,8 +85,7 @@ final class ResourceReturnToObject
|
||||
*/
|
||||
private function resolveArgValueType(FuncCall $funcCall, array $collectionFunctionToReturnObject) : ?Type
|
||||
{
|
||||
/** @var Expr $argResourceValue */
|
||||
$argResourceValue = $funcCall->args[0]->value;
|
||||
$argResourceValue = $funcCall->getArgs()[0]->value;
|
||||
$argValueType = $this->nodeTypeResolver->getType($argResourceValue);
|
||||
// if detected type is not FullyQualifiedObjectType, it still can be a resource to object, when:
|
||||
// - in the right position of BooleanOr, it be NeverType
|
||||
@ -174,8 +173,7 @@ final class ResourceReturnToObject
|
||||
if ($objectInstanceCheck === null) {
|
||||
return null;
|
||||
}
|
||||
/** @var Expr $argResourceValue */
|
||||
$argResourceValue = $funCall->args[0]->value;
|
||||
$argResourceValue = $funCall->getArgs()[0]->value;
|
||||
/** @var Instanceof_ $instanceof */
|
||||
if (!$this->isInstanceOfObjectCheck($instanceof, $argResourceValue, $objectInstanceCheck)) {
|
||||
return null;
|
||||
|
@ -72,9 +72,10 @@ CODE_SAMPLE
|
||||
if (!$funcCall instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
if (isset($funcCall->args[2])) {
|
||||
if ($this->isName($funcCall->name, 'strpos') && $this->isPositiveInteger($funcCall->args[2]->value)) {
|
||||
$funcCall->args[0] = new Arg($this->nodeFactory->createFuncCall('substr', [$funcCall->args[0], $funcCall->args[2]]));
|
||||
if (isset($funcCall->getArgs()[2])) {
|
||||
$secondArg = $funcCall->getArgs()[2];
|
||||
if ($this->isName($funcCall->name, 'strpos') && $this->isPositiveInteger($secondArg->value)) {
|
||||
$funcCall->args[0] = new Arg($this->nodeFactory->createFuncCall('substr', [$funcCall->args[0], $secondArg]));
|
||||
}
|
||||
unset($funcCall->args[2]);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ CODE_SAMPLE
|
||||
}
|
||||
/** @var FuncCall|ClassConstFetch $getClassFuncCallOrClassConstFetchClass */
|
||||
$getClassFuncCallOrClassConstFetchClass = $node->if;
|
||||
$firstExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->args[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
|
||||
$firstExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->getArgs()[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
|
||||
return $this->nodeFactory->createFuncCall('get_debug_type', [$firstExpr]);
|
||||
}
|
||||
private function shouldSkip(Ternary $ternary) : bool
|
||||
@ -112,13 +112,13 @@ CODE_SAMPLE
|
||||
{
|
||||
/** @var FuncCall $isObjectFuncCall */
|
||||
$isObjectFuncCall = $ternary->cond;
|
||||
$firstExpr = $isObjectFuncCall->args[0]->value;
|
||||
$firstExpr = $isObjectFuncCall->getArgs()[0]->value;
|
||||
/** @var FuncCall|ClassConstFetch $getClassFuncCallOrClassConstFetchClass */
|
||||
$getClassFuncCallOrClassConstFetchClass = $ternary->if;
|
||||
if ($getClassFuncCallOrClassConstFetchClass instanceof FuncCall && !$getClassFuncCallOrClassConstFetchClass->args[0] instanceof Arg) {
|
||||
return \false;
|
||||
}
|
||||
$secondExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->args[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
|
||||
$secondExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->getArgs()[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
|
||||
/** @var FuncCall $gettypeFuncCall */
|
||||
$gettypeFuncCall = $ternary->else;
|
||||
if (!$gettypeFuncCall->args[0] instanceof Arg) {
|
||||
|
@ -53,10 +53,10 @@ final class FilesystemIteratorSkipDotsRector extends AbstractRector implements M
|
||||
if (!$this->isObjectType($node->class, new ObjectType('FilesystemIterator'))) {
|
||||
return null;
|
||||
}
|
||||
if (!\array_key_exists(1, $node->args)) {
|
||||
if (!isset($node->args[1])) {
|
||||
return null;
|
||||
}
|
||||
$flags = $node->args[1]->value;
|
||||
$flags = $node->getArgs()[1]->value;
|
||||
if ($this->isSkipDotsPresent($flags)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -90,7 +90,10 @@ CODE_SAMPLE
|
||||
private function refactorResetFuncCall(Ternary $ternary, FuncCall $resetFuncCall, Scope $scope) : void
|
||||
{
|
||||
$ternary->if = $ternary->cond;
|
||||
$firstArgValue = $resetFuncCall->args[0]->value;
|
||||
if ($resetFuncCall->isFirstClassCallable()) {
|
||||
return;
|
||||
}
|
||||
$firstArgValue = $resetFuncCall->getArgs()[0]->value;
|
||||
$firstArgType = $scope->getType($firstArgValue);
|
||||
$falsyCompareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($firstArgType, $firstArgValue, $this->treatAsNonEmpty);
|
||||
if (!$falsyCompareExpr instanceof Expr) {
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f6c4edcd0c3feaad4abc075bae39474ac34bb82d';
|
||||
public const PACKAGE_VERSION = '1e052f588331717f87a8d610db6eb7f89f8690d3';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-08 11:29:53';
|
||||
public const RELEASE_DATE = '2023-05-08 12:50:25';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591::getLoader();
|
||||
return ComposerAutoloaderInit1f0ff480be11c176eb74aef185ba5426::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 ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591
|
||||
class ComposerAutoloaderInit1f0ff480be11c176eb74aef185ba5426
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1f0ff480be11c176eb74aef185ba5426', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1f0ff480be11c176eb74aef185ba5426', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit8dad6289c3598cbdbd188594820db591::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1f0ff480be11c176eb74aef185ba5426::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit8dad6289c3598cbdbd188594820db591::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1f0ff480be11c176eb74aef185ba5426::$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 ComposerStaticInit8dad6289c3598cbdbd188594820db591
|
||||
class ComposerStaticInit1f0ff480be11c176eb74aef185ba5426
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3122,9 +3122,9 @@ class ComposerStaticInit8dad6289c3598cbdbd188594820db591
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1f0ff480be11c176eb74aef185ba5426::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1f0ff480be11c176eb74aef185ba5426::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1f0ff480be11c176eb74aef185ba5426::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user