Updated Rector to commit f6c4edcd0c3feaad4abc075bae39474ac34bb82d

f6c4edcd0c [CodeQuality] Add CleanupUnneededNullsafeOperatorRector (#3767)
This commit is contained in:
Tomas Votruba 2023-05-08 10:34:10 +00:00
parent 39697489d4
commit af500df8f4
21 changed files with 51 additions and 47 deletions

View File

@ -85,11 +85,11 @@ final class ArgumentDefaultValueReplacer
if (!$expr->args[$position] instanceof Arg) {
return null;
}
$argValue = $this->valueResolver->getValue($expr->getArgs()[$position]->value);
$argValue = $this->valueResolver->getValue($expr->args[$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->getArgs(), $replaceArgumentDefaultValue);
$newArgs = $this->processArrayReplacement($expr->args, $replaceArgumentDefaultValue);
if (\is_array($newArgs)) {
$expr->args = $newArgs;
}

View File

@ -4,6 +4,7 @@ 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;
@ -52,10 +53,11 @@ final class SimplifyEmptyArrayCheckRector extends AbstractRector
}
/** @var FuncCall $isArrayExpr */
$isArrayExpr = $twoNodeMatch->getFirstExpr();
$firstArgValue = $isArrayExpr->getArgs()[0]->value;
/** @var Expr $firstArgValue */
$firstArgValue = $isArrayExpr->args[0]->value;
/** @var Empty_ $emptyOrNotIdenticalNode */
$emptyOrNotIdenticalNode = $twoNodeMatch->getSecondExpr();
if ($emptyOrNotIdenticalNode->expr instanceof FuncCall && $this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr->getArgs()[0]->value, $firstArgValue)) {
if ($emptyOrNotIdenticalNode->expr instanceof FuncCall && $this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr->args[0]->value, $firstArgValue)) {
return new Identical($emptyOrNotIdenticalNode->expr, new Array_());
}
if (!$this->nodeComparator->areNodesEqual($emptyOrNotIdenticalNode->expr, $firstArgValue)) {

View File

@ -159,7 +159,7 @@ CODE_SAMPLE
*/
private function resolveCount(bool $isNegated, FuncCall $funcCall)
{
$countedType = $this->getType($funcCall->getArgs()[0]->value);
$countedType = $this->getType($funcCall->args[0]->value);
if ($countedType->isArray()->yes()) {
return null;
}

View File

@ -20,6 +20,9 @@ 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

View File

@ -58,9 +58,8 @@ CODE_SAMPLE
if (!isset($node->getArgs()[0])) {
return null;
}
$firstArg = $node->getArgs()[0];
$node->name = new Name('mysqli_connect');
$node->args[0]->value = $this->joinStringWithNode('p:', $firstArg->value);
$node->args[0]->value = $this->joinStringWithNode('p:', $node->getArgs()[0]->value);
return $node;
}
/**

View File

@ -80,7 +80,7 @@ CODE_SAMPLE
if (!$this->isName($node, $oldFunction)) {
continue;
}
$args = $node->getArgs();
$args = $node->args;
if ($args === [] || !$this->isProbablyMysql($args[0]->value)) {
$connectionVariable = $this->findConnectionVariable($node);
$this->removeExistingConnectionParameter($node);

View File

@ -71,7 +71,7 @@ final class MultiDirnameRector extends AbstractRector implements MinPhpVersionIn
if (!$this->isName($funcCall, self::DIRNAME)) {
return null;
}
$args = $funcCall->getArgs();
$args = $funcCall->args;
if (\count($args) >= 3) {
return null;
}

View File

@ -167,8 +167,7 @@ CODE_SAMPLE
if ($trait instanceof Trait_) {
return \true;
}
$firstArg = $funcCall->getArgs()[0];
if (!$firstArg->value instanceof Variable) {
if (!$funcCall->args[0]->value instanceof Variable) {
return \false;
}
$parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
@ -178,7 +177,7 @@ CODE_SAMPLE
return \true;
}
}
return $this->variableAnalyzer->isStaticOrGlobal($firstArg->value);
return $this->variableAnalyzer->isStaticOrGlobal($funcCall->args[0]->value);
}
private function castToArray(Expr $countedExpr, FuncCall $funcCall) : FuncCall
{

View File

@ -87,7 +87,7 @@ CODE_SAMPLE
if (!isset($eachFuncCall->getArgs()[0])) {
return null;
}
$firstArg = $eachFuncCall->getArgs()[0];
$firstArg = $eachFuncCall->args[0];
$foreachedExpr = \count($listNode->items) === 1 ? $this->nodeFactory->createFuncCall('array_keys', [$firstArg]) : $firstArg->value;
$arrayItem = \array_pop($listNode->items);
$isTrailingCommaLast = \false;

View File

@ -152,7 +152,7 @@ CODE_SAMPLE
if ($subNode->isFirstClassCallable()) {
return \true;
}
return $this->nodeComparator->areNodesEqual($subNode->getArgs()[0]->value, $funcCall->getArgs()[0]->value);
return $this->nodeComparator->areNodesEqual($subNode->args[0]->value, $funcCall->args[0]->value);
});
if ($hasPrevCallNext) {
return \true;

View File

@ -119,7 +119,7 @@ CODE_SAMPLE
if (!isset($funcCall->getArgs()[0])) {
return \false;
}
$firstArg = $funcCall->getArgs()[0];
$firstArg = $funcCall->args[0];
$value = $this->valueResolver->getValue($firstArg->value);
if (\is_string($value)) {
return \true;

View File

@ -10,6 +10,7 @@ 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;
@ -85,15 +86,17 @@ CODE_SAMPLE
return \false;
}
/**
* @return Arg[]
* @return Arg[]|VariadicPlaceholder[]
*/
private function composeNewArgs(FuncCall $funcCall) : array
{
$args = $funcCall->getArgs();
$newArgs = [$args[0], $args[1]];
$items = [];
$args = $funcCall->args;
$newArgs = [];
$newArgs[] = $args[0];
$newArgs[] = $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);

View File

@ -76,8 +76,8 @@ final class ResourceReturnToObject
if ($objectInstanceCheck === null) {
return null;
}
$firstArg = $funcCall->getArgs()[0];
$argResourceValue = $firstArg->value;
/** @var Expr $argResourceValue */
$argResourceValue = $funcCall->args[0]->value;
return new Instanceof_($argResourceValue, new FullyQualified($objectInstanceCheck));
}
/**
@ -85,7 +85,8 @@ final class ResourceReturnToObject
*/
private function resolveArgValueType(FuncCall $funcCall, array $collectionFunctionToReturnObject) : ?Type
{
$argResourceValue = $funcCall->getArgs()[0]->value;
/** @var Expr $argResourceValue */
$argResourceValue = $funcCall->args[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
@ -173,7 +174,8 @@ final class ResourceReturnToObject
if ($objectInstanceCheck === null) {
return null;
}
$argResourceValue = $funCall->getArgs()[0]->value;
/** @var Expr $argResourceValue */
$argResourceValue = $funCall->args[0]->value;
/** @var Instanceof_ $instanceof */
if (!$this->isInstanceOfObjectCheck($instanceof, $argResourceValue, $objectInstanceCheck)) {
return null;

View File

@ -72,10 +72,9 @@ CODE_SAMPLE
if (!$funcCall instanceof FuncCall) {
return null;
}
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]));
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]]));
}
unset($funcCall->args[2]);
}

View File

@ -112,13 +112,13 @@ CODE_SAMPLE
{
/** @var FuncCall $isObjectFuncCall */
$isObjectFuncCall = $ternary->cond;
$firstExpr = $isObjectFuncCall->getArgs()[0]->value;
$firstExpr = $isObjectFuncCall->args[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->getArgs()[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
$secondExpr = $getClassFuncCallOrClassConstFetchClass instanceof FuncCall ? $getClassFuncCallOrClassConstFetchClass->args[0]->value : $getClassFuncCallOrClassConstFetchClass->class;
/** @var FuncCall $gettypeFuncCall */
$gettypeFuncCall = $ternary->else;
if (!$gettypeFuncCall->args[0] instanceof Arg) {

View File

@ -53,10 +53,10 @@ final class FilesystemIteratorSkipDotsRector extends AbstractRector implements M
if (!$this->isObjectType($node->class, new ObjectType('FilesystemIterator'))) {
return null;
}
if (!isset($node->args[1])) {
if (!\array_key_exists(1, $node->args)) {
return null;
}
$flags = $node->getArgs()[1]->value;
$flags = $node->args[1]->value;
if ($this->isSkipDotsPresent($flags)) {
return null;
}

View File

@ -90,10 +90,7 @@ CODE_SAMPLE
private function refactorResetFuncCall(Ternary $ternary, FuncCall $resetFuncCall, Scope $scope) : void
{
$ternary->if = $ternary->cond;
if ($resetFuncCall->isFirstClassCallable()) {
return;
}
$firstArgValue = $resetFuncCall->getArgs()[0]->value;
$firstArgValue = $resetFuncCall->args[0]->value;
$firstArgType = $scope->getType($firstArgValue);
$falsyCompareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($firstArgType, $firstArgValue, $this->treatAsNonEmpty);
if (!$falsyCompareExpr instanceof Expr) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '5a32ed95b75b179e77c14a83a65f2eff1f1474b8';
public const PACKAGE_VERSION = 'f6c4edcd0c3feaad4abc075bae39474ac34bb82d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-08 11:30:10';
public const RELEASE_DATE = '2023-05-08 11:29:53';
/**
* @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 ComposerAutoloaderInitf411abce3116d124ad2aafca1a020ab3::getLoader();
return ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitf411abce3116d124ad2aafca1a020ab3
class ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf411abce3116d124ad2aafca1a020ab3
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitf411abce3116d124ad2aafca1a020ab3', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitf411abce3116d124ad2aafca1a020ab3', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8dad6289c3598cbdbd188594820db591', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitf411abce3116d124ad2aafca1a020ab3::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8dad6289c3598cbdbd188594820db591::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitf411abce3116d124ad2aafca1a020ab3::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit8dad6289c3598cbdbd188594820db591::$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 ComposerStaticInitf411abce3116d124ad2aafca1a020ab3
class ComposerStaticInit8dad6289c3598cbdbd188594820db591
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3122,9 +3122,9 @@ class ComposerStaticInitf411abce3116d124ad2aafca1a020ab3
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf411abce3116d124ad2aafca1a020ab3::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf411abce3116d124ad2aafca1a020ab3::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf411abce3116d124ad2aafca1a020ab3::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8dad6289c3598cbdbd188594820db591::$classMap;
}, null, ClassLoader::class);
}