mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit ebe8c2ef975c2173e21f027486d00f6ec121c264
ebe8c2ef97
Add constuctor support to ReplaceArgumentDefaultValueRector (#4554)
This commit is contained in:
parent
2b435e3666
commit
b1bb02fc44
@ -10,6 +10,7 @@ use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface;
|
||||
@ -34,7 +35,7 @@ final class ArgumentDefaultValueReplacer
|
||||
$this->valueResolver = $valueResolver;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\FuncCall $node
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\New_ $node
|
||||
*/
|
||||
public function processReplaces($node, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?Node
|
||||
{
|
||||
@ -77,15 +78,16 @@ final class ArgumentDefaultValueReplacer
|
||||
return $classMethod;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall $expr
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\New_ $expr
|
||||
*/
|
||||
private function processArgs($expr, ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue) : ?Expr
|
||||
{
|
||||
$position = $replaceArgumentDefaultValue->getPosition();
|
||||
if (!$expr->args[$position] instanceof Arg) {
|
||||
$particularArg = $expr->getArgs()[$position] ?? null;
|
||||
if (!$particularArg instanceof Arg) {
|
||||
return null;
|
||||
}
|
||||
$argValue = $this->valueResolver->getValue($expr->getArgs()[$position]->value);
|
||||
$argValue = $this->valueResolver->getValue($particularArg->value);
|
||||
if (\is_scalar($replaceArgumentDefaultValue->getValueBefore()) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
|
||||
$expr->args[$position] = $this->normalizeValueToArgument($replaceArgumentDefaultValue->getValueAfter());
|
||||
} elseif (\is_array($replaceArgumentDefaultValue->getValueBefore())) {
|
||||
|
@ -5,12 +5,14 @@ namespace Rector\Arguments\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Arguments\ArgumentDefaultValueReplacer;
|
||||
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
@ -28,7 +30,7 @@ final class ReplaceArgumentDefaultValueRector extends AbstractRector implements
|
||||
/**
|
||||
* @var ReplaceArgumentDefaultValue[]
|
||||
*/
|
||||
private $replacedArguments = [];
|
||||
private $replaceArgumentDefaultValues = [];
|
||||
public function __construct(ArgumentDefaultValueReplacer $argumentDefaultValueReplacer)
|
||||
{
|
||||
$this->argumentDefaultValueReplacer = $argumentDefaultValueReplacer;
|
||||
@ -50,23 +52,26 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class, StaticCall::class, ClassMethod::class];
|
||||
return [MethodCall::class, StaticCall::class, ClassMethod::class, New_::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall|StaticCall|ClassMethod $node
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|null
|
||||
* @param MethodCall|StaticCall|ClassMethod|New_ $node
|
||||
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\New_|null
|
||||
*/
|
||||
public function refactor(Node $node)
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($this->replacedArguments as $replacedArgument) {
|
||||
if (!$this->isName($node->name, $replacedArgument->getMethod())) {
|
||||
if ($node instanceof New_) {
|
||||
return $this->refactorNew($node);
|
||||
}
|
||||
foreach ($this->replaceArgumentDefaultValues as $replaceArgumentDefaultValue) {
|
||||
if (!$this->isName($node->name, $replaceArgumentDefaultValue->getMethod())) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType($node, $replacedArgument->getObjectType())) {
|
||||
if (!$this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType($node, $replaceArgumentDefaultValue->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
$replacedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument);
|
||||
$replacedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replaceArgumentDefaultValue);
|
||||
if ($replacedNode instanceof Node) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
@ -82,6 +87,19 @@ CODE_SAMPLE
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsAOf($configuration, ReplaceArgumentDefaultValue::class);
|
||||
$this->replacedArguments = $configuration;
|
||||
$this->replaceArgumentDefaultValues = $configuration;
|
||||
}
|
||||
private function refactorNew(New_ $new) : ?New_
|
||||
{
|
||||
foreach ($this->replaceArgumentDefaultValues as $replaceArgumentDefaultValue) {
|
||||
if ($replaceArgumentDefaultValue->getMethod() !== MethodName::CONSTRUCT) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($new, $replaceArgumentDefaultValue->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
return $this->argumentDefaultValueReplacer->processReplaces($new, $replaceArgumentDefaultValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'bbe6ed0e1471c4f5394f524c477dfa2ada52d7e5';
|
||||
public const PACKAGE_VERSION = 'ebe8c2ef975c2173e21f027486d00f6ec121c264';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-20 16:01:54';
|
||||
public const RELEASE_DATE = '2023-07-20 16:26:36';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit925c215e3d79a48eb5c15a789982c609::getLoader();
|
||||
return ComposerAutoloaderInit5562e4a91da355c7d134544ab0ab7829::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 ComposerAutoloaderInit925c215e3d79a48eb5c15a789982c609
|
||||
class ComposerAutoloaderInit5562e4a91da355c7d134544ab0ab7829
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit925c215e3d79a48eb5c15a789982c609
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit925c215e3d79a48eb5c15a789982c609', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5562e4a91da355c7d134544ab0ab7829', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit925c215e3d79a48eb5c15a789982c609', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5562e4a91da355c7d134544ab0ab7829', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit925c215e3d79a48eb5c15a789982c609::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5562e4a91da355c7d134544ab0ab7829::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit925c215e3d79a48eb5c15a789982c609::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5562e4a91da355c7d134544ab0ab7829::$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 ComposerStaticInit925c215e3d79a48eb5c15a789982c609
|
||||
class ComposerStaticInit5562e4a91da355c7d134544ab0ab7829
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3023,9 +3023,9 @@ class ComposerStaticInit925c215e3d79a48eb5c15a789982c609
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit925c215e3d79a48eb5c15a789982c609::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit925c215e3d79a48eb5c15a789982c609::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit925c215e3d79a48eb5c15a789982c609::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5562e4a91da355c7d134544ab0ab7829::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5562e4a91da355c7d134544ab0ab7829::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5562e4a91da355c7d134544ab0ab7829::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user