mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 9e8ed6c33f39aa9d7d859fb39b6f2d0344cdea0d
9e8ed6c33f
Remove SwapFuncCallArgumentsRector as keeps swaping to infinity, use custom rule instead (#4874)
This commit is contained in:
parent
1b7113d724
commit
dd562a4b59
|
@ -1,10 +1,10 @@
|
|||
# 354 Rules Overview
|
||||
# 353 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
## Categories
|
||||
|
||||
- [Arguments](#arguments) (5)
|
||||
- [Arguments](#arguments) (4)
|
||||
|
||||
- [CodeQuality](#codequality) (70)
|
||||
|
||||
|
@ -138,27 +138,6 @@ Replaces defined map of arguments in defined methods and their calls.
|
|||
|
||||
<br>
|
||||
|
||||
### SwapFuncCallArgumentsRector
|
||||
|
||||
Reorder arguments in function calls
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Arguments\Rector\FuncCall\SwapFuncCallArgumentsRector`](../rules/Arguments/Rector/FuncCall/SwapFuncCallArgumentsRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
- return some_function('one', 'two', 'three');
|
||||
+ return some_function('three', 'two', 'one');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## CodeQuality
|
||||
|
||||
### AbsolutizeRequireAndIncludePathRector
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Arguments\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Arguments\ValueObject\SwapFuncCallArguments;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202308\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Arguments\Rector\FuncCall\SwapFuncCallArgumentsRector\SwapFuncCallArgumentsRectorTest
|
||||
*/
|
||||
final class SwapFuncCallArgumentsRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const JUST_SWAPPED = 'just_swapped';
|
||||
/**
|
||||
* @var SwapFuncCallArguments[]
|
||||
*/
|
||||
private $functionArgumentSwaps = [];
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Reorder arguments in function calls', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return some_function('one', 'two', 'three');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return some_function('three', 'two', 'one');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [new SwapFuncCallArguments('some_function', [2, 1, 0])])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?FuncCall
|
||||
{
|
||||
$isJustSwapped = (bool) $node->getAttribute(self::JUST_SWAPPED, \false);
|
||||
if ($isJustSwapped) {
|
||||
return null;
|
||||
}
|
||||
foreach ($this->functionArgumentSwaps as $functionArgumentSwap) {
|
||||
if (!$this->isName($node, $functionArgumentSwap->getFunction())) {
|
||||
continue;
|
||||
}
|
||||
$newArguments = $this->resolveNewArguments($functionArgumentSwap, $node);
|
||||
if ($newArguments === []) {
|
||||
return null;
|
||||
}
|
||||
foreach ($newArguments as $newPosition => $argument) {
|
||||
$node->args[$newPosition] = $argument;
|
||||
}
|
||||
$node->setAttribute(self::JUST_SWAPPED, \true);
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsAOf($configuration, SwapFuncCallArguments::class);
|
||||
$this->functionArgumentSwaps = $configuration;
|
||||
}
|
||||
/**
|
||||
* @return array<int, Node\Arg>
|
||||
*/
|
||||
private function resolveNewArguments(SwapFuncCallArguments $swapFuncCallArguments, FuncCall $funcCall) : array
|
||||
{
|
||||
$newArguments = [];
|
||||
foreach ($swapFuncCallArguments->getOrder() as $oldPosition => $newPosition) {
|
||||
if (!isset($funcCall->args[$oldPosition])) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($funcCall->args[$newPosition])) {
|
||||
continue;
|
||||
}
|
||||
if (!$funcCall->args[$oldPosition] instanceof Arg) {
|
||||
continue;
|
||||
}
|
||||
$newArguments[$newPosition] = $funcCall->args[$oldPosition];
|
||||
}
|
||||
return $newArguments;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Arguments\ValueObject;
|
||||
|
||||
final class SwapFuncCallArguments
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $function;
|
||||
/**
|
||||
* @var array<int, int>
|
||||
* @readonly
|
||||
*/
|
||||
private $order;
|
||||
/**
|
||||
* @param array<int, int> $order
|
||||
*/
|
||||
public function __construct(string $function, array $order)
|
||||
{
|
||||
$this->function = $function;
|
||||
$this->order = $order;
|
||||
}
|
||||
public function getFunction() : string
|
||||
{
|
||||
return $this->function;
|
||||
}
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
public function getOrder() : array
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ use Rector\Php80\ValueObject\AnnotationToAttribute;
|
|||
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
|
||||
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
|
||||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
||||
use Rector\RectorGenerator\Exception\ConfigurationException;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -127,6 +128,9 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->annotationsToAttributes === []) {
|
||||
throw new ConfigurationException(\sprintf('The "%s" rule requires configuration.', self::class));
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
|
||||
if (!$phpDocInfo instanceof PhpDocInfo) {
|
||||
return null;
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '2f38105001867c15fb1b2001767b37566428719f';
|
||||
public const PACKAGE_VERSION = '9e8ed6c33f39aa9d7d859fb39b6f2d0344cdea0d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-28 13:59:30';
|
||||
public const RELEASE_DATE = '2023-08-28 14:43:08';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitb1385f3edb8c9f0571c633e843dbc286::getLoader();
|
||||
return ComposerAutoloaderInit3242d5514b8f61810061aee8e5f52c95::getLoader();
|
||||
|
|
|
@ -933,13 +933,11 @@ return array(
|
|||
'Rector\\Arguments\\Rector\\ClassMethod\\ArgumentAdderRector' => $baseDir . '/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php',
|
||||
'Rector\\Arguments\\Rector\\ClassMethod\\ReplaceArgumentDefaultValueRector' => $baseDir . '/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php',
|
||||
'Rector\\Arguments\\Rector\\FuncCall\\FunctionArgumentDefaultValueReplacerRector' => $baseDir . '/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php',
|
||||
'Rector\\Arguments\\Rector\\FuncCall\\SwapFuncCallArgumentsRector' => $baseDir . '/rules/Arguments/Rector/FuncCall/SwapFuncCallArgumentsRector.php',
|
||||
'Rector\\Arguments\\Rector\\MethodCall\\RemoveMethodCallParamRector' => $baseDir . '/rules/Arguments/Rector/MethodCall/RemoveMethodCallParamRector.php',
|
||||
'Rector\\Arguments\\ValueObject\\ArgumentAdder' => $baseDir . '/rules/Arguments/ValueObject/ArgumentAdder.php',
|
||||
'Rector\\Arguments\\ValueObject\\RemoveMethodCallParam' => $baseDir . '/rules/Arguments/ValueObject/RemoveMethodCallParam.php',
|
||||
'Rector\\Arguments\\ValueObject\\ReplaceArgumentDefaultValue' => $baseDir . '/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php',
|
||||
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => $baseDir . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
|
||||
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => $baseDir . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
|
||||
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => $baseDir . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
|
||||
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => $baseDir . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',
|
||||
'Rector\\BetterPhpDocParser\\Comment\\CommentsMerger' => $baseDir . '/packages/BetterPhpDocParser/Comment/CommentsMerger.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitb1385f3edb8c9f0571c633e843dbc286
|
||||
class ComposerAutoloaderInit3242d5514b8f61810061aee8e5f52c95
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInitb1385f3edb8c9f0571c633e843dbc286
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitb1385f3edb8c9f0571c633e843dbc286', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3242d5514b8f61810061aee8e5f52c95', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitb1385f3edb8c9f0571c633e843dbc286', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3242d5514b8f61810061aee8e5f52c95', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3242d5514b8f61810061aee8e5f52c95::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3242d5514b8f61810061aee8e5f52c95::$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 ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286
|
||||
class ComposerStaticInit3242d5514b8f61810061aee8e5f52c95
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1153,13 +1153,11 @@ class ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286
|
|||
'Rector\\Arguments\\Rector\\ClassMethod\\ArgumentAdderRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php',
|
||||
'Rector\\Arguments\\Rector\\ClassMethod\\ReplaceArgumentDefaultValueRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php',
|
||||
'Rector\\Arguments\\Rector\\FuncCall\\FunctionArgumentDefaultValueReplacerRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/FuncCall/FunctionArgumentDefaultValueReplacerRector.php',
|
||||
'Rector\\Arguments\\Rector\\FuncCall\\SwapFuncCallArgumentsRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/FuncCall/SwapFuncCallArgumentsRector.php',
|
||||
'Rector\\Arguments\\Rector\\MethodCall\\RemoveMethodCallParamRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/MethodCall/RemoveMethodCallParamRector.php',
|
||||
'Rector\\Arguments\\ValueObject\\ArgumentAdder' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/ArgumentAdder.php',
|
||||
'Rector\\Arguments\\ValueObject\\RemoveMethodCallParam' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/RemoveMethodCallParam.php',
|
||||
'Rector\\Arguments\\ValueObject\\ReplaceArgumentDefaultValue' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php',
|
||||
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
|
||||
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
|
||||
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
|
||||
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',
|
||||
'Rector\\BetterPhpDocParser\\Comment\\CommentsMerger' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Comment/CommentsMerger.php',
|
||||
|
@ -2608,9 +2606,9 @@ class ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitb1385f3edb8c9f0571c633e843dbc286::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3242d5514b8f61810061aee8e5f52c95::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3242d5514b8f61810061aee8e5f52c95::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3242d5514b8f61810061aee8e5f52c95::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue