mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Updated Rector to commit ce12406878b202f9ceb1506a546e732ab1ca2716
ce12406878
Remove ChangeReadOnlyVariableWithDefaultValueToConstantRector overly complex and risky, better job for PHPStan (#3954)
This commit is contained in:
parent
7117aa039a
commit
eb3e6c221d
|
@ -5,7 +5,6 @@ namespace RectorPrefix202305;
|
|||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector;
|
||||
use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector;
|
||||
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
|
||||
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
|
||||
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
|
||||
|
@ -15,7 +14,6 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->rule(FinalizeClassesWithoutChildrenRector::class);
|
||||
$rectorConfig->rule(ChangeGlobalVariablesToPropertiesRector::class);
|
||||
$rectorConfig->rule(ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class);
|
||||
$rectorConfig->rule(ChangeReadOnlyVariableWithDefaultValueToConstantRector::class);
|
||||
$rectorConfig->rule(PrivatizeLocalGetterToPropertyRector::class);
|
||||
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
|
||||
$rectorConfig->rule(PrivatizeFinalClassMethodRector::class);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 402 Rules Overview
|
||||
# 398 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -6,13 +6,13 @@
|
|||
|
||||
- [Arguments](#arguments) (6)
|
||||
|
||||
- [CodeQuality](#codequality) (75)
|
||||
- [CodeQuality](#codequality) (74)
|
||||
|
||||
- [CodingStyle](#codingstyle) (34)
|
||||
|
||||
- [Compatibility](#compatibility) (1)
|
||||
|
||||
- [DeadCode](#deadcode) (47)
|
||||
- [DeadCode](#deadcode) (46)
|
||||
|
||||
- [DependencyInjection](#dependencyinjection) (2)
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
|||
|
||||
- [Php82](#php82) (3)
|
||||
|
||||
- [Privatization](#privatization) (7)
|
||||
- [Privatization](#privatization) (6)
|
||||
|
||||
- [Removing](#removing) (6)
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
|||
|
||||
- [Strict](#strict) (6)
|
||||
|
||||
- [Transform](#transform) (29)
|
||||
- [Transform](#transform) (28)
|
||||
|
||||
- [TypeDeclaration](#typedeclaration) (40)
|
||||
|
||||
|
@ -725,38 +725,6 @@ Make if conditions more explicit
|
|||
|
||||
<br>
|
||||
|
||||
### ExplicitMethodCallOverMagicGetSetRector
|
||||
|
||||
Replace magic property fetch using `__get()` and `__set()` with existing method get*()/set*() calls
|
||||
|
||||
- class: [`Rector\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector`](../rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php)
|
||||
|
||||
```diff
|
||||
class MagicCallsObject
|
||||
{
|
||||
// adds magic __get() and __set() methods
|
||||
use \Nette\SmartObject;
|
||||
|
||||
private $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run(MagicObject $magicObject)
|
||||
{
|
||||
- return $magicObject->name;
|
||||
+ return $magicObject->getName();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FlipTypeControlToUseExclusiveTypeRector
|
||||
|
||||
Flip type control from null compare to use exclusive instanceof object
|
||||
|
@ -2943,28 +2911,6 @@ Remove duplicated key in defined arrays.
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveDuplicatedInstanceOfRector
|
||||
|
||||
Remove duplicated instanceof in one call
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\BinaryOp\RemoveDuplicatedInstanceOfRector`](../rules/DeadCode/Rector/BinaryOp/RemoveDuplicatedInstanceOfRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run($value)
|
||||
+ public function run($value): void
|
||||
{
|
||||
- $isIt = $value instanceof A || $value instanceof A;
|
||||
- $isIt = $value instanceof A && $value instanceof A;
|
||||
+ $isIt = $value instanceof A;
|
||||
+ $isIt = $value instanceof A;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveEmptyClassMethodRector
|
||||
|
||||
Remove empty class methods not required by parents
|
||||
|
@ -5506,6 +5452,7 @@ Change curly based array and string to square bracket
|
|||
$string = 'test';
|
||||
-echo $string{0};
|
||||
+echo $string[0];
|
||||
|
||||
$array = ['test'];
|
||||
-echo $array{0};
|
||||
+echo $array[0];
|
||||
|
@ -6524,39 +6471,6 @@ Change property with read only status with default value to constant
|
|||
|
||||
<br>
|
||||
|
||||
### ChangeReadOnlyVariableWithDefaultValueToConstantRector
|
||||
|
||||
Change variable with read only status with default value to constant
|
||||
|
||||
- class: [`Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector`](../rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php)
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
+ /**
|
||||
+ * @var string[]
|
||||
+ */
|
||||
+ private const REPLACEMENTS = [
|
||||
+ 'PHPUnit\Framework\TestCase\Notice' => 'expectNotice',
|
||||
+ 'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation',
|
||||
+ ];
|
||||
+
|
||||
public function run()
|
||||
{
|
||||
- $replacements = [
|
||||
- 'PHPUnit\Framework\TestCase\Notice' => 'expectNotice',
|
||||
- 'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation',
|
||||
- ];
|
||||
-
|
||||
- foreach ($replacements as $class => $method) {
|
||||
+ foreach (self::REPLACEMENTS as $class => $method) {
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### FinalizeClassesWithoutChildrenRector
|
||||
|
||||
Finalize every class that has no children
|
||||
|
@ -7774,40 +7688,6 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
<br>
|
||||
|
||||
### GetAndSetToMethodCallRector
|
||||
|
||||
Turns defined `__get`/`__set` to specific method calls.
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Transform\Rector\Assign\GetAndSetToMethodCallRector`](../rules/Transform/Rector/Assign/GetAndSetToMethodCallRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Transform\Rector\Assign\GetAndSetToMethodCallRector;
|
||||
use Rector\Transform\ValueObject\GetAndSetToMethodCall;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(GetAndSetToMethodCallRector::class, [
|
||||
new GetAndSetToMethodCall('SomeContainer', 'addService', 'getService'),
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
$container = new SomeContainer;
|
||||
-$container->someService = $someService;
|
||||
+$container->setService("someService", $someService);
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MergeInterfacesRector
|
||||
|
||||
Merges old interface to a new one, that already has its methods
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\BetterPhpDocParser\PhpDocManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
final class VarAnnotationManipulator
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger)
|
||||
{
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function decorateNodeWithType(Node $node, Type $staticType) : void
|
||||
{
|
||||
if ($staticType instanceof MixedType) {
|
||||
return;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType);
|
||||
}
|
||||
}
|
|
@ -4,18 +4,12 @@ declare (strict_types=1);
|
|||
namespace Rector\PostRector\Collector;
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PostRector\Contract\Collector\NodeCollectorInterface;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
final class PropertyToAddCollector implements NodeCollectorInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<string, ClassConst>>
|
||||
*/
|
||||
private $constantsByClass = [];
|
||||
/**
|
||||
* @var array<string, PropertyMetadata[]>
|
||||
*/
|
||||
|
@ -24,19 +18,13 @@ final class PropertyToAddCollector implements NodeCollectorInterface
|
|||
* @var array<string, array<string, Type|null>>
|
||||
*/
|
||||
private $propertiesWithoutConstructorByClass = [];
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\ChangesReporting\Collector\RectorChangeCollector
|
||||
*/
|
||||
private $rectorChangeCollector;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, RectorChangeCollector $rectorChangeCollector)
|
||||
public function __construct(RectorChangeCollector $rectorChangeCollector)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->rectorChangeCollector = $rectorChangeCollector;
|
||||
}
|
||||
public function isActive() : bool
|
||||
|
@ -44,10 +32,7 @@ final class PropertyToAddCollector implements NodeCollectorInterface
|
|||
if ($this->propertiesByClass !== []) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->propertiesWithoutConstructorByClass !== []) {
|
||||
return \true;
|
||||
}
|
||||
return $this->constantsByClass !== [];
|
||||
return $this->propertiesWithoutConstructorByClass !== [];
|
||||
}
|
||||
public function addPropertyToClass(Class_ $class, PropertyMetadata $propertyMetadata) : void
|
||||
{
|
||||
|
@ -55,12 +40,6 @@ final class PropertyToAddCollector implements NodeCollectorInterface
|
|||
$this->propertiesByClass[$uniqueHash][] = $propertyMetadata;
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($class);
|
||||
}
|
||||
public function addConstantToClass(Class_ $class, ClassConst $classConst) : void
|
||||
{
|
||||
$constantName = $this->nodeNameResolver->getName($classConst);
|
||||
$this->constantsByClass[\spl_object_hash($class)][$constantName] = $classConst;
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($class);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
|
@ -69,14 +48,6 @@ final class PropertyToAddCollector implements NodeCollectorInterface
|
|||
$this->propertiesWithoutConstructorByClass[\spl_object_hash($class)][$propertyName] = $propertyType;
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($class);
|
||||
}
|
||||
/**
|
||||
* @return ClassConst[]
|
||||
*/
|
||||
public function getConstantsByClass(Class_ $class) : array
|
||||
{
|
||||
$classHash = \spl_object_hash($class);
|
||||
return $this->constantsByClass[$classHash] ?? [];
|
||||
}
|
||||
/**
|
||||
* @return PropertyMetadata[]
|
||||
*/
|
||||
|
|
|
@ -62,7 +62,6 @@ final class PropertyAddingPostRector extends \Rector\PostRector\Rector\AbstractP
|
|||
if ($this->classAnalyzer->isAnonymousClass($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->addConstants($node);
|
||||
$this->addProperties($node);
|
||||
$this->addPropertiesWithoutConstructor($node);
|
||||
return $node;
|
||||
|
@ -90,13 +89,6 @@ class SomeClass
|
|||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
private function addConstants(Class_ $class) : void
|
||||
{
|
||||
$constants = $this->propertyToAddCollector->getConstantsByClass($class);
|
||||
foreach ($constants as $constantName => $nodeConst) {
|
||||
$this->classInsertManipulator->addConstantToClass($class, $constantName, $nodeConst);
|
||||
}
|
||||
}
|
||||
private function addProperties(Class_ $class) : void
|
||||
{
|
||||
$propertiesMetadatas = $this->propertyToAddCollector->getPropertiesByClass($class);
|
||||
|
|
|
@ -4,7 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\DeadCode\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
final class ExprUsedInNextNodeAnalyzer
|
||||
{
|
||||
|
@ -23,10 +23,10 @@ final class ExprUsedInNextNodeAnalyzer
|
|||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer;
|
||||
}
|
||||
public function isUsed(Expr $expr) : bool
|
||||
public function isUsed(Variable $variable) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirstNext($expr, function (Node $node) use($expr) : bool {
|
||||
return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr);
|
||||
return (bool) $this->betterNodeFinder->findFirstNext($variable, function (Node $node) use($variable) : bool {
|
||||
return $this->exprUsedInNodeAnalyzer->isUsed($node, $variable);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,13 @@ declare (strict_types=1);
|
|||
namespace Rector\DeadCode\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Include_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
|
||||
use Rector\Core\NodeAnalyzer\CompactFuncCallAnalyzer;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
final class ExprUsedInNodeAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer
|
||||
|
@ -33,31 +26,27 @@ final class ExprUsedInNodeAnalyzer
|
|||
* @var \Rector\Core\Contract\PhpParser\NodePrinterInterface
|
||||
*/
|
||||
private $nodePrinter;
|
||||
public function __construct(NodeComparator $nodeComparator, \Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer $usedVariableNameAnalyzer, CompactFuncCallAnalyzer $compactFuncCallAnalyzer, NodePrinterInterface $nodePrinter)
|
||||
public function __construct(\Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer $usedVariableNameAnalyzer, CompactFuncCallAnalyzer $compactFuncCallAnalyzer, NodePrinterInterface $nodePrinter)
|
||||
{
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
$this->usedVariableNameAnalyzer = $usedVariableNameAnalyzer;
|
||||
$this->compactFuncCallAnalyzer = $compactFuncCallAnalyzer;
|
||||
$this->nodePrinter = $nodePrinter;
|
||||
}
|
||||
public function isUsed(Node $node, Expr $expr) : bool
|
||||
public function isUsed(Node $node, Variable $variable) : bool
|
||||
{
|
||||
if ($node instanceof Include_) {
|
||||
return \true;
|
||||
}
|
||||
// variable as variable variable need mark as used
|
||||
if ($node instanceof Variable && $expr instanceof Variable) {
|
||||
if ($node instanceof Variable) {
|
||||
$print = $this->nodePrinter->print($node);
|
||||
if (\strncmp($print, '${$', \strlen('${$')) === 0) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
if ($node instanceof FuncCall && $expr instanceof Variable) {
|
||||
return $this->compactFuncCallAnalyzer->isInCompact($node, $expr);
|
||||
if ($node instanceof FuncCall) {
|
||||
return $this->compactFuncCallAnalyzer->isInCompact($node, $variable);
|
||||
}
|
||||
if ($expr instanceof Variable) {
|
||||
return $this->usedVariableNameAnalyzer->isVariableNamed($node, $expr);
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($node, $expr);
|
||||
return $this->usedVariableNameAnalyzer->isVariableNamed($node, $variable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Privatization\Naming;
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use RectorPrefix202305\Symfony\Component\String\UnicodeString;
|
||||
|
@ -24,14 +23,6 @@ final class ConstantNaming
|
|||
$propertyName = $this->nodeNameResolver->getName($propertyProperty);
|
||||
return $this->createUnderscoreUppercaseString($propertyName);
|
||||
}
|
||||
public function createFromVariable(Variable $variable) : ?string
|
||||
{
|
||||
$variableName = $this->nodeNameResolver->getName($variable);
|
||||
if ($variableName === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->createUnderscoreUppercaseString($variableName);
|
||||
}
|
||||
private function createUnderscoreUppercaseString(string $propertyName) : string
|
||||
{
|
||||
$propertyNameUnicodeString = new UnicodeString($propertyName);
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Privatization\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\VarAnnotationManipulator;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\NodeManipulator\ClassMethodAssignManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\Privatization\Naming\ConstantNaming;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector\ChangeReadOnlyVariableWithDefaultValueToConstantRectorTest
|
||||
*/
|
||||
final class ChangeReadOnlyVariableWithDefaultValueToConstantRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $addedConstantNames = [];
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\ClassMethodAssignManipulator
|
||||
*/
|
||||
private $classMethodAssignManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\VarAnnotationManipulator
|
||||
*/
|
||||
private $varAnnotationManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PostRector\Collector\PropertyToAddCollector
|
||||
*/
|
||||
private $propertyToAddCollector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Privatization\Naming\ConstantNaming
|
||||
*/
|
||||
private $constantNaming;
|
||||
public function __construct(ClassMethodAssignManipulator $classMethodAssignManipulator, VarAnnotationManipulator $varAnnotationManipulator, PropertyToAddCollector $propertyToAddCollector, ConstantNaming $constantNaming)
|
||||
{
|
||||
$this->classMethodAssignManipulator = $classMethodAssignManipulator;
|
||||
$this->varAnnotationManipulator = $varAnnotationManipulator;
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
$this->constantNaming = $constantNaming;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change variable with read only status with default value to constant', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$replacements = [
|
||||
'PHPUnit\Framework\TestCase\Notice' => 'expectNotice',
|
||||
'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation',
|
||||
];
|
||||
|
||||
foreach ($replacements as $class => $method) {
|
||||
}
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const REPLACEMENTS = [
|
||||
'PHPUnit\Framework\TestCase\Notice' => 'expectNotice',
|
||||
'PHPUnit\Framework\TestCase\Deprecated' => 'expectDeprecation',
|
||||
];
|
||||
|
||||
public function run()
|
||||
{
|
||||
foreach (self::REPLACEMENTS as $class => $method) {
|
||||
}
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$this->addedConstantNames = [];
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
$readOnlyVariableAssignScalarVariables = $this->classMethodAssignManipulator->collectReadyOnlyAssignScalarVariables($classMethod, $node);
|
||||
$this->refactorClassMethod($classMethod, $node, $readOnlyVariableAssignScalarVariables);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $readOnlyVariableAssigns
|
||||
*/
|
||||
private function refactorClassMethod(ClassMethod $classMethod, Class_ $class, array $readOnlyVariableAssigns) : void
|
||||
{
|
||||
foreach ($readOnlyVariableAssigns as $readOnlyVariableAssign) {
|
||||
$variable = $readOnlyVariableAssign->var;
|
||||
// already overridden
|
||||
if (!$variable instanceof Variable) {
|
||||
continue;
|
||||
}
|
||||
$variableName = $this->getName($variable);
|
||||
if ($variableName === null) {
|
||||
continue;
|
||||
}
|
||||
if ($this->isVariableParamName($classMethod, $variableName)) {
|
||||
continue;
|
||||
}
|
||||
$parentAssign = $readOnlyVariableAssign->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentAssign instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
$constantName = $this->constantNaming->createFromVariable($variable);
|
||||
if ($constantName === null) {
|
||||
continue;
|
||||
}
|
||||
if (\in_array($constantName, $this->addedConstantNames, \true)) {
|
||||
continue;
|
||||
}
|
||||
$this->addedConstantNames[] = $constantName;
|
||||
$this->removeNode($readOnlyVariableAssign);
|
||||
$classConst = $this->createPrivateClassConst($variable, $readOnlyVariableAssign->expr);
|
||||
// replace $variable usage in the code with constant
|
||||
$this->propertyToAddCollector->addConstantToClass($class, $classConst);
|
||||
$this->replaceVariableWithClassConstFetch($classMethod, $variableName, $classConst);
|
||||
}
|
||||
}
|
||||
private function createPrivateClassConst(Variable $variable, Expr $expr) : ClassConst
|
||||
{
|
||||
$constantName = $this->constantNaming->createFromVariable($variable);
|
||||
if ($constantName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
$const = new Const_($constantName, $expr);
|
||||
$classConst = new ClassConst([$const]);
|
||||
$classConst->flags = Class_::MODIFIER_PRIVATE;
|
||||
$this->mirrorComments($classConst, $variable);
|
||||
$constantType = $this->getType($classConst->consts[0]->value);
|
||||
$this->varAnnotationManipulator->decorateNodeWithType($classConst, $constantType);
|
||||
return $classConst;
|
||||
}
|
||||
private function replaceVariableWithClassConstFetch(ClassMethod $classMethod, string $variableName, ClassConst $classConst) : void
|
||||
{
|
||||
$constantName = $this->getName($classConst);
|
||||
if ($constantName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
$this->traverseNodesWithCallable($classMethod, function (Node $node) use($variableName, $constantName) : ?ClassConstFetch {
|
||||
if (!$node instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($node, $variableName)) {
|
||||
return null;
|
||||
}
|
||||
// replace with constant fetch
|
||||
return new ClassConstFetch(new Name('self'), new Identifier($constantName));
|
||||
});
|
||||
}
|
||||
private function isVariableParamName(ClassMethod $classMethod, string $variableName) : bool
|
||||
{
|
||||
foreach ($classMethod->getParams() as $param) {
|
||||
if ($this->nodeNameResolver->isName($param->var, $variableName)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'c4b524e77a5eccd387d1ebe5b01ab3ae680049a3';
|
||||
public const PACKAGE_VERSION = 'ce12406878b202f9ceb1506a546e732ab1ca2716';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-24 14:43:55';
|
||||
public const RELEASE_DATE = '2023-05-24 16:04:54';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@ final class RectorKernel
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const CACHE_KEY = 'v26';
|
||||
private const CACHE_KEY = 'v28';
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
|
||||
*/
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\List_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class ArrayDestructVariableFilter
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $variableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
public function filterOut(array $variableAssigns, ClassMethod $classMethod) : array
|
||||
{
|
||||
$arrayDestructionCreatedVariables = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod, function (Node $node) use(&$arrayDestructionCreatedVariables) {
|
||||
if (!$node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->var instanceof Array_ && !$node->var instanceof List_) {
|
||||
return null;
|
||||
}
|
||||
foreach ($node->var->items as $arrayItem) {
|
||||
// empty item
|
||||
if (!$arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
if (!$arrayItem->value instanceof Variable) {
|
||||
continue;
|
||||
}
|
||||
/** @var string $variableName */
|
||||
$variableName = $this->nodeNameResolver->getName($arrayItem->value);
|
||||
$arrayDestructionCreatedVariables[] = $variableName;
|
||||
}
|
||||
});
|
||||
return \array_filter($variableAssigns, function (Assign $assign) use($arrayDestructionCreatedVariables) : bool {
|
||||
return !$this->nodeNameResolver->isNames($assign->var, $arrayDestructionCreatedVariables);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\Property;
|
|||
use PhpParser\Node\Stmt\TraitUse;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
final class ClassInsertManipulator
|
||||
|
@ -26,15 +25,9 @@ final class ClassInsertManipulator
|
|||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(NodeFactory $nodeFactory, NodeNameResolver $nodeNameResolver)
|
||||
public function __construct(NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
|
@ -52,13 +45,6 @@ final class ClassInsertManipulator
|
|||
}
|
||||
$class->stmts[] = $stmt;
|
||||
}
|
||||
public function addConstantToClass(Class_ $class, string $constantName, ClassConst $classConst) : void
|
||||
{
|
||||
if ($this->hasClassConstant($class, $constantName)) {
|
||||
return;
|
||||
}
|
||||
$this->addAsFirstMethod($class, $classConst);
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
* @param Property[] $properties
|
||||
|
@ -133,15 +119,6 @@ final class ClassInsertManipulator
|
|||
}
|
||||
return \false;
|
||||
}
|
||||
private function hasClassConstant(Class_ $class, string $constantName) : bool
|
||||
{
|
||||
foreach ($class->getConstants() as $classConst) {
|
||||
if ($this->nodeNameResolver->isName($classConst, $constantName)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function addTraitUse(Class_ $class, TraitUse $traitUse) : void
|
||||
{
|
||||
foreach (self::BEFORE_TRAIT_TYPES as $type) {
|
||||
|
|
|
@ -3,44 +3,18 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Scalar\Encapsed;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ParameterReflection;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\Util\ArrayChecker;
|
||||
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
final class ClassMethodAssignManipulator
|
||||
{
|
||||
/**
|
||||
* @var array<string, string[]>
|
||||
*/
|
||||
private $alreadyAddedClassMethodNames = [];
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
|
@ -51,66 +25,10 @@ final class ClassMethodAssignManipulator
|
|||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\VariableManipulator
|
||||
*/
|
||||
private $variableManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\ArrayDestructVariableFilter
|
||||
*/
|
||||
private $arrayDestructVariableFilter;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer
|
||||
*/
|
||||
private $exprUsedInNextNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Util\ArrayChecker
|
||||
*/
|
||||
private $arrayChecker;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeFactory $nodeFactory, NodeNameResolver $nodeNameResolver, \Rector\Core\NodeManipulator\VariableManipulator $variableManipulator, NodeComparator $nodeComparator, ReflectionResolver $reflectionResolver, \Rector\Core\NodeManipulator\ArrayDestructVariableFilter $arrayDestructVariableFilter, ExprUsedInNextNodeAnalyzer $exprUsedInNextNodeAnalyzer, ArrayChecker $arrayChecker)
|
||||
public function __construct(NodeFactory $nodeFactory, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->variableManipulator = $variableManipulator;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
$this->arrayDestructVariableFilter = $arrayDestructVariableFilter;
|
||||
$this->exprUsedInNextNodeAnalyzer = $exprUsedInNextNodeAnalyzer;
|
||||
$this->arrayChecker = $arrayChecker;
|
||||
}
|
||||
/**
|
||||
* @return Assign[]
|
||||
*/
|
||||
public function collectReadyOnlyAssignScalarVariables(ClassMethod $classMethod, Class_ $class) : array
|
||||
{
|
||||
$assignsOfScalarOrArrayToVariable = $this->variableManipulator->collectScalarOrArrayAssignsOfVariable($classMethod, $class);
|
||||
// filter out [$value] = $array, array destructing
|
||||
$readOnlyVariableAssigns = $this->arrayDestructVariableFilter->filterOut($assignsOfScalarOrArrayToVariable, $classMethod);
|
||||
$readOnlyVariableAssigns = $this->filterOutReferencedVariables($readOnlyVariableAssigns, $classMethod);
|
||||
$readOnlyVariableAssigns = $this->filterOutMultiAssigns($readOnlyVariableAssigns);
|
||||
$readOnlyVariableAssigns = $this->filterOutForeachVariables($readOnlyVariableAssigns);
|
||||
$readOnlyVariableAssigns = $this->filterOutUsedByEncapsed($readOnlyVariableAssigns);
|
||||
/**
|
||||
* Remove unused variable assign is task of RemoveUnusedVariableAssignRector
|
||||
* so no need to move to constant early
|
||||
*/
|
||||
$readOnlyVariableAssigns = $this->filterOutNeverUsedNext($readOnlyVariableAssigns);
|
||||
return $this->variableManipulator->filterOutChangedVariables($readOnlyVariableAssigns, $classMethod);
|
||||
}
|
||||
public function addParameterAndAssignToMethod(ClassMethod $classMethod, string $name, ?Type $type, Assign $assign) : void
|
||||
{
|
||||
|
@ -122,80 +40,6 @@ final class ClassMethodAssignManipulator
|
|||
$classMethodHash = \spl_object_hash($classMethod);
|
||||
$this->alreadyAddedClassMethodNames[$classMethodHash][] = $name;
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $readOnlyVariableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function filterOutUsedByEncapsed(array $readOnlyVariableAssigns) : array
|
||||
{
|
||||
$callable = function (Assign $readOnlyVariableAssign) : bool {
|
||||
$variable = $readOnlyVariableAssign->var;
|
||||
return !(bool) $this->betterNodeFinder->findFirstNext($readOnlyVariableAssign, function (Node $node) use($variable) : bool {
|
||||
if (!$node instanceof Encapsed) {
|
||||
return \false;
|
||||
}
|
||||
return $this->arrayChecker->doesExist($node->parts, function (Expr $expr) use($variable) : bool {
|
||||
return $this->nodeComparator->areNodesEqual($expr, $variable);
|
||||
});
|
||||
});
|
||||
};
|
||||
return \array_filter($readOnlyVariableAssigns, $callable);
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $readOnlyVariableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function filterOutNeverUsedNext(array $readOnlyVariableAssigns) : array
|
||||
{
|
||||
return \array_filter($readOnlyVariableAssigns, function (Assign $assign) : bool {
|
||||
return $this->exprUsedInNextNodeAnalyzer->isUsed($assign->var);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $variableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function filterOutReferencedVariables(array $variableAssigns, ClassMethod $classMethod) : array
|
||||
{
|
||||
$referencedVariables = $this->collectReferenceVariableNames($classMethod);
|
||||
return \array_filter($variableAssigns, function (Assign $assign) use($referencedVariables) : bool {
|
||||
return !$this->nodeNameResolver->isNames($assign->var, $referencedVariables);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* E.g. $a = $b = $c = '...';
|
||||
*
|
||||
* @param Assign[] $readOnlyVariableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function filterOutMultiAssigns(array $readOnlyVariableAssigns) : array
|
||||
{
|
||||
return \array_filter($readOnlyVariableAssigns, static function (Assign $assign) : bool {
|
||||
$parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE);
|
||||
return !$parentNode instanceof Assign;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $variableAssigns
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function filterOutForeachVariables(array $variableAssigns) : array
|
||||
{
|
||||
foreach ($variableAssigns as $key => $variableAssign) {
|
||||
$foreach = $this->findParentForeach($variableAssign);
|
||||
if (!$foreach instanceof Foreach_) {
|
||||
continue;
|
||||
}
|
||||
if ($this->nodeComparator->areNodesEqual($foreach->valueVar, $variableAssign->var)) {
|
||||
unset($variableAssigns[$key]);
|
||||
continue;
|
||||
}
|
||||
if ($this->nodeComparator->areNodesEqual($foreach->keyVar, $variableAssign->var)) {
|
||||
unset($variableAssigns[$key]);
|
||||
}
|
||||
}
|
||||
return $variableAssigns;
|
||||
}
|
||||
private function hasMethodParameter(ClassMethod $classMethod, string $name) : bool
|
||||
{
|
||||
foreach ($classMethod->params as $param) {
|
||||
|
@ -209,133 +53,4 @@ final class ClassMethodAssignManipulator
|
|||
}
|
||||
return \in_array($name, $this->alreadyAddedClassMethodNames[$classMethodHash], \true);
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function collectReferenceVariableNames(ClassMethod $classMethod) : array
|
||||
{
|
||||
$referencedVariables = [];
|
||||
/** @var Variable[] $variables */
|
||||
$variables = $this->betterNodeFinder->findInstanceOf($classMethod, Variable::class);
|
||||
foreach ($variables as $variable) {
|
||||
$variableName = $this->nodeNameResolver->getName($variable);
|
||||
if ($variableName === 'this') {
|
||||
continue;
|
||||
}
|
||||
if ($variableName === null) {
|
||||
continue;
|
||||
}
|
||||
$parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof Node && $this->isExplicitlyReferenced($parentNode)) {
|
||||
$referencedVariables[] = $variableName;
|
||||
continue;
|
||||
}
|
||||
$argumentPosition = null;
|
||||
if ($parentNode instanceof Arg) {
|
||||
$argumentPosition = $parentNode->getAttribute(AttributeKey::ARGUMENT_POSITION);
|
||||
$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
|
||||
}
|
||||
if (!$parentNode instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
if ($argumentPosition === null) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isCallOrConstructorWithReference($parentNode, $variable, $argumentPosition)) {
|
||||
continue;
|
||||
}
|
||||
$referencedVariables[] = $variableName;
|
||||
}
|
||||
return $referencedVariables;
|
||||
}
|
||||
private function findParentForeach(Assign $assign) : ?Foreach_
|
||||
{
|
||||
/** @var Foreach_|FunctionLike|null $foundNode */
|
||||
$foundNode = $this->betterNodeFinder->findParentByTypes($assign, [Foreach_::class, FunctionLike::class]);
|
||||
if (!$foundNode instanceof Foreach_) {
|
||||
return null;
|
||||
}
|
||||
return $foundNode;
|
||||
}
|
||||
private function isExplicitlyReferenced(Node $node) : bool
|
||||
{
|
||||
if ($node instanceof Arg || $node instanceof ClosureUse || $node instanceof Param) {
|
||||
return $node->byRef;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function isCallOrConstructorWithReference(Node $node, Variable $variable, int $argumentPosition) : bool
|
||||
{
|
||||
if ($this->isMethodCallWithReferencedArgument($node, $variable)) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->isFuncCallWithReferencedArgument($node, $variable)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isConstructorWithReference($node, $argumentPosition);
|
||||
}
|
||||
private function isMethodCallWithReferencedArgument(Node $node, Variable $variable) : bool
|
||||
{
|
||||
if (!$node instanceof MethodCall) {
|
||||
return \false;
|
||||
}
|
||||
$methodReflection = $this->reflectionResolver->resolveMethodReflectionFromMethodCall($node);
|
||||
if (!$methodReflection instanceof MethodReflection) {
|
||||
return \false;
|
||||
}
|
||||
$variableName = $this->nodeNameResolver->getName($variable);
|
||||
foreach ($methodReflection->getVariants() as $parametersAcceptor) {
|
||||
foreach ($parametersAcceptor->getParameters() as $parameterReflection) {
|
||||
if ($parameterReflection->getName() !== $variableName) {
|
||||
continue;
|
||||
}
|
||||
return $parameterReflection->passedByReference()->yes();
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* Matches e.g:
|
||||
* - array_shift($value)
|
||||
* - sort($values)
|
||||
*/
|
||||
private function isFuncCallWithReferencedArgument(Node $node, Variable $variable) : bool
|
||||
{
|
||||
if (!$node instanceof FuncCall) {
|
||||
return \false;
|
||||
}
|
||||
if (!isset($node->getArgs()[0])) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isNames($node, ['array_shift', '*sort'])) {
|
||||
return \false;
|
||||
}
|
||||
// is 1st argument
|
||||
$firstArg = $node->getArgs()[0];
|
||||
return $firstArg->value !== $variable;
|
||||
}
|
||||
private function isConstructorWithReference(Node $node, int $argumentPosition) : bool
|
||||
{
|
||||
if (!$node instanceof New_) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isParameterReferencedInMethodReflection($node, $argumentPosition);
|
||||
}
|
||||
private function isParameterReferencedInMethodReflection(New_ $new, int $argumentPosition) : bool
|
||||
{
|
||||
$methodReflection = $this->reflectionResolver->resolveMethodReflectionFromNew($new);
|
||||
if (!$methodReflection instanceof MethodReflection) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($methodReflection->getVariants() as $parametersAcceptor) {
|
||||
/** @var ParameterReflection $parameterReflection */
|
||||
foreach ($parametersAcceptor->getParameters() as $parameterPosition => $parameterReflection) {
|
||||
if ($parameterPosition !== $argumentPosition) {
|
||||
continue;
|
||||
}
|
||||
return $parameterReflection->passedByReference()->yes();
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,199 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\Encapsed;
|
||||
use PhpParser\Node\Scalar\EncapsedStringPart;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\ReadWrite\Guard\VariableToConstantGuard;
|
||||
final class VariableManipulator
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\AssignManipulator
|
||||
*/
|
||||
private $assignManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\ReadWrite\Guard\VariableToConstantGuard
|
||||
*/
|
||||
private $variableToConstantGuard;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ExprAnalyzer
|
||||
*/
|
||||
private $exprAnalyzer;
|
||||
public function __construct(\Rector\Core\NodeManipulator\AssignManipulator $assignManipulator, BetterNodeFinder $betterNodeFinder, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, VariableToConstantGuard $variableToConstantGuard, NodeComparator $nodeComparator, ExprAnalyzer $exprAnalyzer)
|
||||
{
|
||||
$this->assignManipulator = $assignManipulator;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->variableToConstantGuard = $variableToConstantGuard;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
$this->exprAnalyzer = $exprAnalyzer;
|
||||
}
|
||||
/**
|
||||
* @return Assign[]
|
||||
*/
|
||||
public function collectScalarOrArrayAssignsOfVariable(ClassMethod $classMethod, Class_ $class) : array
|
||||
{
|
||||
$currentClassName = (string) $this->nodeNameResolver->getName($class);
|
||||
$assignsOfArrayToVariable = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->getStmts(), function (Node $node) use(&$assignsOfArrayToVariable, $class, $currentClassName) {
|
||||
if (!$node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if ($this->exprAnalyzer->isDynamicExpr($node->expr)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->hasEncapsedStringPart($node->expr)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isTestCaseExpectedVariable($node->var)) {
|
||||
return null;
|
||||
}
|
||||
if ($node->expr instanceof ConstFetch) {
|
||||
return null;
|
||||
}
|
||||
if ($node->expr instanceof ClassConstFetch && $this->isOutsideClass($node->expr, $class, $currentClassName)) {
|
||||
return null;
|
||||
}
|
||||
$assignsOfArrayToVariable[] = $node;
|
||||
});
|
||||
return $assignsOfArrayToVariable;
|
||||
}
|
||||
/**
|
||||
* @param Assign[] $assignsOfArrayToVariable
|
||||
* @return Assign[]
|
||||
*/
|
||||
public function filterOutChangedVariables(array $assignsOfArrayToVariable, ClassMethod $classMethod) : array
|
||||
{
|
||||
return \array_filter($assignsOfArrayToVariable, function (Assign $assign) use($classMethod) : bool {
|
||||
return $this->isReadOnlyVariable($classMethod, $assign);
|
||||
});
|
||||
}
|
||||
private function isOutsideClass(ClassConstFetch $classConstFetch, Class_ $currentClass, string $currentClassName) : bool
|
||||
{
|
||||
/**
|
||||
* Dynamic class already checked on $this->exprAnalyzer->isDynamicValue() early
|
||||
* @var Name $class
|
||||
*/
|
||||
$class = $classConstFetch->class;
|
||||
if ($this->nodeNameResolver->isName($class, 'self')) {
|
||||
return $currentClass->extends instanceof FullyQualified;
|
||||
}
|
||||
return !$this->nodeNameResolver->isName($class, $currentClassName);
|
||||
}
|
||||
private function hasEncapsedStringPart(Expr $expr) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst($expr, static function (Node $subNode) : bool {
|
||||
return $subNode instanceof Encapsed || $subNode instanceof EncapsedStringPart;
|
||||
});
|
||||
}
|
||||
private function isTestCaseExpectedVariable(Variable $variable) : bool
|
||||
{
|
||||
$classLike = $this->betterNodeFinder->findParentType($variable, ClassLike::class);
|
||||
if (!$classLike instanceof ClassLike) {
|
||||
return \false;
|
||||
}
|
||||
$className = (string) $this->nodeNameResolver->getName($classLike);
|
||||
if (\substr_compare($className, 'Test', -\strlen('Test')) !== 0) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($variable, 'expect*');
|
||||
}
|
||||
/**
|
||||
* Inspiration
|
||||
* @see \Rector\Core\NodeManipulator\PropertyManipulator::isPropertyUsedInReadContext()
|
||||
*/
|
||||
private function isReadOnlyVariable(ClassMethod $classMethod, Assign $assign) : bool
|
||||
{
|
||||
if (!$assign->var instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
$variableUsages = $this->collectVariableUsages($classMethod, $assign->var, $assign);
|
||||
foreach ($variableUsages as $variableUsage) {
|
||||
if ($variableUsage instanceof Arg) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->assignManipulator->isLeftPartOfAssign($variableUsage)) {
|
||||
continue;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
/**
|
||||
* @return Variable[]|Arg[]
|
||||
*/
|
||||
private function collectVariableUsages(ClassMethod $classMethod, Variable $variable, Assign $assign) : array
|
||||
{
|
||||
/** @var Variable[]|Arg[] $variables */
|
||||
$variables = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->getStmts(), function (Node $node) use($variable, $assign, &$variables) : ?int {
|
||||
// skip anonymous classes and inner function
|
||||
if ($node instanceof Class_ || $node instanceof Function_) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
// skip initialization
|
||||
if ($node === $assign) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if ($node instanceof Arg && $node->value instanceof Variable && !$this->variableToConstantGuard->isReadArg($node)) {
|
||||
$variables = [$node];
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
}
|
||||
if (!$node instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if ($this->nodeComparator->areNodesEqual($node, $variable)) {
|
||||
$variables[] = $node;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return $variables;
|
||||
}
|
||||
}
|
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 ComposerAutoloaderInit5d020b628e489ed7fa420d2cee09c72d::getLoader();
|
||||
return ComposerAutoloaderInit971cef4e61efaf671602226c86632e0f::getLoader();
|
||||
|
|
4
vendor/composer/autoload_classmap.php
vendored
4
vendor/composer/autoload_classmap.php
vendored
|
@ -1145,7 +1145,6 @@ return array(
|
|||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PhpDocTagRemover' => $baseDir . '/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTagRemover.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PhpDocTypeChanger' => $baseDir . '/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PropertyDocBlockManipulator' => $baseDir . '/packages/BetterPhpDocParser/PhpDocManipulator/PropertyDocBlockManipulator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\VarAnnotationManipulator' => $baseDir . '/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeFinder\\PhpDocNodeByTypeFinder' => $baseDir . '/packages/BetterPhpDocParser/PhpDocNodeFinder/PhpDocNodeByTypeFinder.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeMapper' => $baseDir . '/packages/BetterPhpDocParser/PhpDocNodeMapper.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\ArrayTypePhpDocNodeVisitor' => $baseDir . '/packages/BetterPhpDocParser/PhpDocNodeVisitor/ArrayTypePhpDocNodeVisitor.php',
|
||||
|
@ -1471,7 +1470,6 @@ return array(
|
|||
'Rector\\Core\\NodeDecorator\\CreatedByRuleDecorator' => $baseDir . '/src/NodeDecorator/CreatedByRuleDecorator.php',
|
||||
'Rector\\Core\\NodeDecorator\\MixPhpHtmlDecorator' => $baseDir . '/src/NodeDecorator/MixPhpHtmlDecorator.php',
|
||||
'Rector\\Core\\NodeDecorator\\PropertyTypeDecorator' => $baseDir . '/src/NodeDecorator/PropertyTypeDecorator.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => $baseDir . '/src/NodeManipulator/ArrayDestructVariableFilter.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => $baseDir . '/src/NodeManipulator/ArrayManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\AssignManipulator' => $baseDir . '/src/NodeManipulator/AssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => $baseDir . '/src/NodeManipulator/BinaryOpManipulator.php',
|
||||
|
@ -1490,7 +1488,6 @@ return array(
|
|||
'Rector\\Core\\NodeManipulator\\PropertyFetchAssignManipulator' => $baseDir . '/src/NodeManipulator/PropertyFetchAssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\PropertyManipulator' => $baseDir . '/src/NodeManipulator/PropertyManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\StmtsManipulator' => $baseDir . '/src/NodeManipulator/StmtsManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\VariableManipulator' => $baseDir . '/src/NodeManipulator/VariableManipulator.php',
|
||||
'Rector\\Core\\NonPhpFile\\NonPhpFileProcessor' => $baseDir . '/src/NonPhpFile/NonPhpFileProcessor.php',
|
||||
'Rector\\Core\\NonPhpFile\\Rector\\RenameClassNonPhpRector' => $baseDir . '/src/NonPhpFile/Rector/RenameClassNonPhpRector.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ClosureTypeToCallReflectionResolver' => $baseDir . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php',
|
||||
|
@ -2386,7 +2383,6 @@ return array(
|
|||
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithConstFetchReplacer' => $baseDir . '/rules/Privatization/NodeReplacer/PropertyFetchWithConstFetchReplacer.php',
|
||||
'Rector\\Privatization\\Rector\\ClassMethod\\PrivatizeFinalClassMethodRector' => $baseDir . '/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\ChangeGlobalVariablesToPropertiesRector' => $baseDir . '/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\ChangeReadOnlyVariableWithDefaultValueToConstantRector' => $baseDir . '/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\FinalizeClassesWithoutChildrenRector' => $baseDir . '/rules/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector.php',
|
||||
'Rector\\Privatization\\Rector\\MethodCall\\PrivatizeLocalGetterToPropertyRector' => $baseDir . '/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php',
|
||||
'Rector\\Privatization\\Rector\\Property\\ChangeReadOnlyPropertyWithDefaultValueToConstantRector' => $baseDir . '/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.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 ComposerAutoloaderInit5d020b628e489ed7fa420d2cee09c72d
|
||||
class ComposerAutoloaderInit971cef4e61efaf671602226c86632e0f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5d020b628e489ed7fa420d2cee09c72d
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5d020b628e489ed7fa420d2cee09c72d', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit971cef4e61efaf671602226c86632e0f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5d020b628e489ed7fa420d2cee09c72d', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit971cef4e61efaf671602226c86632e0f', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit971cef4e61efaf671602226c86632e0f::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit971cef4e61efaf671602226c86632e0f::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
12
vendor/composer/autoload_static.php
vendored
12
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
||||
class ComposerStaticInit971cef4e61efaf671602226c86632e0f
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1387,7 +1387,6 @@ class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
|||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PhpDocTagRemover' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTagRemover.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PhpDocTypeChanger' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\PropertyDocBlockManipulator' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocManipulator/PropertyDocBlockManipulator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocManipulator\\VarAnnotationManipulator' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeFinder\\PhpDocNodeByTypeFinder' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocNodeFinder/PhpDocNodeByTypeFinder.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeMapper' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocNodeMapper.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\ArrayTypePhpDocNodeVisitor' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/PhpDocNodeVisitor/ArrayTypePhpDocNodeVisitor.php',
|
||||
|
@ -1713,7 +1712,6 @@ class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
|||
'Rector\\Core\\NodeDecorator\\CreatedByRuleDecorator' => __DIR__ . '/../..' . '/src/NodeDecorator/CreatedByRuleDecorator.php',
|
||||
'Rector\\Core\\NodeDecorator\\MixPhpHtmlDecorator' => __DIR__ . '/../..' . '/src/NodeDecorator/MixPhpHtmlDecorator.php',
|
||||
'Rector\\Core\\NodeDecorator\\PropertyTypeDecorator' => __DIR__ . '/../..' . '/src/NodeDecorator/PropertyTypeDecorator.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayDestructVariableFilter.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\AssignManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/AssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/BinaryOpManipulator.php',
|
||||
|
@ -1732,7 +1730,6 @@ class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
|||
'Rector\\Core\\NodeManipulator\\PropertyFetchAssignManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/PropertyFetchAssignManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\PropertyManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/PropertyManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\StmtsManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/StmtsManipulator.php',
|
||||
'Rector\\Core\\NodeManipulator\\VariableManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/VariableManipulator.php',
|
||||
'Rector\\Core\\NonPhpFile\\NonPhpFileProcessor' => __DIR__ . '/../..' . '/src/NonPhpFile/NonPhpFileProcessor.php',
|
||||
'Rector\\Core\\NonPhpFile\\Rector\\RenameClassNonPhpRector' => __DIR__ . '/../..' . '/src/NonPhpFile/Rector/RenameClassNonPhpRector.php',
|
||||
'Rector\\Core\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\ClosureTypeToCallReflectionResolver' => __DIR__ . '/../..' . '/src/PHPStan/Reflection/TypeToCallReflectionResolver/ClosureTypeToCallReflectionResolver.php',
|
||||
|
@ -2628,7 +2625,6 @@ class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
|||
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithConstFetchReplacer' => __DIR__ . '/../..' . '/rules/Privatization/NodeReplacer/PropertyFetchWithConstFetchReplacer.php',
|
||||
'Rector\\Privatization\\Rector\\ClassMethod\\PrivatizeFinalClassMethodRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\ChangeGlobalVariablesToPropertiesRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\ChangeReadOnlyVariableWithDefaultValueToConstantRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php',
|
||||
'Rector\\Privatization\\Rector\\Class_\\FinalizeClassesWithoutChildrenRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector.php',
|
||||
'Rector\\Privatization\\Rector\\MethodCall\\PrivatizeLocalGetterToPropertyRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php',
|
||||
'Rector\\Privatization\\Rector\\Property\\ChangeReadOnlyPropertyWithDefaultValueToConstantRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php',
|
||||
|
@ -3102,9 +3098,9 @@ class ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5d020b628e489ed7fa420d2cee09c72d::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit971cef4e61efaf671602226c86632e0f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit971cef4e61efaf671602226c86632e0f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit971cef4e61efaf671602226c86632e0f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user