mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit ebc2e7efa17d9871cc5d9b90a81c41d504a214db
ebc2e7efa1
Add new rule to remove function calls (#3524)
This commit is contained in:
parent
3031f5d544
commit
da7c61a9a9
|
@ -52,7 +52,7 @@
|
|||
|
||||
- [Privatization](#privatization) (7)
|
||||
|
||||
- [Removing](#removing) (5)
|
||||
- [Removing](#removing) (6)
|
||||
|
||||
- [RemovingStatic](#removingstatic) (1)
|
||||
|
||||
|
@ -6942,6 +6942,39 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveFuncCallRector
|
||||
|
||||
Remove function
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Removing\Rector\FuncCall\RemoveFuncCallRector`](../rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
|
||||
'var_dump',
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
-$x = 'something';
|
||||
-var_dump($x);
|
||||
+$x = 'something';
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveInterfacesRector
|
||||
|
||||
Removes interfaces usage from class.
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Removing\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202304\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Removing\Rector\FuncCall\RemoveFuncCallRector\RemoveFuncCallRectorTest
|
||||
*/
|
||||
final class RemoveFuncCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $removedFunctions = [];
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove function', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
$x = 'something';
|
||||
var_dump($x);
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$x = 'something';
|
||||
CODE_SAMPLE
|
||||
, ['var_dump'])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Expression::class];
|
||||
}
|
||||
/**
|
||||
* @param Expression $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$expr = $node->expr;
|
||||
if (!$expr instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
$this->removeNodeIfNeeded($node, $expr);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allString($configuration);
|
||||
$this->removedFunctions = $configuration;
|
||||
}
|
||||
private function removeNodeIfNeeded(Expression $node, FuncCall $expr) : void
|
||||
{
|
||||
foreach ($this->removedFunctions as $removedFunction) {
|
||||
if (!$this->isName($expr->name, $removedFunction)) {
|
||||
continue;
|
||||
}
|
||||
$this->removeNode($node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f604bf38cbb3b1053e0cec78423e82bd6e72b29d';
|
||||
public const PACKAGE_VERSION = 'ebc2e7efa17d9871cc5d9b90a81c41d504a214db';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-04-09 11:39:55';
|
||||
public const RELEASE_DATE = '2023-04-10 15:15:13';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit89fc8dc7efd43be062f97964d6ed76aa::getLoader();
|
||||
return ComposerAutoloaderInit396b82c5df91b4b5cc5ac3eeddf2c8e3::getLoader();
|
||||
|
|
|
@ -2435,6 +2435,7 @@ return array(
|
|||
'Rector\\Removing\\Rector\\Class_\\RemoveParentRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveParentRector.php',
|
||||
'Rector\\Removing\\Rector\\Class_\\RemoveTraitUseRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveTraitUseRector.php',
|
||||
'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallArgRector' => $baseDir . '/rules/Removing/Rector/FuncCall/RemoveFuncCallArgRector.php',
|
||||
'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallRector' => $baseDir . '/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php',
|
||||
'Rector\\Removing\\ValueObject\\ArgumentRemover' => $baseDir . '/rules/Removing/ValueObject/ArgumentRemover.php',
|
||||
'Rector\\Removing\\ValueObject\\RemoveFuncCallArg' => $baseDir . '/rules/Removing/ValueObject/RemoveFuncCallArg.php',
|
||||
'Rector\\Renaming\\Contract\\MethodCallRenameInterface' => $baseDir . '/rules/Renaming/Contract/MethodCallRenameInterface.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit89fc8dc7efd43be062f97964d6ed76aa
|
||||
class ComposerAutoloaderInit396b82c5df91b4b5cc5ac3eeddf2c8e3
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit89fc8dc7efd43be062f97964d6ed76aa
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit89fc8dc7efd43be062f97964d6ed76aa', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit396b82c5df91b4b5cc5ac3eeddf2c8e3', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit89fc8dc7efd43be062f97964d6ed76aa', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit396b82c5df91b4b5cc5ac3eeddf2c8e3', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3::$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 ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa
|
||||
class ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2682,6 +2682,7 @@ class ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa
|
|||
'Rector\\Removing\\Rector\\Class_\\RemoveParentRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveParentRector.php',
|
||||
'Rector\\Removing\\Rector\\Class_\\RemoveTraitUseRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveTraitUseRector.php',
|
||||
'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallArgRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/FuncCall/RemoveFuncCallArgRector.php',
|
||||
'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php',
|
||||
'Rector\\Removing\\ValueObject\\ArgumentRemover' => __DIR__ . '/../..' . '/rules/Removing/ValueObject/ArgumentRemover.php',
|
||||
'Rector\\Removing\\ValueObject\\RemoveFuncCallArg' => __DIR__ . '/../..' . '/rules/Removing/ValueObject/RemoveFuncCallArg.php',
|
||||
'Rector\\Renaming\\Contract\\MethodCallRenameInterface' => __DIR__ . '/../..' . '/rules/Renaming/Contract/MethodCallRenameInterface.php',
|
||||
|
@ -3137,9 +3138,9 @@ class ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit89fc8dc7efd43be062f97964d6ed76aa::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit396b82c5df91b4b5cc5ac3eeddf2c8e3::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue