mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 56e13466c3ba3c23c0eb5e7e3af6908433c0c6af
56e13466c3
[CI] Enable zend.assertions=1 on CI (#3823)
This commit is contained in:
parent
c8378bb7c9
commit
af39f1cc41
|
@ -13,7 +13,6 @@ use PhpParser\Node\Stmt\Property;
|
|||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\Renaming\Helper\RenameClassCallbackHandler;
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'ed494161ee091037ea7cb791e569abb1bf2ff990';
|
||||
public const PACKAGE_VERSION = '56e13466c3ba3c23c0eb5e7e3af6908433c0c6af';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-13 14:36:19';
|
||||
public const RELEASE_DATE = '2023-05-13 16:40:51';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitb5ee464d17bb12f1d6a060ed28147208::getLoader();
|
||||
return ComposerAutoloaderInit0b719f9a900fe844677d95a21f1699d1::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitb5ee464d17bb12f1d6a060ed28147208
|
||||
class ComposerAutoloaderInit0b719f9a900fe844677d95a21f1699d1
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInitb5ee464d17bb12f1d6a060ed28147208
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitb5ee464d17bb12f1d6a060ed28147208', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0b719f9a900fe844677d95a21f1699d1', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitb5ee464d17bb12f1d6a060ed28147208', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0b719f9a900fe844677d95a21f1699d1', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0b719f9a900fe844677d95a21f1699d1::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit0b719f9a900fe844677d95a21f1699d1::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208
|
||||
class ComposerStaticInit0b719f9a900fe844677d95a21f1699d1
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3111,9 +3111,9 @@ class ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitb5ee464d17bb12f1d6a060ed28147208::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0b719f9a900fe844677d95a21f1699d1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0b719f9a900fe844677d95a21f1699d1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0b719f9a900fe844677d95a21f1699d1::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -1924,12 +1924,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
|
||||
"reference": "3209c44703d4bef7614048ed2a5019665ec3a9f2"
|
||||
"reference": "86a937c9c1b31ed702070cb39f2ee2d4748f545b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/3209c44703d4bef7614048ed2a5019665ec3a9f2",
|
||||
"reference": "3209c44703d4bef7614048ed2a5019665ec3a9f2",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/86a937c9c1b31ed702070cb39f2ee2d4748f545b",
|
||||
"reference": "86a937c9c1b31ed702070cb39f2ee2d4748f545b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1953,7 +1953,7 @@
|
|||
"tomasvotruba\/type-coverage": "^0.0.9",
|
||||
"tomasvotruba\/unused-public": "^0.0.34"
|
||||
},
|
||||
"time": "2023-05-04T13:13:06+00:00",
|
||||
"time": "2023-05-13T15:19:39+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 03df9e3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3209c44'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 63d391e'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f385be4'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 03df9e3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 86a937c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 63d391e'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f385be4'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ CODE_SAMPLE
|
|||
if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($node->name)) {
|
||||
return null;
|
||||
}
|
||||
$args = \array_merge([new Arg($node->name)], $node->args);
|
||||
$args = \array_merge([new Arg($node->name)], $node->getArgs());
|
||||
return new FuncCall(new Name('call_user_func'), $args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @changelog https://wiki.php.net/rfc/class_name_scalars
|
||||
*
|
||||
* @see Rector\Tests\DowngradePhp55\Rector\ClassConstFetch\DowngradeClassConstantToStringRector\DowngradeClassConstantToStringRectorTest
|
||||
* @see \Rector\Tests\DowngradePhp55\Rector\ClassConstFetch\DowngradeClassConstantToStringRector\DowngradeClassConstantToStringRectorTest
|
||||
*/
|
||||
final class DowngradeClassConstantToStringRector extends AbstractRector
|
||||
{
|
||||
|
|
|
@ -72,22 +72,16 @@ CODE_SAMPLE
|
|||
}
|
||||
private function refactorBoolval(FuncCall $funcCall) : ?Bool_
|
||||
{
|
||||
if (!isset($funcCall->args[0])) {
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$funcCall->args[0] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
return new Bool_($funcCall->args[0]->value);
|
||||
return new Bool_($funcCall->getArgs()[0]->value);
|
||||
}
|
||||
private function refactorAsCallback(FuncCall $funcCall) : ?FuncCall
|
||||
{
|
||||
$functionLikeReflection = null;
|
||||
$refactored = \false;
|
||||
foreach ($funcCall->args as $position => $arg) {
|
||||
if (!$arg instanceof Arg) {
|
||||
continue;
|
||||
}
|
||||
foreach ($funcCall->getArgs() as $position => $arg) {
|
||||
if (!$this->isBoolvalReference($arg)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp70\Rector\Expression;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
|
@ -12,7 +11,6 @@ use PhpParser\Node\Scalar\String_;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -21,15 +19,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*/
|
||||
final class DowngradeDefineArrayConstantRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
|
||||
*/
|
||||
private $argsAnalyzer;
|
||||
public function __construct(ArgsAnalyzer $argsAnalyzer)
|
||||
{
|
||||
$this->argsAnalyzer = $argsAnalyzer;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
|
@ -67,8 +56,7 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkip($funcCall)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg[] $args */
|
||||
$args = $funcCall->args;
|
||||
$args = $funcCall->getArgs();
|
||||
/** @var String_ $arg0 */
|
||||
$arg0 = $args[0]->value;
|
||||
$arg0Value = $arg0->value;
|
||||
|
@ -78,14 +66,13 @@ CODE_SAMPLE
|
|||
}
|
||||
private function shouldSkip(FuncCall $funcCall) : bool
|
||||
{
|
||||
if ($funcCall->isFirstClassCallable()) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->isName($funcCall, 'define')) {
|
||||
return \true;
|
||||
}
|
||||
$args = $funcCall->args;
|
||||
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($args, [0, 1])) {
|
||||
return \true;
|
||||
}
|
||||
/** @var Arg[] $args */
|
||||
$args = $funcCall->getArgs();
|
||||
if (!$args[0]->value instanceof String_) {
|
||||
return \true;
|
||||
}
|
||||
|
|
|
@ -87,13 +87,7 @@ CODE_SAMPLE
|
|||
if (!$this->isName($funcCall, self::DIRNAME)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($funcCall->args[1])) {
|
||||
return null;
|
||||
}
|
||||
if (!$funcCall->args[1] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
return $funcCall->args[1];
|
||||
return $funcCall->getArgs()[1] ?? null;
|
||||
}
|
||||
private function getLevelsRealValue(Arg $levelsArg) : ?int
|
||||
{
|
||||
|
|
|
@ -57,14 +57,11 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($node->args[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->args[0] instanceof Arg) {
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
/** @var Array_ $options */
|
||||
$options = $node->args[0]->value;
|
||||
$options = $node->getArgs()[0]->value;
|
||||
foreach ($options->items as $option) {
|
||||
if (!$option instanceof ArrayItem) {
|
||||
return null;
|
||||
|
@ -88,12 +85,9 @@ CODE_SAMPLE
|
|||
if (!$this->isName($funcCall, 'session_start')) {
|
||||
return \true;
|
||||
}
|
||||
if (!isset($funcCall->args[0])) {
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return \true;
|
||||
}
|
||||
if (!$funcCall->args[0] instanceof Arg) {
|
||||
return \true;
|
||||
}
|
||||
return !$funcCall->args[0]->value instanceof Array_;
|
||||
return !$funcCall->getArgs()[0]->value instanceof Array_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ CODE_SAMPLE
|
|||
if (!$this->isNotDirectlyCallableInPhp5($node->name)) {
|
||||
return null;
|
||||
}
|
||||
$args = \array_merge([new Arg($node->name)], $node->args);
|
||||
$args = \array_merge([new Arg($node->name)], $node->getArgs());
|
||||
return new FuncCall(new Name('call_user_func'), $args);
|
||||
}
|
||||
private function isNotDirectlyCallableInPhp5(Expr $expr) : bool
|
||||
|
|
|
@ -58,7 +58,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
$methodCall = $this->createBindToCall($node);
|
||||
$item1Unpacked = \array_slice($node->args, 1);
|
||||
$item1Unpacked = \array_slice($node->getArgs(), 1);
|
||||
$args = \array_merge([new Arg($methodCall)], $item1Unpacked);
|
||||
return new FuncCall(new Name('call_user_func'), $args);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ CODE_SAMPLE
|
|||
$class = $this->classFromAnonymousFactory->create($className, $node->class);
|
||||
$this->classes[] = $class;
|
||||
$this->namespacedNameDecorator->decorate($class);
|
||||
return new New_(new Name($className), $node->args);
|
||||
return new New_(new Name($className), $node->getArgs());
|
||||
}
|
||||
private function createAnonymousClassName() : string
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp71\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
|
@ -56,16 +55,12 @@ CODE_SAMPLE
|
|||
if (!$this->isName($node, 'is_iterable')) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($node->args[0])) {
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->args[0] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
/** @var mixed $arg */
|
||||
$arg = $node->args[0]->value;
|
||||
$funcCall = $this->nodeFactory->createFuncCall('is_array', [$arg]);
|
||||
$instanceof = new Instanceof_($arg, new FullyQualified('Traversable'));
|
||||
$expr = $node->getArgs()[0]->value;
|
||||
$funcCall = $this->nodeFactory->createFuncCall('is_array', [$expr]);
|
||||
$instanceof = new Instanceof_($expr, new FullyQualified('Traversable'));
|
||||
return new BooleanOr($funcCall, $instanceof);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,14 +67,11 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($node->args[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->args[0] instanceof Arg) {
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
$tempVariable = $this->namedVariableFactory->createVariable($node, 'callable');
|
||||
$expression = new Expression(new Assign($tempVariable, $node->args[0]->value));
|
||||
$expression = new Expression(new Assign($tempVariable, $node->getArgs()[0]->value));
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($expression, $node);
|
||||
$closure = new Closure();
|
||||
$closure->uses[] = new ClosureUse($tempVariable);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\DowngradePhp72\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
|
@ -47,12 +46,9 @@ final class FunctionExistsFunCallAnalyzer
|
|||
}
|
||||
/** @var FuncCall $functionExists */
|
||||
$functionExists = $firstParentIf->cond;
|
||||
if (!isset($functionExists->args[0])) {
|
||||
if (!isset($functionExists->getArgs()[0])) {
|
||||
return \false;
|
||||
}
|
||||
if (!$functionExists->args[0] instanceof Arg) {
|
||||
return \false;
|
||||
}
|
||||
return $this->valueResolver->isValue($functionExists->args[0]->value, $functionName);
|
||||
return $this->valueResolver->isValue($functionExists->getArgs()[0]->value, $functionName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,10 @@ final class BitwiseFlagCleaner
|
|||
} elseif ($bitwiseOr->left instanceof ConstFetch && $this->nodeNameResolver->isName($bitwiseOr->left, $flag)) {
|
||||
$bitwiseOr = $bitwiseOr->right;
|
||||
}
|
||||
if (!$funcCall->args[3] instanceof Arg) {
|
||||
$fourthArg = $funcCall->getArgs()[3] ?? null;
|
||||
if (!$fourthArg instanceof Arg) {
|
||||
return;
|
||||
}
|
||||
$funcCall->args[3]->value = $bitwiseOr;
|
||||
$fourthArg->value = $bitwiseOr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ CODE_SAMPLE
|
|||
$variable = new Variable($this->variableNaming->createCountedValueName('streamIsatty', $scope));
|
||||
$assign = new Assign($variable, $function);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
|
||||
return new FuncCall($variable, $node->args);
|
||||
return new FuncCall($variable, $node->getArgs());
|
||||
}
|
||||
private function createClosure() : Closure
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp73\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Cast\Array_;
|
||||
|
@ -85,13 +84,10 @@ CODE_SAMPLE
|
|||
}
|
||||
private function refactorArrayKeyFirst(FuncCall $funcCall) : ?FuncCall
|
||||
{
|
||||
if (!isset($funcCall->args[0])) {
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$funcCall->args[0] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
$originalArray = $funcCall->args[0]->value;
|
||||
$originalArray = $funcCall->getArgs()[0]->value;
|
||||
$array = $this->resolveCastedArray($originalArray);
|
||||
if ($originalArray !== $array) {
|
||||
$this->addAssignNewVariable($funcCall, $originalArray, $array);
|
||||
|
@ -107,13 +103,10 @@ CODE_SAMPLE
|
|||
}
|
||||
private function refactorArrayKeyLast(FuncCall $funcCall) : ?FuncCall
|
||||
{
|
||||
if (!isset($funcCall->args[0])) {
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$funcCall->args[0] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
$originalArray = $funcCall->args[0]->value;
|
||||
$originalArray = $funcCall->getArgs()[0]->value;
|
||||
$array = $this->resolveCastedArray($originalArray);
|
||||
if ($originalArray !== $array) {
|
||||
$this->addAssignNewVariable($funcCall, $originalArray, $array);
|
||||
|
|
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp73\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
|
@ -46,14 +45,11 @@ CODE_SAMPLE
|
|||
if (!$this->isName($node, 'is_countable')) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($node->args[0])) {
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->args[0] instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
$isArrayFuncCall = $this->nodeFactory->createFuncCall('is_array', $node->args);
|
||||
$instanceof = new Instanceof_($node->args[0]->value, new FullyQualified('Countable'));
|
||||
$isArrayFuncCall = $this->nodeFactory->createFuncCall('is_array', $node->getArgs());
|
||||
$instanceof = new Instanceof_($node->getArgs()[0]->value, new FullyQualified('Countable'));
|
||||
return new BooleanOr($isArrayFuncCall, $instanceof);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,9 @@ CODE_SAMPLE
|
|||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node->getArgs() !== []) {
|
||||
\end($node->args);
|
||||
$lastArgumentPosition = \key($node->args);
|
||||
$last = $node->args[$lastArgumentPosition];
|
||||
\end($node->getArgs());
|
||||
$lastArgumentPosition = \key($node->getArgs());
|
||||
$last = $node->getArgs()[$lastArgumentPosition];
|
||||
if (!$this->followedByCommaAnalyzer->isFollowed($this->file, $last)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ use PhpParser\Node\Expr\ArrayItem;
|
|||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -34,15 +33,6 @@ final class SetCookieOptionsArrayToArgumentsRector extends AbstractRector
|
|||
* @var int
|
||||
*/
|
||||
private $highestIndex = 1;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
|
||||
*/
|
||||
private $argsAnalyzer;
|
||||
public function __construct(ArgsAnalyzer $argsAnalyzer)
|
||||
{
|
||||
$this->argsAnalyzer = $argsAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Convert setcookie option array to arguments', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
|
@ -76,14 +66,11 @@ CODE_SAMPLE
|
|||
if (!$this->isNames($funcCall, ['setcookie', 'setrawcookie'])) {
|
||||
return \true;
|
||||
}
|
||||
$argsCount = \count($funcCall->args);
|
||||
if ($argsCount <= 2) {
|
||||
if (\count($funcCall->getArgs()) < 3) {
|
||||
return \true;
|
||||
}
|
||||
if (!isset($funcCall->args[2])) {
|
||||
return \true;
|
||||
}
|
||||
return !($funcCall->args[2] instanceof Arg && $funcCall->args[2]->value instanceof Array_);
|
||||
$thirdArg = $funcCall->getArgs()[2];
|
||||
return !$thirdArg->value instanceof Array_;
|
||||
}
|
||||
/**
|
||||
* @return Arg[]
|
||||
|
@ -91,19 +78,15 @@ CODE_SAMPLE
|
|||
private function composeNewArgs(FuncCall $funcCall) : array
|
||||
{
|
||||
$this->highestIndex = 1;
|
||||
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1, 2])) {
|
||||
if (\count($funcCall->getArgs()) < 3) {
|
||||
return [];
|
||||
}
|
||||
/** @var Arg $firstArg */
|
||||
$firstArg = $funcCall->args[0];
|
||||
/** @var Arg $secondArg */
|
||||
$secondArg = $funcCall->args[1];
|
||||
$firstArg = $funcCall->getArgs()[0];
|
||||
$secondArg = $funcCall->getArgs()[1];
|
||||
$newArgs = [$firstArg, $secondArg];
|
||||
/** @var Arg $thirdArg */
|
||||
$thirdArg = $funcCall->args[2];
|
||||
$thirdArg = $funcCall->getArgs()[2];
|
||||
/** @var Array_ $optionsArray */
|
||||
$optionsArray = $thirdArg->value;
|
||||
/** @var ArrayItem|null $arrayItem */
|
||||
foreach ($optionsArray->items as $arrayItem) {
|
||||
if (!$arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
|
|
|
@ -99,8 +99,7 @@ CODE_SAMPLE
|
|||
if ($this->shouldSkipFuncCall($node)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg $secondArg */
|
||||
$secondArg = $node->args[1];
|
||||
$secondArg = $node->getArgs()[1];
|
||||
$allowableTagsParam = $secondArg->value;
|
||||
if ($allowableTagsParam instanceof Array_) {
|
||||
// If it is an array, convert it to string
|
||||
|
@ -132,14 +131,11 @@ CODE_SAMPLE
|
|||
if (\count($funcCall->args) < 2) {
|
||||
return \true;
|
||||
}
|
||||
if (!isset($funcCall->args[1])) {
|
||||
return \true;
|
||||
}
|
||||
if (!$funcCall->args[1] instanceof Arg) {
|
||||
if (!isset($funcCall->getArgs()[1])) {
|
||||
return \true;
|
||||
}
|
||||
// Process anything other than String and null (eg: variables, function calls)
|
||||
$allowableTagsParam = $funcCall->args[1]->value;
|
||||
$allowableTagsParam = $funcCall->getArgs()[1]->value;
|
||||
// Skip for string
|
||||
if ($allowableTagsParam instanceof String_) {
|
||||
return \true;
|
||||
|
|
|
@ -15,7 +15,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @changelog https://www.php.net/manual/en/function.number-format.php#refsect1-function.number-format-changelog
|
||||
*
|
||||
* @see Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector\DowngradeNumberFormatNoFourthArgRectorTest
|
||||
* @see \Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector\DowngradeNumberFormatNoFourthArgRectorTest
|
||||
*/
|
||||
final class DowngradeNumberFormatNoFourthArgRector extends AbstractRector
|
||||
{
|
||||
|
|
|
@ -4,31 +4,20 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp80\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\BinaryOp\Identical;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://wiki.php.net/rfc/str_contains
|
||||
*
|
||||
* @see Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector\DowngradeStrContainsRectorTest
|
||||
* @see \Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector\DowngradeStrContainsRectorTest
|
||||
*/
|
||||
final class DowngradeStrContainsRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
|
||||
*/
|
||||
private $argsAnalyzer;
|
||||
public function __construct(ArgsAnalyzer $argsAnalyzer)
|
||||
{
|
||||
$this->argsAnalyzer = $argsAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Replace str_contains() with strpos() !== false', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
|
@ -68,15 +57,11 @@ CODE_SAMPLE
|
|||
if (!$funcCall instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->argsAnalyzer->isArgsInstanceInArgsPositions($funcCall->args, [0, 1])) {
|
||||
if (\count($funcCall->getArgs()) < 2) {
|
||||
return null;
|
||||
}
|
||||
/** @var Arg $firstArg */
|
||||
$firstArg = $funcCall->args[0];
|
||||
$haystack = $firstArg->value;
|
||||
/** @var Arg $secondArg */
|
||||
$secondArg = $funcCall->args[1];
|
||||
$needle = $secondArg->value;
|
||||
$haystack = $funcCall->getArgs()[0]->value;
|
||||
$needle = $funcCall->getArgs()[1]->value;
|
||||
$funcCall = $this->nodeFactory->createFuncCall('strpos', [$haystack, $needle]);
|
||||
if ($node instanceof BooleanNot) {
|
||||
return new Identical($funcCall, $this->nodeFactory->createFalse());
|
||||
|
|
|
@ -58,7 +58,7 @@ CODE_SAMPLE
|
|||
/** @var MutatingScope $scope */
|
||||
$tempVarName = $this->variableNaming->resolveFromNodeWithScopeCountAndFallbackName($node->var, $scope, '_');
|
||||
$variable = new Variable($tempVarName);
|
||||
$called = $node instanceof NullsafeMethodCall ? new MethodCall($variable, $node->name, $node->args) : new PropertyFetch($variable, $node->name);
|
||||
$called = $node instanceof NullsafeMethodCall ? new MethodCall($variable, $node->name, $node->getArgs()) : new PropertyFetch($variable, $node->name);
|
||||
$assign = new Assign($variable, $node->var);
|
||||
return new Ternary($assign, $called, $this->nodeFactory->createNull());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace Rector\DowngradePhp81\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
||||
|
@ -79,13 +78,10 @@ final class ObjectToResourceReturn
|
|||
if (!$this->nodeNameResolver->isName($subNode->name, 'is_resource')) {
|
||||
return \false;
|
||||
}
|
||||
if (!isset($subNode->args[0])) {
|
||||
if (!isset($subNode->getArgs()[0])) {
|
||||
return \false;
|
||||
}
|
||||
if (!$subNode->args[0] instanceof Arg) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($subNode->args[0], $expr);
|
||||
return $this->nodeComparator->areNodesEqual($subNode->getArgs()[0], $expr);
|
||||
});
|
||||
}
|
||||
return \false;
|
||||
|
|
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
$function = $this->createClosure();
|
||||
$expression = new Expression(new Assign($variable, $function));
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($expression, $node);
|
||||
return new FuncCall($variable, $node->args);
|
||||
return new FuncCall($variable, $node->getArgs());
|
||||
}
|
||||
private function createClosure() : Closure
|
||||
{
|
||||
|
|
|
@ -92,7 +92,7 @@ CODE_SAMPLE
|
|||
$function = $this->createClosure();
|
||||
$expression = new Expression(new Assign($variable, $function));
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($expression, $node);
|
||||
return new FuncCall($variable, $node->args);
|
||||
return new FuncCall($variable, $node->getArgs());
|
||||
}
|
||||
private function createClosure() : Closure
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue