Updated Rector to commit 282ba30ece0c31f03c5a5825c5b9520218c7db8c

282ba30ece Restore RemoveMethodCallParamRector as used (#4244)
This commit is contained in:
Tomas Votruba 2023-06-16 14:39:03 +00:00
parent 03abca7861
commit 901ae42dc7
8 changed files with 201 additions and 14 deletions

View File

@ -1,10 +1,10 @@
# 368 Rules Overview
# 369 Rules Overview
<br>
## Categories
- [Arguments](#arguments) (5)
- [Arguments](#arguments) (6)
- [CodeQuality](#codequality) (72)
@ -140,6 +140,45 @@ return static function (RectorConfig $rectorConfig): void {
<br>
### RemoveMethodCallParamRector
Remove parameter of method call
:wrench: **configure it!**
- class: [`Rector\Arguments\Rector\MethodCall\RemoveMethodCallParamRector`](../rules/Arguments/Rector/MethodCall/RemoveMethodCallParamRector.php)
```php
<?php
declare(strict_types=1);
use Rector\Arguments\Rector\MethodCall\RemoveMethodCallParamRector;
use Rector\Arguments\ValueObject\RemoveMethodCallParam;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RemoveMethodCallParamRector::class, [
new RemoveMethodCallParam('Caller', 'process', 1),
]);
};
```
```diff
final class SomeClass
{
public function run(Caller $caller)
{
- $caller->process(1, 2);
+ $caller->process(1);
}
}
```
<br>
### ReplaceArgumentDefaultValueRector
Replaces defined map of arguments in defined methods and their calls.

View File

@ -0,0 +1,99 @@
<?php
declare (strict_types=1);
namespace Rector\Arguments\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Arguments\ValueObject\RemoveMethodCallParam;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202306\Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\Arguments\Rector\MethodCall\RemoveMethodCallParamRector\RemoveMethodCallParamRectorTest
*/
final class RemoveMethodCallParamRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var RemoveMethodCallParam[]
*/
private $removeMethodCallParams = [];
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove parameter of method call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(Caller $caller)
{
$caller->process(1, 2);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
public function run(Caller $caller)
{
$caller->process(1);
}
}
CODE_SAMPLE
, [new RemoveMethodCallParam('Caller', 'process', 1)])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
$hasChanged = \false;
if ($node->isFirstClassCallable()) {
return null;
}
foreach ($this->removeMethodCallParams as $removeMethodCallParam) {
if (!$this->isName($node->name, $removeMethodCallParam->getMethodName())) {
continue;
}
if (!$this->isCallerObjectType($node, $removeMethodCallParam)) {
continue;
}
$args = $node->getArgs();
if (!isset($args[$removeMethodCallParam->getParamPosition()])) {
continue;
}
unset($node->args[$removeMethodCallParam->getParamPosition()]);
$hasChanged = \true;
}
if (!$hasChanged) {
return null;
}
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
Assert::allIsInstanceOf($configuration, RemoveMethodCallParam::class);
$this->removeMethodCallParams = $configuration;
}
/**
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
*/
private function isCallerObjectType($call, RemoveMethodCallParam $removeMethodCallParam) : bool
{
if ($call instanceof MethodCall) {
return $this->isObjectType($call->var, $removeMethodCallParam->getObjectType());
}
return $this->isObjectType($call->class, $removeMethodCallParam->getObjectType());
}
}

View File

@ -0,0 +1,45 @@
<?php
declare (strict_types=1);
namespace Rector\Arguments\ValueObject;
use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;
final class RemoveMethodCallParam
{
/**
* @readonly
* @var string
*/
private $class;
/**
* @readonly
* @var string
*/
private $methodName;
/**
* @readonly
* @var int
*/
private $paramPosition;
public function __construct(string $class, string $methodName, int $paramPosition)
{
$this->class = $class;
$this->methodName = $methodName;
$this->paramPosition = $paramPosition;
RectorAssert::className($class);
RectorAssert::methodName($methodName);
}
public function getObjectType() : ObjectType
{
return new ObjectType($this->class);
}
public function getMethodName() : string
{
return $this->methodName;
}
public function getParamPosition() : int
{
return $this->paramPosition;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '37b10c6db20c61c11f8d6e17933aaff378b9344d';
public const PACKAGE_VERSION = '282ba30ece0c31f03c5a5825c5b9520218c7db8c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-16 21:31:45';
public const RELEASE_DATE = '2023-06-16 15:35:08';
/**
* @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 ComposerAutoloaderInita0c1b861d9109a56a61a38e5166ebca3::getLoader();
return ComposerAutoloaderInit6126d25e8f1d017aeb10d8e7d38617f6::getLoader();

View File

@ -1272,8 +1272,10 @@ return array(
'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\\Rector\\MethodCall\\SwapMethodCallArgumentsRector' => $baseDir . '/rules/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector.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',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita0c1b861d9109a56a61a38e5166ebca3
class ComposerAutoloaderInit6126d25e8f1d017aeb10d8e7d38617f6
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInita0c1b861d9109a56a61a38e5166ebca3
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita0c1b861d9109a56a61a38e5166ebca3', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6126d25e8f1d017aeb10d8e7d38617f6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInita0c1b861d9109a56a61a38e5166ebca3', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6126d25e8f1d017aeb10d8e7d38617f6', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6::$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 ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3
class ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1523,8 +1523,10 @@ class ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3
'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\\Rector\\MethodCall\\SwapMethodCallArgumentsRector' => __DIR__ . '/../..' . '/rules/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector.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',
@ -3092,9 +3094,9 @@ class ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita0c1b861d9109a56a61a38e5166ebca3::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6126d25e8f1d017aeb10d8e7d38617f6::$classMap;
}, null, ClassLoader::class);
}