mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 20:39:43 +01:00
Updated Rector to commit 937bf3e28b7868d79c4679d8e1e03cfb2e366a42
937bf3e28b
[Transform] Add MethodCallToFuncCallRector (#3391)
This commit is contained in:
parent
7f6ee79741
commit
44595ed746
@ -1,4 +1,4 @@
|
||||
# 413 Rules Overview
|
||||
# 414 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
|
||||
- [Transform](#transform) (34)
|
||||
- [Transform](#transform) (35)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (36)
|
||||
|
||||
@ -8305,6 +8305,45 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
|
||||
<br>
|
||||
|
||||
### MethodCallToFuncCallRector
|
||||
|
||||
Change method call to function call
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\MethodCall\MethodCallToFuncCallRector`](../rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Transform\Rector\MethodCall\MethodCallToFuncCallRector;
|
||||
use Rector\Transform\ValueObject\MethodCallToFuncCall;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(MethodCallToFuncCallRector::class, [
|
||||
new MethodCallToFuncCall('SomeClass', 'render', 'view'),
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
- return $this->render('some_template');
|
||||
+ return view('some_template');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MethodCallToMethodCallRector
|
||||
|
||||
Change method one method from one service to a method call to in another service
|
||||
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Transform\ValueObject\MethodCallToFuncCall;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202302\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Transform\Rector\MethodCall\MethodCallToFuncCallRector\MethodCallToFuncCallRectorTest
|
||||
*/
|
||||
final class MethodCallToFuncCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var MethodCallToFuncCall[]
|
||||
*/
|
||||
private $methodCallsToFuncCalls = [];
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change method call to function call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return $this->render('some_template');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return view('some_template');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [new MethodCallToFuncCall('SomeClass', 'render', 'view')])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
foreach ($this->methodCallsToFuncCalls as $methodCallToFuncCall) {
|
||||
if (!$this->isName($node->name, $methodCallToFuncCall->getMethodName())) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($node->var, new ObjectType($methodCallToFuncCall->getObjectType()))) {
|
||||
continue;
|
||||
}
|
||||
return new FuncCall(new FullyQualified($methodCallToFuncCall->getFunctionName()), $node->getArgs());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsInstanceOf($configuration, MethodCallToFuncCall::class);
|
||||
$this->methodCallsToFuncCalls = $configuration;
|
||||
}
|
||||
}
|
41
rules/Transform/ValueObject/MethodCallToFuncCall.php
Normal file
41
rules/Transform/ValueObject/MethodCallToFuncCall.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\ValueObject;
|
||||
|
||||
final class MethodCallToFuncCall
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $objectType;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $methodName;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $functionName;
|
||||
public function __construct(string $objectType, string $methodName, string $functionName)
|
||||
{
|
||||
$this->objectType = $objectType;
|
||||
$this->methodName = $methodName;
|
||||
$this->functionName = $functionName;
|
||||
}
|
||||
public function getObjectType() : string
|
||||
{
|
||||
return $this->objectType;
|
||||
}
|
||||
public function getMethodName() : string
|
||||
{
|
||||
return $this->methodName;
|
||||
}
|
||||
public function getFunctionName() : string
|
||||
{
|
||||
return $this->functionName;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.15.17';
|
||||
public const PACKAGE_VERSION = '937bf3e28b7868d79c4679d8e1e03cfb2e366a42';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-02-17 19:47:24';
|
||||
public const RELEASE_DATE = '2023-02-19 13:35:05';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -49,7 +49,7 @@ final class FileDiff implements SerializableInterface
|
||||
$this->diff = $diff;
|
||||
$this->diffConsoleFormatted = $diffConsoleFormatted;
|
||||
$this->rectorsWithLineChanges = $rectorsWithLineChanges;
|
||||
Assert::allIsAOf($rectorsWithLineChanges, RectorWithLineChange::class);
|
||||
Assert::allIsInstanceOf($rectorsWithLineChanges, RectorWithLineChange::class);
|
||||
}
|
||||
public function getDiff() : string
|
||||
{
|
||||
|
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 ComposerAutoloaderInite8d170876f7751c4cbe4355e631feff5::getLoader();
|
||||
return ComposerAutoloaderInitd78efb692a2a5257dae172881335b91f::getLoader();
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -2716,6 +2716,7 @@ return array(
|
||||
'Rector\\Transform\\Rector\\FunctionLike\\FileGetContentsAndJsonDecodeToStaticCallRector' => $baseDir . '/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Isset_\\UnsetAndIssetToMethodCallRector' => $baseDir . '/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToAnotherMethodCallWithArgumentsRector' => $baseDir . '/rules/Transform/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToFuncCallRector' => $baseDir . '/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToMethodCallRector' => $baseDir . '/rules/Transform/Rector/MethodCall/MethodCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToPropertyFetchRector' => $baseDir . '/rules/Transform/Rector/MethodCall/MethodCallToPropertyFetchRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToStaticCallRector' => $baseDir . '/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php',
|
||||
@ -2738,6 +2739,7 @@ return array(
|
||||
'Rector\\Transform\\ValueObject\\FuncCallToStaticCall' => $baseDir . '/rules/Transform/ValueObject/FuncCallToStaticCall.php',
|
||||
'Rector\\Transform\\ValueObject\\GetAndSetToMethodCall' => $baseDir . '/rules/Transform/ValueObject/GetAndSetToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToAnotherMethodCallWithArguments' => $baseDir . '/rules/Transform/ValueObject/MethodCallToAnotherMethodCallWithArguments.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToFuncCall' => $baseDir . '/rules/Transform/ValueObject/MethodCallToFuncCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToMethodCall' => $baseDir . '/rules/Transform/ValueObject/MethodCallToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToPropertyFetch' => $baseDir . '/rules/Transform/ValueObject/MethodCallToPropertyFetch.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToStaticCall' => $baseDir . '/rules/Transform/ValueObject/MethodCallToStaticCall.php',
|
||||
|
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 ComposerAutoloaderInite8d170876f7751c4cbe4355e631feff5
|
||||
class ComposerAutoloaderInitd78efb692a2a5257dae172881335b91f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInite8d170876f7751c4cbe4355e631feff5
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite8d170876f7751c4cbe4355e631feff5', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitd78efb692a2a5257dae172881335b91f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite8d170876f7751c4cbe4355e631feff5', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitd78efb692a2a5257dae172881335b91f', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite8d170876f7751c4cbe4355e631feff5::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitd78efb692a2a5257dae172881335b91f::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite8d170876f7751c4cbe4355e631feff5::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitd78efb692a2a5257dae172881335b91f::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite8d170876f7751c4cbe4355e631feff5
|
||||
class ComposerStaticInitd78efb692a2a5257dae172881335b91f
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2963,6 +2963,7 @@ class ComposerStaticInite8d170876f7751c4cbe4355e631feff5
|
||||
'Rector\\Transform\\Rector\\FunctionLike\\FileGetContentsAndJsonDecodeToStaticCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Isset_\\UnsetAndIssetToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToAnotherMethodCallWithArgumentsRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToFuncCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/MethodCall/MethodCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToPropertyFetchRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/MethodCall/MethodCallToPropertyFetchRector.php',
|
||||
'Rector\\Transform\\Rector\\MethodCall\\MethodCallToStaticCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php',
|
||||
@ -2985,6 +2986,7 @@ class ComposerStaticInite8d170876f7751c4cbe4355e631feff5
|
||||
'Rector\\Transform\\ValueObject\\FuncCallToStaticCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/FuncCallToStaticCall.php',
|
||||
'Rector\\Transform\\ValueObject\\GetAndSetToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/GetAndSetToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToAnotherMethodCallWithArguments' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/MethodCallToAnotherMethodCallWithArguments.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToFuncCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/MethodCallToFuncCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/MethodCallToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToPropertyFetch' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/MethodCallToPropertyFetch.php',
|
||||
'Rector\\Transform\\ValueObject\\MethodCallToStaticCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/MethodCallToStaticCall.php',
|
||||
@ -3124,9 +3126,9 @@ class ComposerStaticInite8d170876f7751c4cbe4355e631feff5
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite8d170876f7751c4cbe4355e631feff5::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite8d170876f7751c4cbe4355e631feff5::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite8d170876f7751c4cbe4355e631feff5::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitd78efb692a2a5257dae172881335b91f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitd78efb692a2a5257dae172881335b91f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitd78efb692a2a5257dae172881335b91f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user