mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 05:18:18 +01:00
Updated Rector to commit cdde425c2224a1357d70d6784936fe47fe3ffee0
cdde425c22
[Transform] Adds ArrayDimFetchToMethodCallRector rule (#5723)
This commit is contained in:
parent
d3357ab3eb
commit
ae50c0e5a3
@ -56,7 +56,7 @@
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
|
||||
- [Transform](#transform) (24)
|
||||
- [Transform](#transform) (25)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (45)
|
||||
|
||||
@ -5869,6 +5869,21 @@ Add interface by used trait
|
||||
|
||||
<br>
|
||||
|
||||
### ArrayDimFetchToMethodCallRector
|
||||
|
||||
Change array dim fetch to method call
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\ArrayDimFetch\ArrayDimFetchToMethodCallRector`](../rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php)
|
||||
|
||||
```diff
|
||||
-$app['someService'];
|
||||
+$app->make('someService');
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### AttributeKeyToClassConstFetchRector
|
||||
|
||||
Replace key value on specific attribute to class constant
|
||||
|
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\Rector\ArrayDimFetch;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\Transform\ValueObject\ArrayDimFetchToMethodCall;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202403\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\Transform\Rector\ArrayDimFetch\ArrayDimFetchToMethodCallRector\ArrayDimFetchToMethodCallRectorTest
|
||||
*/
|
||||
class ArrayDimFetchToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var ArrayDimFetchToMethodCall[]
|
||||
*/
|
||||
private $arrayDimFetchToMethodCalls;
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change array dim fetch to method call', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
$app['someService'];
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$app->make('someService');
|
||||
CODE_SAMPLE
|
||||
, [new ArrayDimFetchToMethodCall('SomeClass', 'make')])]);
|
||||
}
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ArrayDimFetch::class];
|
||||
}
|
||||
/**
|
||||
* @param ArrayDimFetch $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?MethodCall
|
||||
{
|
||||
if (!$node->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
foreach ($this->arrayDimFetchToMethodCalls as $arrayDimFetchToMethodCall) {
|
||||
if (!$node->dim instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isObjectType($node->var, new ObjectType($arrayDimFetchToMethodCall->getClass()))) {
|
||||
return null;
|
||||
}
|
||||
return new MethodCall($node->var, $arrayDimFetchToMethodCall->getMethod(), [new Arg($node->dim)]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
Assert::allIsInstanceOf($configuration, ArrayDimFetchToMethodCall::class);
|
||||
$this->arrayDimFetchToMethodCalls = $configuration;
|
||||
}
|
||||
}
|
31
rules/Transform/ValueObject/ArrayDimFetchToMethodCall.php
Normal file
31
rules/Transform/ValueObject/ArrayDimFetchToMethodCall.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Transform\ValueObject;
|
||||
|
||||
class ArrayDimFetchToMethodCall
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $class;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $method;
|
||||
public function __construct(string $class, string $method)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->method = $method;
|
||||
}
|
||||
public function getClass() : string
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
public function getMethod() : string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'a844e40a3f84f120866198401f9b3640575f7c06';
|
||||
public const PACKAGE_VERSION = 'cdde425c2224a1357d70d6784936fe47fe3ffee0';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-03-15 14:13:28';
|
||||
public const RELEASE_DATE = '2024-03-15 20:22:53';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
@ -2286,6 +2286,7 @@ return array(
|
||||
'Rector\\Transform\\NodeAnalyzer\\FuncCallStaticCallToMethodCallAnalyzer' => $baseDir . '/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php',
|
||||
'Rector\\Transform\\NodeFactory\\PropertyFetchFactory' => $baseDir . '/rules/Transform/NodeFactory/PropertyFetchFactory.php',
|
||||
'Rector\\Transform\\NodeTypeAnalyzer\\TypeProvidingExprFromClassResolver' => $baseDir . '/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php',
|
||||
'Rector\\Transform\\Rector\\ArrayDimFetch\\ArrayDimFetchToMethodCallRector' => $baseDir . '/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Assign\\PropertyAssignToMethodCallRector' => $baseDir . '/rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Assign\\PropertyFetchToMethodCallRector' => $baseDir . '/rules/Transform/Rector/Assign/PropertyFetchToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Attribute\\AttributeKeyToClassConstFetchRector' => $baseDir . '/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php',
|
||||
@ -2310,6 +2311,7 @@ return array(
|
||||
'Rector\\Transform\\Rector\\StaticCall\\StaticCallToMethodCallRector' => $baseDir . '/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\StaticCall\\StaticCallToNewRector' => $baseDir . '/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php',
|
||||
'Rector\\Transform\\Rector\\String_\\StringToClassConstantRector' => $baseDir . '/rules/Transform/Rector/String_/StringToClassConstantRector.php',
|
||||
'Rector\\Transform\\ValueObject\\ArrayDimFetchToMethodCall' => $baseDir . '/rules/Transform/ValueObject/ArrayDimFetchToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\AttributeKeyToClassConstFetch' => $baseDir . '/rules/Transform/ValueObject/AttributeKeyToClassConstFetch.php',
|
||||
'Rector\\Transform\\ValueObject\\ClassMethodReference' => $baseDir . '/rules/Transform/ValueObject/ClassMethodReference.php',
|
||||
'Rector\\Transform\\ValueObject\\ConstFetchToClassConstFetch' => $baseDir . '/rules/Transform/ValueObject/ConstFetchToClassConstFetch.php',
|
||||
|
2
vendor/composer/autoload_static.php
vendored
2
vendor/composer/autoload_static.php
vendored
@ -2505,6 +2505,7 @@ class ComposerStaticInit1738583af5734d6ba4a4af91c9f317d8
|
||||
'Rector\\Transform\\NodeAnalyzer\\FuncCallStaticCallToMethodCallAnalyzer' => __DIR__ . '/../..' . '/rules/Transform/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php',
|
||||
'Rector\\Transform\\NodeFactory\\PropertyFetchFactory' => __DIR__ . '/../..' . '/rules/Transform/NodeFactory/PropertyFetchFactory.php',
|
||||
'Rector\\Transform\\NodeTypeAnalyzer\\TypeProvidingExprFromClassResolver' => __DIR__ . '/../..' . '/rules/Transform/NodeTypeAnalyzer/TypeProvidingExprFromClassResolver.php',
|
||||
'Rector\\Transform\\Rector\\ArrayDimFetch\\ArrayDimFetchToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Assign\\PropertyAssignToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Assign\\PropertyFetchToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Assign/PropertyFetchToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\Attribute\\AttributeKeyToClassConstFetchRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php',
|
||||
@ -2529,6 +2530,7 @@ class ComposerStaticInit1738583af5734d6ba4a4af91c9f317d8
|
||||
'Rector\\Transform\\Rector\\StaticCall\\StaticCallToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php',
|
||||
'Rector\\Transform\\Rector\\StaticCall\\StaticCallToNewRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/StaticCall/StaticCallToNewRector.php',
|
||||
'Rector\\Transform\\Rector\\String_\\StringToClassConstantRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/String_/StringToClassConstantRector.php',
|
||||
'Rector\\Transform\\ValueObject\\ArrayDimFetchToMethodCall' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/ArrayDimFetchToMethodCall.php',
|
||||
'Rector\\Transform\\ValueObject\\AttributeKeyToClassConstFetch' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/AttributeKeyToClassConstFetch.php',
|
||||
'Rector\\Transform\\ValueObject\\ClassMethodReference' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/ClassMethodReference.php',
|
||||
'Rector\\Transform\\ValueObject\\ConstFetchToClassConstFetch' => __DIR__ . '/../..' . '/rules/Transform/ValueObject/ConstFetchToClassConstFetch.php',
|
||||
|
Loading…
x
Reference in New Issue
Block a user