mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit 2c13033108f884fb007ccfa74d29e85cc726b985
2c13033108
Remove UnsetAndIssetToMethodCallRector as unused (#4123)
This commit is contained in:
parent
cdb2d0ed3f
commit
b9a035cc96
@ -1,4 +1,4 @@
|
||||
# 374 Rules Overview
|
||||
# 373 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
|
||||
- [Transform](#transform) (25)
|
||||
- [Transform](#transform) (24)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (40)
|
||||
|
||||
@ -7679,42 +7679,6 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
|
||||
<br>
|
||||
|
||||
### UnsetAndIssetToMethodCallRector
|
||||
|
||||
Turns defined `__isset`/`__unset` calls to specific method calls.
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector`](../rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector;
|
||||
use Rector\Transform\ValueObject\UnsetAndIssetToMethodCall;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(UnsetAndIssetToMethodCallRector::class, [
|
||||
new UnsetAndIssetToMethodCall('SomeContainer', 'hasService', 'removeService'),
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
$container = new SomeContainer;
|
||||
-isset($container["someKey"]);
|
||||
-unset($container["someKey"]);
|
||||
+$container->hasService("someKey");
|
||||
+$container->removeService("someKey");
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### WrapReturnRector
|
||||
|
||||
Wrap return value of specific method
|
||||
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\Rector\Isset_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Isset_;
|
||||
use PhpParser\Node\Stmt\Unset_;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Transform\ValueObject\UnsetAndIssetToMethodCall;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202306\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @deprecated Used for custom project, not practical
|
||||
* @see \Rector\Tests\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector\UnsetAndIssetToMethodCallRectorTest
|
||||
*/
|
||||
final class UnsetAndIssetToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var UnsetAndIssetToMethodCall[]
|
||||
*/
|
||||
private $issetUnsetToMethodCalls = [];
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns defined `__isset`/`__unset` calls to specific method calls.', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
$container = new SomeContainer;
|
||||
isset($container["someKey"]);
|
||||
unset($container["someKey"]);
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$container = new SomeContainer;
|
||||
$container->hasService("someKey");
|
||||
$container->removeService("someKey");
|
||||
CODE_SAMPLE
|
||||
, [new UnsetAndIssetToMethodCall('SomeContainer', 'hasService', 'removeService')])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Isset_::class, Unset_::class];
|
||||
}
|
||||
/**
|
||||
* @param Isset_|Unset_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
foreach ($node->vars as $arrayDimFetch) {
|
||||
if (!$arrayDimFetch instanceof ArrayDimFetch) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->issetUnsetToMethodCalls as $issetUnsetToMethodCall) {
|
||||
if (!$this->isObjectType($arrayDimFetch->var, $issetUnsetToMethodCall->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
$newNode = $this->processArrayDimFetchNode($node, $arrayDimFetch, $issetUnsetToMethodCall);
|
||||
if ($newNode instanceof Node) {
|
||||
return $newNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsAOf($configuration, UnsetAndIssetToMethodCall::class);
|
||||
$this->issetUnsetToMethodCalls = $configuration;
|
||||
}
|
||||
private function processArrayDimFetchNode(Node $node, ArrayDimFetch $arrayDimFetch, UnsetAndIssetToMethodCall $unsetAndIssetToMethodCall) : ?Node
|
||||
{
|
||||
if ($node instanceof Isset_) {
|
||||
if ($unsetAndIssetToMethodCall->getIssetMethodCall() === '') {
|
||||
return null;
|
||||
}
|
||||
return $this->nodeFactory->createMethodCall($arrayDimFetch->var, $unsetAndIssetToMethodCall->getIssetMethodCall(), [$arrayDimFetch->dim]);
|
||||
}
|
||||
if ($node instanceof Unset_) {
|
||||
if ($unsetAndIssetToMethodCall->getUnsedMethodCall() === '') {
|
||||
return null;
|
||||
}
|
||||
return $this->nodeFactory->createMethodCall($arrayDimFetch->var, $unsetAndIssetToMethodCall->getUnsedMethodCall(), [$arrayDimFetch->dim]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\ValueObject;
|
||||
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Validation\RectorAssert;
|
||||
final class UnsetAndIssetToMethodCall
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $issetMethodCall;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $unsedMethodCall;
|
||||
public function __construct(string $type, string $issetMethodCall, string $unsedMethodCall)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->issetMethodCall = $issetMethodCall;
|
||||
$this->unsedMethodCall = $unsedMethodCall;
|
||||
RectorAssert::className($type);
|
||||
RectorAssert::methodName($issetMethodCall);
|
||||
RectorAssert::methodName($unsedMethodCall);
|
||||
}
|
||||
public function getObjectType() : ObjectType
|
||||
{
|
||||
return new ObjectType($this->type);
|
||||
}
|
||||
public function getIssetMethodCall() : string
|
||||
{
|
||||
return $this->issetMethodCall;
|
||||
}
|
||||
public function getUnsedMethodCall() : string
|
||||
{
|
||||
return $this->unsedMethodCall;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f2509fa341525d3939073c5b4513f47ab8362fda';
|
||||
public const PACKAGE_VERSION = '2c13033108f884fb007ccfa74d29e85cc726b985';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-08 22:19:05';
|
||||
public const RELEASE_DATE = '2023-06-08 22:29:53';
|
||||
/**
|
||||
* @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 ComposerAutoloaderIniteba99b089a008fa8685ebae07df294c6::getLoader();
|
||||
return ComposerAutoloaderInitabbd4d71331eac28853a6c6f03eeca65::getLoader();
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -2738,7 +2738,6 @@ return array(
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToMethodCallRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToNewRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php',
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToStaticCallRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Isset_\\UnsetAndIssetToMethodCallRector' => $baseDir . '/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.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',
|
||||
@ -2768,7 +2767,6 @@ return array(
|
||||
'Rector\\Transform\\ValueObject\\StaticCallToMethodCall' => $baseDir . '/rules/Transform/ValueObject/StaticCallToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\StaticCallToNew' => $baseDir . '/rules/Transform/ValueObject/StaticCallToNew.php',
|
||||
'Rector\\Transform\\ValueObject\\StringToClassConstant' => $baseDir . '/rules/Transform/ValueObject/StringToClassConstant.php',
|
||||
'Rector\\Transform\\ValueObject\\UnsetAndIssetToMethodCall' => $baseDir . '/rules/Transform/ValueObject/UnsetAndIssetToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\WrapReturn' => $baseDir . '/rules/Transform/ValueObject/WrapReturn.php',
|
||||
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\ConstructorAssignDetector' => $baseDir . '/rules/TypeDeclaration/AlreadyAssignDetector/ConstructorAssignDetector.php',
|
||||
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\NullTypeAssignDetector' => $baseDir . '/rules/TypeDeclaration/AlreadyAssignDetector/NullTypeAssignDetector.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 ComposerAutoloaderIniteba99b089a008fa8685ebae07df294c6
|
||||
class ComposerAutoloaderInitabbd4d71331eac28853a6c6f03eeca65
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderIniteba99b089a008fa8685ebae07df294c6
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderIniteba99b089a008fa8685ebae07df294c6', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitabbd4d71331eac28853a6c6f03eeca65', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderIniteba99b089a008fa8685ebae07df294c6', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitabbd4d71331eac28853a6c6f03eeca65', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticIniteba99b089a008fa8685ebae07df294c6::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticIniteba99b089a008fa8685ebae07df294c6::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65::$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 ComposerStaticIniteba99b089a008fa8685ebae07df294c6
|
||||
class ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -2989,7 +2989,6 @@ class ComposerStaticIniteba99b089a008fa8685ebae07df294c6
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToNewRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php',
|
||||
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToStaticCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Isset_\\UnsetAndIssetToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Isset_/UnsetAndIssetToMethodCallRector.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',
|
||||
@ -3019,7 +3018,6 @@ class ComposerStaticIniteba99b089a008fa8685ebae07df294c6
|
||||
'Rector\\Transform\\ValueObject\\StaticCallToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StaticCallToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\StaticCallToNew' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StaticCallToNew.php',
|
||||
'Rector\\Transform\\ValueObject\\StringToClassConstant' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/StringToClassConstant.php',
|
||||
'Rector\\Transform\\ValueObject\\UnsetAndIssetToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/UnsetAndIssetToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\WrapReturn' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/WrapReturn.php',
|
||||
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\ConstructorAssignDetector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/AlreadyAssignDetector/ConstructorAssignDetector.php',
|
||||
'Rector\\TypeDeclaration\\AlreadyAssignDetector\\NullTypeAssignDetector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/AlreadyAssignDetector/NullTypeAssignDetector.php',
|
||||
@ -3144,9 +3142,9 @@ class ComposerStaticIniteba99b089a008fa8685ebae07df294c6
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticIniteba99b089a008fa8685ebae07df294c6::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticIniteba99b089a008fa8685ebae07df294c6::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticIniteba99b089a008fa8685ebae07df294c6::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitabbd4d71331eac28853a6c6f03eeca65::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user