mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
Updated Rector to commit 541e40b48f
541e40b48f
[IDE-refactoring cleanup] Remove rather custom PassFactoryToEntityRector and NewUniqueObjectToEntityFactoryRector rules, better use PHPStorm there (#783)
This commit is contained in:
parent
0a4e8e9f91
commit
9ba6923f97
|
@ -1,4 +1,4 @@
|
|||
# 477 Rules Overview
|
||||
# 474 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
|||
|
||||
- [Removing](#removing) (6)
|
||||
|
||||
- [RemovingStatic](#removingstatic) (8)
|
||||
- [RemovingStatic](#removingstatic) (5)
|
||||
|
||||
- [Renaming](#renaming) (11)
|
||||
|
||||
|
@ -132,31 +132,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$someObject = new SomeExampleClass;
|
||||
-$someObject->someMethod();
|
||||
+$someObject->someMethod(true);
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
```php
|
||||
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
|
||||
use Rector\Arguments\ValueObject\ArgumentAdder;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(ArgumentAdderRector::class)
|
||||
->call('configure', [[
|
||||
ArgumentAdderRector::ADDED_ARGUMENTS => ValueObjectInliner::inline([
|
||||
new ArgumentAdder('SomeExampleClass', 'someMethod', 0, 'someArgument', true, 'SomeType', null),
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class MyCustomClass extends SomeExampleClass
|
||||
{
|
||||
- public function someMethod()
|
||||
|
@ -9107,177 +9083,6 @@ Change static method and local-only calls to non-static
|
|||
|
||||
<br>
|
||||
|
||||
### NewUniqueObjectToEntityFactoryRector
|
||||
|
||||
Convert new X to new factories
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\RemovingStatic\Rector\Class_\NewUniqueObjectToEntityFactoryRector`](../rules/RemovingStatic/Rector/Class_/NewUniqueObjectToEntityFactoryRector.php)
|
||||
|
||||
```php
|
||||
use Rector\RemovingStatic\Rector\Class_\NewUniqueObjectToEntityFactoryRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(NewUniqueObjectToEntityFactoryRector::class)
|
||||
->call('configure', [[
|
||||
NewUniqueObjectToEntityFactoryRector::TYPES_TO_SERVICES => ['ClassName'],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
+ public function __construct(AnotherClassFactory $anotherClassFactory)
|
||||
+ {
|
||||
+ $this->anotherClassFactory = $anotherClassFactory;
|
||||
+ }
|
||||
+
|
||||
public function run()
|
||||
{
|
||||
- return new AnotherClass;
|
||||
+ return $this->anotherClassFactory->create();
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
public function someFun()
|
||||
{
|
||||
return StaticClass::staticMethod();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### PassFactoryToUniqueObjectRector
|
||||
|
||||
Convert new `X/Static::call()` to factories in entities, pass them via constructor to each other
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\RemovingStatic\Rector\Class_\PassFactoryToUniqueObjectRector`](../rules/RemovingStatic/Rector/Class_/PassFactoryToUniqueObjectRector.php)
|
||||
|
||||
```php
|
||||
use Rector\RemovingStatic\Rector\Class_\PassFactoryToUniqueObjectRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(PassFactoryToUniqueObjectRector::class)
|
||||
->call('configure', [[
|
||||
PassFactoryToUniqueObjectRector::TYPES_TO_SERVICES => ['StaticClass'],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
+ public function __construct(AnotherClassFactory $anotherClassFactory)
|
||||
+ {
|
||||
+ $this->anotherClassFactory = $anotherClassFactory;
|
||||
+ }
|
||||
+
|
||||
public function run()
|
||||
{
|
||||
- return new AnotherClass;
|
||||
+ return $this->anotherClassFactory->create();
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
+ public function __construct(StaticClass $staticClass)
|
||||
+ {
|
||||
+ $this->staticClass = $staticClass;
|
||||
+ }
|
||||
+
|
||||
public function someFun()
|
||||
{
|
||||
- return StaticClass::staticMethod();
|
||||
+ return $this->staticClass->staticMethod();
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+final class AnotherClassFactory
|
||||
+{
|
||||
+ /**
|
||||
+ * @var StaticClass
|
||||
+ */
|
||||
+ private $staticClass;
|
||||
+
|
||||
+ public function __construct(StaticClass $staticClass)
|
||||
+ {
|
||||
+ $this->staticClass = $staticClass;
|
||||
+ }
|
||||
+
|
||||
+ public function create(): AnotherClass
|
||||
+ {
|
||||
+ return new AnotherClass($this->staticClass);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### StaticTypeToSetterInjectionRector
|
||||
|
||||
Changes types to setter injection
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\RemovingStatic\Rector\Class_\StaticTypeToSetterInjectionRector`](../rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php)
|
||||
|
||||
```php
|
||||
use Rector\RemovingStatic\Rector\Class_\StaticTypeToSetterInjectionRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(StaticTypeToSetterInjectionRector::class)
|
||||
->call('configure', [[
|
||||
StaticTypeToSetterInjectionRector::STATIC_TYPES => ['SomeStaticClass'],
|
||||
]]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class CheckoutEntityFactory
|
||||
{
|
||||
+ /**
|
||||
+ * @var SomeStaticClass
|
||||
+ */
|
||||
+ private $someStaticClass;
|
||||
+
|
||||
+ public function setSomeStaticClass(SomeStaticClass $someStaticClass)
|
||||
+ {
|
||||
+ $this->someStaticClass = $someStaticClass;
|
||||
+ }
|
||||
+
|
||||
public function run()
|
||||
{
|
||||
- return SomeStaticClass::go();
|
||||
+ return $this->someStaticClass->go();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Renaming
|
||||
|
||||
### PseudoNamespaceToNamespaceRector
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic\Printer;
|
||||
|
||||
use RectorPrefix20210827\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
|
||||
use Rector\Core\Provider\CurrentFileProvider;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use RectorPrefix20210827\Symplify\SmartFileSystem\SmartFileSystem;
|
||||
final class FactoryClassPrinter
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\Printer\BetterStandardPrinter
|
||||
*/
|
||||
private $betterStandardPrinter;
|
||||
/**
|
||||
* @var \Symplify\SmartFileSystem\SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
/**
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @var \Rector\Core\Provider\CurrentFileProvider
|
||||
*/
|
||||
private $currentFileProvider;
|
||||
public function __construct(\Rector\Core\PhpParser\Printer\BetterStandardPrinter $betterStandardPrinter, \RectorPrefix20210827\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\Provider\CurrentFileProvider $currentFileProvider)
|
||||
{
|
||||
$this->betterStandardPrinter = $betterStandardPrinter;
|
||||
$this->smartFileSystem = $smartFileSystem;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->currentFileProvider = $currentFileProvider;
|
||||
}
|
||||
public function printFactoryForClass(\PhpParser\Node\Stmt\Class_ $factoryClass, \PhpParser\Node\Stmt\Class_ $oldClass) : void
|
||||
{
|
||||
$parentNode = $oldClass->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
|
||||
if ($parentNode instanceof \PhpParser\Node\Stmt\Namespace_) {
|
||||
$newNamespace = clone $parentNode;
|
||||
$newNamespace->stmts = [];
|
||||
$newNamespace->stmts[] = $factoryClass;
|
||||
$nodeToPrint = $newNamespace;
|
||||
} else {
|
||||
$nodeToPrint = $factoryClass;
|
||||
}
|
||||
$factoryClassFilePath = $this->createFactoryClassFilePath($oldClass);
|
||||
$factoryClassContent = $this->betterStandardPrinter->prettyPrintFile([$nodeToPrint]);
|
||||
$this->smartFileSystem->dumpFile($factoryClassFilePath, $factoryClassContent);
|
||||
}
|
||||
private function createFactoryClassFilePath(\PhpParser\Node\Stmt\Class_ $oldClass) : string
|
||||
{
|
||||
$file = $this->currentFileProvider->getFile();
|
||||
$smartFileInfo = $file->getSmartFileInfo();
|
||||
$directoryPath = \RectorPrefix20210827\Nette\Utils\Strings::before($smartFileInfo->getRealPath(), \DIRECTORY_SEPARATOR, -1);
|
||||
$resolvedOldClass = $this->nodeNameResolver->getName($oldClass);
|
||||
if ($resolvedOldClass === null) {
|
||||
throw new \Rector\Core\Exception\ShouldNotHappenException();
|
||||
}
|
||||
$bareClassName = \RectorPrefix20210827\Nette\Utils\Strings::after($resolvedOldClass, '\\', -1) . 'Factory.php';
|
||||
return $directoryPath . \DIRECTORY_SEPARATOR . $bareClassName;
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* Depends on @see PassFactoryToUniqueObjectRector
|
||||
*
|
||||
* @see \Rector\Tests\RemovingStatic\Rector\Class_\PassFactoryToEntityRector\PassFactoryToEntityRectorTest
|
||||
*/
|
||||
final class NewUniqueObjectToEntityFactoryRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const TYPES_TO_SERVICES = 'types_to_services';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const FACTORY = 'Factory';
|
||||
/**
|
||||
* @var ObjectType[]
|
||||
*/
|
||||
private $matchedObjectTypes = [];
|
||||
/**
|
||||
* @var ObjectType[]
|
||||
*/
|
||||
private $serviceObjectTypes = [];
|
||||
/**
|
||||
* @var \Rector\Naming\Naming\PropertyNaming
|
||||
*/
|
||||
private $propertyNaming;
|
||||
/**
|
||||
* @var \Rector\PostRector\Collector\PropertyToAddCollector
|
||||
*/
|
||||
private $propertyToAddCollector;
|
||||
public function __construct(\Rector\Naming\Naming\PropertyNaming $propertyNaming, \Rector\PostRector\Collector\PropertyToAddCollector $propertyToAddCollector)
|
||||
{
|
||||
$this->propertyNaming = $propertyNaming;
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Convert new X to new factories', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return new AnotherClass;
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
public function someFun()
|
||||
{
|
||||
return StaticClass::staticMethod();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function __construct(AnotherClassFactory $anotherClassFactory)
|
||||
{
|
||||
$this->anotherClassFactory = $anotherClassFactory;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->anotherClassFactory->create();
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
public function someFun()
|
||||
{
|
||||
return StaticClass::staticMethod();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::TYPES_TO_SERVICES => ['ClassName']])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : \PhpParser\Node\Stmt\Class_
|
||||
{
|
||||
$this->matchedObjectTypes = [];
|
||||
// collect classes with new to factory in all classes
|
||||
$this->traverseNodesWithCallable($node->stmts, function (\PhpParser\Node $node) : ?MethodCall {
|
||||
if (!$node instanceof \PhpParser\Node\Expr\New_) {
|
||||
return null;
|
||||
}
|
||||
$class = $this->getName($node->class);
|
||||
if ($class === null) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isClassMatching($class)) {
|
||||
return null;
|
||||
}
|
||||
$objectType = new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($class);
|
||||
$this->matchedObjectTypes[] = $objectType;
|
||||
$propertyName = $this->propertyNaming->fqnToVariableName($objectType) . self::FACTORY;
|
||||
$propertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $propertyName);
|
||||
return new \PhpParser\Node\Expr\MethodCall($propertyFetch, 'create', $node->args);
|
||||
});
|
||||
foreach ($this->matchedObjectTypes as $matchedObjectType) {
|
||||
$propertyName = $this->propertyNaming->fqnToVariableName($matchedObjectType) . self::FACTORY;
|
||||
$propertyType = new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($matchedObjectType->getClassName() . self::FACTORY);
|
||||
$propertyMetadata = new \Rector\PostRector\ValueObject\PropertyMetadata($propertyName, $propertyType, \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE);
|
||||
$this->propertyToAddCollector->addPropertyToClass($node, $propertyMetadata);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param array<string, mixed[]> $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$typesToServices = $configuration[self::TYPES_TO_SERVICES] ?? [];
|
||||
foreach ($typesToServices as $typeToService) {
|
||||
$this->serviceObjectTypes[] = new \PHPStan\Type\ObjectType($typeToService);
|
||||
}
|
||||
}
|
||||
private function isClassMatching(string $class) : bool
|
||||
{
|
||||
foreach ($this->serviceObjectTypes as $serviceObjectType) {
|
||||
if ($serviceObjectType->isInstanceOf($class)->yes()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
use Rector\RemovingStatic\Printer\FactoryClassPrinter;
|
||||
use Rector\RemovingStatic\StaticTypesInClassResolver;
|
||||
use Rector\RemovingStatic\UniqueObjectFactoryFactory;
|
||||
use Rector\RemovingStatic\UniqueObjectOrServiceDetector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\RemovingStatic\Rector\Class_\PassFactoryToEntityRector\PassFactoryToEntityRectorTest
|
||||
*/
|
||||
final class PassFactoryToUniqueObjectRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const TYPES_TO_SERVICES = 'types_to_services';
|
||||
/**
|
||||
* @var ObjectType[]
|
||||
*/
|
||||
private $serviceObjectTypes = [];
|
||||
/**
|
||||
* @var \Rector\RemovingStatic\StaticTypesInClassResolver
|
||||
*/
|
||||
private $staticTypesInClassResolver;
|
||||
/**
|
||||
* @var \Rector\Naming\Naming\PropertyNaming
|
||||
*/
|
||||
private $propertyNaming;
|
||||
/**
|
||||
* @var \Rector\RemovingStatic\UniqueObjectOrServiceDetector
|
||||
*/
|
||||
private $uniqueObjectOrServiceDetector;
|
||||
/**
|
||||
* @var \Rector\RemovingStatic\UniqueObjectFactoryFactory
|
||||
*/
|
||||
private $uniqueObjectFactoryFactory;
|
||||
/**
|
||||
* @var \Rector\RemovingStatic\Printer\FactoryClassPrinter
|
||||
*/
|
||||
private $factoryClassPrinter;
|
||||
/**
|
||||
* @var \Rector\PostRector\Collector\PropertyToAddCollector
|
||||
*/
|
||||
private $propertyToAddCollector;
|
||||
public function __construct(\Rector\RemovingStatic\StaticTypesInClassResolver $staticTypesInClassResolver, \Rector\Naming\Naming\PropertyNaming $propertyNaming, \Rector\RemovingStatic\UniqueObjectOrServiceDetector $uniqueObjectOrServiceDetector, \Rector\RemovingStatic\UniqueObjectFactoryFactory $uniqueObjectFactoryFactory, \Rector\RemovingStatic\Printer\FactoryClassPrinter $factoryClassPrinter, \Rector\PostRector\Collector\PropertyToAddCollector $propertyToAddCollector)
|
||||
{
|
||||
$this->staticTypesInClassResolver = $staticTypesInClassResolver;
|
||||
$this->propertyNaming = $propertyNaming;
|
||||
$this->uniqueObjectOrServiceDetector = $uniqueObjectOrServiceDetector;
|
||||
$this->uniqueObjectFactoryFactory = $uniqueObjectFactoryFactory;
|
||||
$this->factoryClassPrinter = $factoryClassPrinter;
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Convert new X/Static::call() to factories in entities, pass them via constructor to each other', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return new AnotherClass;
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
public function someFun()
|
||||
{
|
||||
return StaticClass::staticMethod();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function __construct(AnotherClassFactory $anotherClassFactory)
|
||||
{
|
||||
$this->anotherClassFactory = $anotherClassFactory;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->anotherClassFactory->create();
|
||||
}
|
||||
}
|
||||
|
||||
class AnotherClass
|
||||
{
|
||||
public function __construct(StaticClass $staticClass)
|
||||
{
|
||||
$this->staticClass = $staticClass;
|
||||
}
|
||||
|
||||
public function someFun()
|
||||
{
|
||||
return $this->staticClass->staticMethod();
|
||||
}
|
||||
}
|
||||
|
||||
final class AnotherClassFactory
|
||||
{
|
||||
/**
|
||||
* @var StaticClass
|
||||
*/
|
||||
private $staticClass;
|
||||
|
||||
public function __construct(StaticClass $staticClass)
|
||||
{
|
||||
$this->staticClass = $staticClass;
|
||||
}
|
||||
|
||||
public function create(): AnotherClass
|
||||
{
|
||||
return new AnotherClass($this->staticClass);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::TYPES_TO_SERVICES => ['StaticClass']])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Class_::class, \PhpParser\Node\Expr\StaticCall::class];
|
||||
}
|
||||
/**
|
||||
* @param StaticCall|Class_ $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Class_) {
|
||||
return $this->refactorClass($node);
|
||||
}
|
||||
foreach ($this->serviceObjectTypes as $serviceObjectType) {
|
||||
if (!$this->isObjectType($node->class, $serviceObjectType)) {
|
||||
continue;
|
||||
}
|
||||
// is this object created via new somewhere else? use factory!
|
||||
$variableName = $this->propertyNaming->fqnToVariableName($serviceObjectType);
|
||||
$thisPropertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $variableName);
|
||||
return new \PhpParser\Node\Expr\MethodCall($thisPropertyFetch, $node->name, $node->args);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param array<string, mixed[]> $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$typesToServices = $configuration[self::TYPES_TO_SERVICES] ?? [];
|
||||
foreach ($typesToServices as $typeToService) {
|
||||
$this->serviceObjectTypes[] = new \PHPStan\Type\ObjectType($typeToService);
|
||||
}
|
||||
}
|
||||
private function refactorClass(\PhpParser\Node\Stmt\Class_ $class) : \PhpParser\Node\Stmt\Class_
|
||||
{
|
||||
$staticTypesInClass = $this->staticTypesInClassResolver->collectStaticCallTypeInClass($class, $this->serviceObjectTypes);
|
||||
foreach ($staticTypesInClass as $staticTypeInClass) {
|
||||
$variableName = $this->propertyNaming->fqnToVariableName($staticTypeInClass);
|
||||
$propertyMetadata = new \Rector\PostRector\ValueObject\PropertyMetadata($variableName, $staticTypeInClass, \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE);
|
||||
$this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
|
||||
// is this an object? create factory for it next to this :)
|
||||
if ($this->uniqueObjectOrServiceDetector->isUniqueObject()) {
|
||||
$factoryClass = $this->uniqueObjectFactoryFactory->createFactoryClass($class, $staticTypeInClass);
|
||||
$this->factoryClassPrinter->printFactoryForClass($factoryClass, $class);
|
||||
}
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\RemovingStatic\Rector\Class_\StaticTypeToSetterInjectionRector\StaticTypeToSetterInjectionRectorTest
|
||||
*/
|
||||
final class StaticTypeToSetterInjectionRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const STATIC_TYPES = 'static_types';
|
||||
/**
|
||||
* @var array<class-string|int, class-string>
|
||||
*/
|
||||
private $staticTypes = [];
|
||||
/**
|
||||
* @var \Rector\Naming\Naming\PropertyNaming
|
||||
*/
|
||||
private $propertyNaming;
|
||||
/**
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
public function __construct(\Rector\Naming\Naming\PropertyNaming $propertyNaming, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger)
|
||||
{
|
||||
$this->propertyNaming = $propertyNaming;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
// custom made only for Elasticr
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes types to setter injection', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
final class CheckoutEntityFactory
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return SomeStaticClass::go();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class CheckoutEntityFactory
|
||||
{
|
||||
/**
|
||||
* @var SomeStaticClass
|
||||
*/
|
||||
private $someStaticClass;
|
||||
|
||||
public function setSomeStaticClass(SomeStaticClass $someStaticClass)
|
||||
{
|
||||
$this->someStaticClass = $someStaticClass;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->someStaticClass->go();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::STATIC_TYPES => ['SomeStaticClass']])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Class_::class, \PhpParser\Node\Expr\StaticCall::class];
|
||||
}
|
||||
/**
|
||||
* @param StaticCall|Class_ $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Class_) {
|
||||
return $this->processClass($node);
|
||||
}
|
||||
foreach ($this->staticTypes as $staticType) {
|
||||
$objectType = new \PHPStan\Type\ObjectType($staticType);
|
||||
if (!$this->isObjectType($node->class, $objectType)) {
|
||||
continue;
|
||||
}
|
||||
$variableName = $this->propertyNaming->fqnToVariableName($objectType);
|
||||
$propertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $variableName);
|
||||
return new \PhpParser\Node\Expr\MethodCall($propertyFetch, $node->name, $node->args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @param array<string, array<class-string|int, class-string>> $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$this->staticTypes = $configuration[self::STATIC_TYPES] ?? [];
|
||||
}
|
||||
private function processClass(\PhpParser\Node\Stmt\Class_ $class) : \PhpParser\Node\Stmt\Class_
|
||||
{
|
||||
foreach ($this->staticTypes as $implements => $staticType) {
|
||||
$objectType = new \PHPStan\Type\ObjectType($staticType);
|
||||
$containsEntityFactoryStaticCall = (bool) $this->betterNodeFinder->findFirst($class->stmts, function (\PhpParser\Node $node) use($objectType) : bool {
|
||||
return $this->isEntityFactoryStaticCall($node, $objectType);
|
||||
});
|
||||
if (!$containsEntityFactoryStaticCall) {
|
||||
continue;
|
||||
}
|
||||
if (\is_string($implements)) {
|
||||
$class->implements[] = new \PhpParser\Node\Name\FullyQualified($implements);
|
||||
}
|
||||
$variableName = $this->propertyNaming->fqnToVariableName($objectType);
|
||||
$setEntityFactoryMethod = $this->nodeFactory->createSetterClassMethod($variableName, $objectType);
|
||||
$entityFactoryProperty = $this->nodeFactory->createPrivateProperty($variableName);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($entityFactoryProperty);
|
||||
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $objectType);
|
||||
$class->stmts = \array_merge([$entityFactoryProperty, $setEntityFactoryMethod], $class->stmts);
|
||||
break;
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
private function isEntityFactoryStaticCall(\PhpParser\Node $node, \PHPStan\Type\ObjectType $objectType) : bool
|
||||
{
|
||||
if (!$node instanceof \PhpParser\Node\Expr\StaticCall) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isObjectType($node->class, $objectType);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use RectorPrefix20210827\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class StaticTypesInClassResolver
|
||||
{
|
||||
/**
|
||||
* @var \Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
public function __construct(\RectorPrefix20210827\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser $simpleCallableNodeTraverser, \Rector\NodeTypeResolver\NodeTypeResolver $nodeTypeResolver)
|
||||
{
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
/**
|
||||
* @param ObjectType[] $objectTypes
|
||||
* @return ObjectType[]
|
||||
*/
|
||||
public function collectStaticCallTypeInClass(\PhpParser\Node\Stmt\Class_ $class, array $objectTypes) : array
|
||||
{
|
||||
$staticTypesInClass = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($class->stmts, function (\PhpParser\Node $class) use($objectTypes, &$staticTypesInClass) {
|
||||
if (!$class instanceof \PhpParser\Node\Expr\StaticCall) {
|
||||
return null;
|
||||
}
|
||||
foreach ($objectTypes as $objectType) {
|
||||
if ($this->nodeTypeResolver->isObjectType($class->class, $objectType)) {
|
||||
$staticTypesInClass[] = $objectType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return $staticTypesInClass;
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic;
|
||||
|
||||
use RectorPrefix20210827\Nette\Utils\Strings;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\ClassBuilder;
|
||||
use RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\MethodBuilder;
|
||||
use RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\ParamBuilder;
|
||||
final class UniqueObjectFactoryFactory
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
/**
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @var \Rector\Naming\Naming\PropertyNaming
|
||||
*/
|
||||
private $propertyNaming;
|
||||
/**
|
||||
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||
*/
|
||||
private $staticTypeMapper;
|
||||
/**
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger
|
||||
*/
|
||||
private $phpDocTypeChanger;
|
||||
/**
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
public function __construct(\Rector\Core\PhpParser\Node\NodeFactory $nodeFactory, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Naming\Naming\PropertyNaming $propertyNaming, \Rector\StaticTypeMapper\StaticTypeMapper $staticTypeMapper, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory $phpDocInfoFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->propertyNaming = $propertyNaming;
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->phpDocTypeChanger = $phpDocTypeChanger;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
}
|
||||
public function createFactoryClass(\PhpParser\Node\Stmt\Class_ $class, \PHPStan\Type\ObjectType $objectType) : \PhpParser\Node\Stmt\Class_
|
||||
{
|
||||
$className = $this->nodeNameResolver->getName($class);
|
||||
if ($className === null) {
|
||||
throw new \Rector\Core\Exception\ShouldNotHappenException();
|
||||
}
|
||||
$name = $className . 'Factory';
|
||||
$shortName = $this->resolveClassShortName($name);
|
||||
$factoryClassBuilder = new \RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\ClassBuilder($shortName);
|
||||
$factoryClassBuilder->makeFinal();
|
||||
$properties = $this->createPropertiesFromTypes($objectType);
|
||||
$factoryClassBuilder->addStmts($properties);
|
||||
// constructor
|
||||
$constructorClassMethod = $this->createConstructMethod($objectType);
|
||||
$factoryClassBuilder->addStmt($constructorClassMethod);
|
||||
// create
|
||||
$classMethod = $this->createCreateMethod($class, $className, $properties);
|
||||
$factoryClassBuilder->addStmt($classMethod);
|
||||
return $factoryClassBuilder->getNode();
|
||||
}
|
||||
private function resolveClassShortName(string $name) : string
|
||||
{
|
||||
if (\strpos($name, '\\') !== \false) {
|
||||
return (string) \RectorPrefix20210827\Nette\Utils\Strings::after($name, '\\', -1);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
/**
|
||||
* @return Property[]
|
||||
*/
|
||||
private function createPropertiesFromTypes(\PHPStan\Type\ObjectType $objectType) : array
|
||||
{
|
||||
$properties = [];
|
||||
$properties[] = $this->createPropertyFromObjectType($objectType);
|
||||
return $properties;
|
||||
}
|
||||
private function createConstructMethod(\PHPStan\Type\ObjectType $objectType) : \PhpParser\Node\Stmt\ClassMethod
|
||||
{
|
||||
$propertyName = $this->propertyNaming->fqnToVariableName($objectType);
|
||||
$paramBuilder = new \RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\ParamBuilder($propertyName);
|
||||
$typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($objectType, \Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind::PARAM());
|
||||
if ($typeNode !== null) {
|
||||
$paramBuilder->setType($typeNode);
|
||||
}
|
||||
$params = [$paramBuilder->getNode()];
|
||||
$assigns = $this->createAssignsFromParams($params);
|
||||
$methodBuilder = new \RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\MethodBuilder(\Rector\Core\ValueObject\MethodName::CONSTRUCT);
|
||||
$methodBuilder->makePublic();
|
||||
$methodBuilder->addParams($params);
|
||||
$methodBuilder->addStmts($assigns);
|
||||
return $methodBuilder->getNode();
|
||||
}
|
||||
/**
|
||||
* @param Property[] $properties
|
||||
*/
|
||||
private function createCreateMethod(\PhpParser\Node\Stmt\Class_ $class, string $className, array $properties) : \PhpParser\Node\Stmt\ClassMethod
|
||||
{
|
||||
$new = new \PhpParser\Node\Expr\New_(new \PhpParser\Node\Name\FullyQualified($className));
|
||||
$constructClassMethod = $class->getMethod(\Rector\Core\ValueObject\MethodName::CONSTRUCT);
|
||||
$params = [];
|
||||
if ($constructClassMethod !== null) {
|
||||
foreach ($constructClassMethod->params as $param) {
|
||||
$params[] = $param;
|
||||
$new->args[] = new \PhpParser\Node\Arg($param->var);
|
||||
}
|
||||
}
|
||||
foreach ($properties as $property) {
|
||||
$propertyName = $this->nodeNameResolver->getName($property);
|
||||
$propertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $propertyName);
|
||||
$new->args[] = new \PhpParser\Node\Arg($propertyFetch);
|
||||
}
|
||||
$return = new \PhpParser\Node\Stmt\Return_($new);
|
||||
$methodBuilder = new \RectorPrefix20210827\Symplify\Astral\ValueObject\NodeBuilder\MethodBuilder('create');
|
||||
$methodBuilder->setReturnType(new \PhpParser\Node\Name\FullyQualified($className));
|
||||
$methodBuilder->makePublic();
|
||||
$methodBuilder->addStmt($return);
|
||||
$methodBuilder->addParams($params);
|
||||
return $methodBuilder->getNode();
|
||||
}
|
||||
private function createPropertyFromObjectType(\PHPStan\Type\ObjectType $objectType) : \PhpParser\Node\Stmt\Property
|
||||
{
|
||||
$propertyName = $this->propertyNaming->fqnToVariableName($objectType);
|
||||
$property = $this->nodeFactory->createPrivateProperty($propertyName);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
$this->phpDocTypeChanger->changeVarType($phpDocInfo, $objectType);
|
||||
return $property;
|
||||
}
|
||||
/**
|
||||
* @param Param[] $params
|
||||
*
|
||||
* @return Assign[]
|
||||
*/
|
||||
private function createAssignsFromParams(array $params) : array
|
||||
{
|
||||
$assigns = [];
|
||||
/** @var Param $param */
|
||||
foreach ($params as $param) {
|
||||
$propertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), $param->var->name);
|
||||
$assigns[] = new \PhpParser\Node\Expr\Assign($propertyFetch, new \PhpParser\Node\Expr\Variable($param->var->name));
|
||||
}
|
||||
return $assigns;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\RemovingStatic;
|
||||
|
||||
final class UniqueObjectOrServiceDetector
|
||||
{
|
||||
public function isUniqueObject() : bool
|
||||
{
|
||||
// ideas:
|
||||
// hook in container?
|
||||
// has scalar arguments?
|
||||
// is created by new X in the code? → add "NewNodeCollector"
|
||||
// fallback for now :)
|
||||
return \true;
|
||||
}
|
||||
}
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '130b634b5e348554c3349ed3b3f52fa3d08bfb6e';
|
||||
public const PACKAGE_VERSION = '541e40b48fd80ba38eb1cc17bbcfb28a639a104e';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-08-27 12:45:35';
|
||||
public const RELEASE_DATE = '2021-08-27 14:17:45';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210827\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc::getLoader();
|
||||
return ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa::getLoader();
|
||||
|
|
7
vendor/composer/autoload_classmap.php
vendored
7
vendor/composer/autoload_classmap.php
vendored
|
@ -2851,18 +2851,11 @@ return array(
|
|||
'Rector\\RectorInstaller\\PluginInstaller' => $vendorDir . '/rector/extension-installer/src/PluginInstaller.php',
|
||||
'Rector\\RemovingStatic\\NodeAnalyzer\\StaticCallPresenceAnalyzer' => $baseDir . '/rules/RemovingStatic/NodeAnalyzer/StaticCallPresenceAnalyzer.php',
|
||||
'Rector\\RemovingStatic\\NodeFactory\\SetUpFactory' => $baseDir . '/rules/RemovingStatic/NodeFactory/SetUpFactory.php',
|
||||
'Rector\\RemovingStatic\\Printer\\FactoryClassPrinter' => $baseDir . '/rules/RemovingStatic/Printer/FactoryClassPrinter.php',
|
||||
'Rector\\RemovingStatic\\Rector\\ClassMethod\\LocallyCalledStaticMethodToNonStaticRector' => $baseDir . '/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\DesiredClassTypeToDynamicRector' => $baseDir . '/rules/RemovingStatic/Rector/Class_/DesiredClassTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\NewUniqueObjectToEntityFactoryRector' => $baseDir . '/rules/RemovingStatic/Rector/Class_/NewUniqueObjectToEntityFactoryRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\PassFactoryToUniqueObjectRector' => $baseDir . '/rules/RemovingStatic/Rector/Class_/PassFactoryToUniqueObjectRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\StaticTypeToSetterInjectionRector' => $baseDir . '/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Property\\DesiredPropertyClassMethodTypeToDynamicRector' => $baseDir . '/rules/RemovingStatic/Rector/Property/DesiredPropertyClassMethodTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\StaticCall\\DesiredStaticCallTypeToDynamicRector' => $baseDir . '/rules/RemovingStatic/Rector/StaticCall/DesiredStaticCallTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\StaticPropertyFetch\\DesiredStaticPropertyFetchTypeToDynamicRector' => $baseDir . '/rules/RemovingStatic/Rector/StaticPropertyFetch/DesiredStaticPropertyFetchTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\StaticTypesInClassResolver' => $baseDir . '/rules/RemovingStatic/StaticTypesInClassResolver.php',
|
||||
'Rector\\RemovingStatic\\UniqueObjectFactoryFactory' => $baseDir . '/rules/RemovingStatic/UniqueObjectFactoryFactory.php',
|
||||
'Rector\\RemovingStatic\\UniqueObjectOrServiceDetector' => $baseDir . '/rules/RemovingStatic/UniqueObjectOrServiceDetector.php',
|
||||
'Rector\\Removing\\NodeManipulator\\ComplexNodeRemover' => $baseDir . '/rules/Removing/NodeManipulator/ComplexNodeRemover.php',
|
||||
'Rector\\Removing\\Rector\\ClassMethod\\ArgumentRemoverRector' => $baseDir . '/rules/Removing/Rector/ClassMethod/ArgumentRemoverRector.php',
|
||||
'Rector\\Removing\\Rector\\Class_\\RemoveInterfacesRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveInterfacesRector.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc
|
||||
class ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitced676bac478ca7f538d0185ee84e6bc::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita6ab9ef7a275625464f155554aa7acaa::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitced676bac478ca7f538d0185ee84e6bc::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInita6ab9ef7a275625464f155554aa7acaa::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequireced676bac478ca7f538d0185ee84e6bc($fileIdentifier, $file);
|
||||
composerRequirea6ab9ef7a275625464f155554aa7acaa($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequireced676bac478ca7f538d0185ee84e6bc($fileIdentifier, $file)
|
||||
function composerRequirea6ab9ef7a275625464f155554aa7acaa($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
15
vendor/composer/autoload_static.php
vendored
15
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitced676bac478ca7f538d0185ee84e6bc
|
||||
class ComposerStaticInita6ab9ef7a275625464f155554aa7acaa
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3211,18 +3211,11 @@ class ComposerStaticInitced676bac478ca7f538d0185ee84e6bc
|
|||
'Rector\\RectorInstaller\\PluginInstaller' => __DIR__ . '/..' . '/rector/extension-installer/src/PluginInstaller.php',
|
||||
'Rector\\RemovingStatic\\NodeAnalyzer\\StaticCallPresenceAnalyzer' => __DIR__ . '/../..' . '/rules/RemovingStatic/NodeAnalyzer/StaticCallPresenceAnalyzer.php',
|
||||
'Rector\\RemovingStatic\\NodeFactory\\SetUpFactory' => __DIR__ . '/../..' . '/rules/RemovingStatic/NodeFactory/SetUpFactory.php',
|
||||
'Rector\\RemovingStatic\\Printer\\FactoryClassPrinter' => __DIR__ . '/../..' . '/rules/RemovingStatic/Printer/FactoryClassPrinter.php',
|
||||
'Rector\\RemovingStatic\\Rector\\ClassMethod\\LocallyCalledStaticMethodToNonStaticRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\DesiredClassTypeToDynamicRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/Class_/DesiredClassTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\NewUniqueObjectToEntityFactoryRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/Class_/NewUniqueObjectToEntityFactoryRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\PassFactoryToUniqueObjectRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/Class_/PassFactoryToUniqueObjectRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Class_\\StaticTypeToSetterInjectionRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\Property\\DesiredPropertyClassMethodTypeToDynamicRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/Property/DesiredPropertyClassMethodTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\StaticCall\\DesiredStaticCallTypeToDynamicRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/StaticCall/DesiredStaticCallTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\Rector\\StaticPropertyFetch\\DesiredStaticPropertyFetchTypeToDynamicRector' => __DIR__ . '/../..' . '/rules/RemovingStatic/Rector/StaticPropertyFetch/DesiredStaticPropertyFetchTypeToDynamicRector.php',
|
||||
'Rector\\RemovingStatic\\StaticTypesInClassResolver' => __DIR__ . '/../..' . '/rules/RemovingStatic/StaticTypesInClassResolver.php',
|
||||
'Rector\\RemovingStatic\\UniqueObjectFactoryFactory' => __DIR__ . '/../..' . '/rules/RemovingStatic/UniqueObjectFactoryFactory.php',
|
||||
'Rector\\RemovingStatic\\UniqueObjectOrServiceDetector' => __DIR__ . '/../..' . '/rules/RemovingStatic/UniqueObjectOrServiceDetector.php',
|
||||
'Rector\\Removing\\NodeManipulator\\ComplexNodeRemover' => __DIR__ . '/../..' . '/rules/Removing/NodeManipulator/ComplexNodeRemover.php',
|
||||
'Rector\\Removing\\Rector\\ClassMethod\\ArgumentRemoverRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/ClassMethod/ArgumentRemoverRector.php',
|
||||
'Rector\\Removing\\Rector\\Class_\\RemoveInterfacesRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveInterfacesRector.php',
|
||||
|
@ -3860,9 +3853,9 @@ class ComposerStaticInitced676bac478ca7f538d0185ee84e6bc
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitced676bac478ca7f538d0185ee84e6bc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitced676bac478ca7f538d0185ee84e6bc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitced676bac478ca7f538d0185ee84e6bc::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita6ab9ef7a275625464f155554aa7acaa::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita6ab9ef7a275625464f155554aa7acaa::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita6ab9ef7a275625464f155554aa7acaa::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc', false) && !interface_exists('ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc', false) && !trait_exists('ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\ComposerAutoloaderInitced676bac478ca7f538d0185ee84e6bc');
|
||||
if (!class_exists('ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa', false) && !interface_exists('ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa', false) && !trait_exists('ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\ComposerAutoloaderInita6ab9ef7a275625464f155554aa7acaa');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20210827\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -3311,9 +3311,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210827\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequireced676bac478ca7f538d0185ee84e6bc')) {
|
||||
function composerRequireced676bac478ca7f538d0185ee84e6bc() {
|
||||
return \RectorPrefix20210827\composerRequireced676bac478ca7f538d0185ee84e6bc(...func_get_args());
|
||||
if (!function_exists('composerRequirea6ab9ef7a275625464f155554aa7acaa')) {
|
||||
function composerRequirea6ab9ef7a275625464f155554aa7acaa() {
|
||||
return \RectorPrefix20210827\composerRequirea6ab9ef7a275625464f155554aa7acaa(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user