[Generic] specialize generic rules (#5355)

This commit is contained in:
Tomas Votruba 2021-01-29 01:29:12 +01:00 committed by GitHub
parent 34c0f08969
commit 1f61ef7160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 366 additions and 719 deletions

View File

@ -8,8 +8,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ActionInjectionToConstructorInjectionRector::class);
$services->set(ReplaceVariableByPropertyFetchRector::class);
};

View File

@ -5,9 +5,8 @@ declare(strict_types=1);
use Rector\CakePHP\Rector\MethodCall\ModalToGetSetRector;
use Rector\CakePHP\ValueObject\ModalToGetSet;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\Rector\ClassMethod\NormalToFluentRector;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Generic\ValueObject\NormalToFluent;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -16,6 +15,7 @@ use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -3,12 +3,12 @@
declare(strict_types=1);
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\NetteToSymfony\Rector\MethodCall\WrapTransParameterNameRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -2,11 +2,11 @@
declare(strict_types=1);
use Rector\Generic\Rector\FuncCall\FuncCallToNewRector;
use Rector\Laravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use Rector\Laravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\FuncCall\ArgumentFuncCallToMethodCallRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall;
use Rector\Transform\ValueObject\ArrayFuncCallToMethodCall;
@ -176,7 +176,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]),
]]);
$services->set(FuncCallToNewRector::class)->call('configure', [[
FuncCallToNewRector::FUNCTION_TO_NEW => [
FuncCallToNewRector::FUNCTIONS_TO_NEWS => [
'collect' => 'Illuminate\Support\Collection',
],
]]);

View File

@ -3,10 +3,10 @@
declare(strict_types=1);
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -5,15 +5,15 @@ declare(strict_types=1);
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Generic\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector;
use Rector\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector;
use Rector\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector;
use Rector\Laravel\Rector\New_\AddGuardToLoginEventRector;
use Rector\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -4,9 +4,8 @@ declare(strict_types=1);
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
@ -15,6 +14,7 @@ use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\Transform\Rector\Expression\MethodCallToReturnRector;
use Rector\Transform\ValueObject\MethodCallToReturn;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

20
config/set/nette-24.php Normal file
View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
use Rector\Generic\Rector\Class_\ParentClassToTraitsRector;
use Rector\Generic\ValueObject\ParentClassToTraits;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
// @see https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ParentClassToTraitsRector::class)
->call('configure', [[
ParentClassToTraitsRector::PARENT_CLASS_TO_TRAITS => ValueObjectInliner::inline([
new ParentClassToTraits('Nette\Object', ['Nette\SmartObject']),
]),
]]);
};

View File

@ -2,7 +2,6 @@
declare(strict_types=1);
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Nette\Rector\FuncCall\FilePutContentsToFileSystemWriteRector;
use Rector\Nette\Rector\FuncCall\JsonDecodeEncodeToNetteUtilsJsonDecodeEncodeRector;
use Rector\Nette\Rector\FuncCall\PregFunctionToNetteUtilsStringsRector;
@ -12,6 +11,7 @@ use Rector\Nette\Rector\Identical\EndsWithFunctionToNetteUtilsStringsRector;
use Rector\Nette\Rector\Identical\StartsWithFunctionToNetteUtilsStringsRector;
use Rector\Nette\Rector\NotIdentical\StrposToStringsContainsRector;
use Rector\NetteUtilsCodeQuality\Rector\LNumber\ReplaceTimeNumberWithDateTimeConstantRector;
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -2,8 +2,6 @@
declare(strict_types=1);
use Rector\Generic\Rector\StaticCall\SwapClassMethodArgumentsRector;
use Rector\Generic\ValueObject\SwapClassMethodArguments;
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -15,15 +13,6 @@ use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
# !!! be careful not to run this twice, since it swaps arguments back and forth
# see https://github.com/rectorphp/rector/issues/2408#issue-534441142
$services->set(SwapClassMethodArgumentsRector::class)
->call('configure', [[
SwapClassMethodArgumentsRector::ARGUMENT_SWAPS => ValueObjectInliner::inline([
new SwapClassMethodArguments('Phalcon\Model', 'assign', [0, 2, 1]),
]),
]]);
# for class renames is better - https://docs.phalcon.io/4.0/en/upgrade#cheat-sheet
$services->set(RenameClassRector::class)
->call('configure', [[

View File

@ -10,12 +10,11 @@ use Rector\Generic\NodeAnalyzer\ArgumentAddingScope;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Generic\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Generic\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\Rector\ClassMethod\WrapReturnRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ArgumentDefaultValueReplacer;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Generic\ValueObject\WrapReturn;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -27,6 +26,7 @@ use Rector\Transform\Rector\New_\NewToStaticCallRector;
use Rector\Transform\ValueObject\NewToStaticCall;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -6889,7 +6889,7 @@ Change visibility of constant from parent class.
```php
use Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Generic\ValueObject\ClassConstantVisibilityChange;
use Rector\Visibility\ValueObject\ClassConstantVisibilityChange;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -6931,15 +6931,15 @@ Change method that returns single value to multiple values
- class: `Rector\Generic\Rector\ClassMethod\ChangeContractMethodSingleToManyRector`
```php
use Rector\Generic\Rector\ClassMethod\ChangeContractMethodSingleToManyRector;
use Rector\Generic\Rector\ClassMethod\SingleToManyMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ChangeContractMethodSingleToManyRector::class)
$services->set(SingleToManyMethodRector::class)
->call('configure', [[
ChangeContractMethodSingleToManyRector::OLD_TO_NEW_METHOD_BY_TYPE => [
SingleToManyMethodRector::SINGLES_TO_MANY_METHODS => [
'SomeClass' => [
'getNode' => 'getNodes',
],
@ -6973,11 +6973,11 @@ Change visibility of method from parent class.
:wrench: **configure it!**
- class: `Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector`
- class: `Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector`
```php
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -7132,10 +7132,10 @@ Change configured function calls to new Instance
:wrench: **configure it!**
- class: `Rector\Generic\Rector\FuncCall\FuncCallToNewRector`
- class: `Rector\Transform\Rector\FuncCall\FuncCallToNewRector`
```php
use Rector\Generic\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -7143,7 +7143,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(FuncCallToNewRector::class)
->call('configure', [[
FuncCallToNewRector::FUNCTION_TO_NEW => [
FuncCallToNewRector::FUNCTIONS_TO_NEWS => [
'collection' => ['Collection'],
],
]]);
@ -7171,10 +7171,10 @@ Turns defined function call to static method call.
:wrench: **configure it!**
- class: `Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector`
- class: `Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector`
```php
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -301,6 +301,11 @@ final class SetList
*/
public const NAMING = __DIR__ . '/../../../../config/set/naming.php';
/**
* @var string
*/
public const NETTE_24 = __DIR__ . '/../../../../config/set/nette-24.php';
/**
* @var string
*/

View File

@ -6,7 +6,7 @@ namespace Rector\Generic\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ArrayType;
@ -14,25 +14,27 @@ use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\SingleToManyMethod;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\ChangeContractMethodSingleToManyRectorTest
* @see \Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\SingleToManyMethodRectorTest
*/
final class ChangeContractMethodSingleToManyRector extends AbstractRector implements ConfigurableRectorInterface
final class SingleToManyMethodRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const OLD_TO_NEW_METHOD_BY_TYPE = 'old_to_new_method_by_type';
public const SINGLES_TO_MANY_METHODS = 'singles_to_many_methods';
/**
* @var mixed[]
* @var SingleToManyMethod[]
*/
private $oldToNewMethodByType = [];
private $singleToManyMethods = [];
/**
* @var PhpDocTypeChanger
@ -71,11 +73,7 @@ class SomeClass
}
CODE_SAMPLE
, [
self::OLD_TO_NEW_METHOD_BY_TYPE => [
'SomeClass' => [
'getNode' => 'getNodes',
],
],
self::SINGLES_TO_MANY_METHODS => [new SingleToManyMethod('SomeClass', 'getNode', 'getNodes')],
]),
]);
}
@ -93,36 +91,41 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
/** @var Class_ $classLike */
$classLike = $node->getAttribute(AttributeKey::CLASS_NODE);
if (! $classLike instanceof ClassLike) {
return null;
}
/** @var string $type */
foreach ($this->oldToNewMethodByType as $type => $oldToNewMethod) {
if (! $this->isObjectType($classLike, $type)) {
foreach ($this->singleToManyMethods as $singleToManyMethod) {
if (! $this->isObjectType($classLike, $singleToManyMethod->getClass())) {
continue;
}
foreach ($oldToNewMethod as $oldMethod => $newMethod) {
if (! $this->isName($node, $oldMethod)) {
continue;
}
$node->name = new Identifier($newMethod);
$this->keepOldReturnTypeInDocBlock($node);
$node->returnType = new Identifier('array');
$this->wrapReturnValueToArray($node);
break;
if (! $this->isName($node, $singleToManyMethod->getSingleMethodName())) {
continue;
}
$node->name = new Identifier($singleToManyMethod->getManyMethodName());
$this->keepOldReturnTypeInDocBlock($node);
$node->returnType = new Identifier('array');
$this->wrapReturnValueToArray($node);
return $node;
}
return $node;
return null;
}
/**
* @param array<string, SingleToManyMethod[]> $configuration
*/
public function configure(array $configuration): void
{
$this->oldToNewMethodByType = $configuration[self::OLD_TO_NEW_METHOD_BY_TYPE] ?? [];
$singleToManyMethods = $configuration[self::SINGLES_TO_MANY_METHODS] ?? [];
Assert::allIsInstanceOf($singleToManyMethods, SingleToManyMethod::class);
$this->singleToManyMethods = $singleToManyMethods;
}
private function keepOldReturnTypeInDocBlock(ClassMethod $classMethod): void

View File

@ -9,8 +9,10 @@ use PhpParser\Node\Stmt\Class_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\PhpParser\Node\Manipulator\ClassInsertManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\ParentClassToTraits;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* Can handle cases like:
@ -24,10 +26,10 @@ final class ParentClassToTraitsRector extends AbstractRector implements Configur
/**
* @var string
*/
public const PARENT_CLASS_TO_TRAITS = '$parentClassToTraits';
public const PARENT_CLASS_TO_TRAITS = 'parent_class_to_traits';
/**
* @var string[][] { parent class => [ traits ] }
* @var ParentClassToTraits[]
*/
private $parentClassToTraits = [];
@ -83,31 +85,36 @@ CODE_SAMPLE
if ($node->extends === null) {
return null;
}
if ($node->isAnonymous()) {
return null;
}
$nodeParentClassName = $this->getName($node->extends);
if (! isset($this->parentClassToTraits[$nodeParentClassName])) {
return null;
foreach ($this->parentClassToTraits as $parentClassToTrait) {
if (! $this->isObjectType($node, $parentClassToTrait->getParentType())){
continue;
}
foreach ($parentClassToTrait->getTraitNames() as $traitName) {
$this->classInsertManipulator->addAsFirstTrait($node, $traitName);
}
$this->removeParentClass($node);
return $node;
}
$traitNames = $this->parentClassToTraits[$nodeParentClassName];
// keep the Trait order the way it is in config
$traitNames = array_reverse($traitNames);
foreach ($traitNames as $traitName) {
$this->classInsertManipulator->addAsFirstTrait($node, $traitName);
}
$this->removeParentClass($node);
return $node;
return null;
}
/**
* @param array<string, ParentClassToTraits[]> $configuration
*/
public function configure(array $configuration): void
{
$this->parentClassToTraits = $configuration[self::PARENT_CLASS_TO_TRAITS] ?? [];
$parentClassToTraits = $configuration[self::PARENT_CLASS_TO_TRAITS] ?? [];
Assert::allIsInstanceOf($parentClassToTraits, ParentClassToTraits::class);
$this->parentClassToTraits = $parentClassToTraits;
}
private function removeParentClass(Class_ $class): void

View File

@ -21,7 +21,7 @@ final class RemoveParentRector extends AbstractRector implements ConfigurableRec
* @api
* @var string
*/
public const PARENT_TYPES_TO_REMOVE = '$parentsToRemove';
public const PARENT_TYPES_TO_REMOVE = 'parents_to_remove';
/**
* @var string[]

View File

@ -1,87 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\MethodCallRemoverRectorTest
*/
final class MethodCallRemoverRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const METHOD_CALL_REMOVER_ARGUMENT = '$methodCallRemoverArgument';
/**
* @var string[]
*/
private $methodCallRemoverArgument = [];
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Turns "$this->something()->anything()" to "$this->anything()"', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
$someObject = new Car;
$someObject->something()->anything();
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$someObject = new Car;
$someObject->anything();
CODE_SAMPLE
,
[
self::METHOD_CALL_REMOVER_ARGUMENT => [
self::METHOD_CALL_REMOVER_ARGUMENT => [
'Car' => 'something',
],
],
]
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node): ?Node
{
foreach ($this->methodCallRemoverArgument as $className => $methodName) {
if (! $this->isObjectType($node->var, $className)) {
continue;
}
if (! $this->isName($node->name, $methodName)) {
continue;
}
return $node->var;
}
return $node;
}
public function configure(array $configuration): void
{
$this->methodCallRemoverArgument = $configuration[self::METHOD_CALL_REMOVER_ARGUMENT] ?? [];
}
}

View File

@ -1,166 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Rector\StaticCall;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\SwapClassMethodArguments;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\StaticCall\SwapClassMethodArgumentsRector\SwapClassMethodArgumentsRectorTest
*/
final class SwapClassMethodArgumentsRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const ARGUMENT_SWAPS = 'argument_swaps';
/**
* @var SwapClassMethodArguments[]
*/
private $argumentSwaps = [];
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Reorder class method arguments, including their calls', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public static function run($first, $second)
{
self::run($first, $second);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public static function run($second, $first)
{
self::run($second, $first);
}
}
CODE_SAMPLE
,
[
self::ARGUMENT_SWAPS => [new SwapClassMethodArguments('SomeClass', 'run', [1, 0])],
]),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [StaticCall::class, MethodCall::class, ClassMethod::class];
}
/**
* @param StaticCall|MethodCall|ClassMethod $node
*/
public function refactor(Node $node): ?Node
{
foreach ($this->argumentSwaps as $argumentSwap) {
if (! $this->isMethodStaticCallOrClassMethodObjectType($node, $argumentSwap->getClass())) {
continue;
}
$this->refactorArgumentPositions($argumentSwap, $node);
}
return $node;
}
public function configure(array $configuration): void
{
$argumentSwaps = $configuration[self::ARGUMENT_SWAPS] ?? [];
Assert::allIsInstanceOf($argumentSwaps, SwapClassMethodArguments::class);
$this->argumentSwaps = $argumentSwaps;
}
/**
* @param StaticCall|MethodCall|ClassMethod $node
*/
private function refactorArgumentPositions(SwapClassMethodArguments $swapClassMethodArguments, Node $node): void
{
if (! $this->isMethodStaticCallOrClassMethodName($node, $swapClassMethodArguments->getMethod())) {
return;
}
if ($node instanceof ClassMethod) {
$this->swapParameters($node, $swapClassMethodArguments->getOrder());
} else {
$this->swapArguments($node, $swapClassMethodArguments->getOrder());
}
}
/**
* @param StaticCall|MethodCall|ClassMethod $node
*/
private function isMethodStaticCallOrClassMethodName(Node $node, string $methodName): bool
{
if ($node instanceof MethodCall || $node instanceof StaticCall) {
if ($node->name instanceof Expr) {
return false;
}
return $this->isName($node->name, $methodName);
}
return $this->isName($node->name, $methodName);
}
/**
* @param array<int, int> $newParameterPositions
*/
private function swapParameters(ClassMethod $classMethod, array $newParameterPositions): void
{
$newArguments = [];
foreach ($newParameterPositions as $oldPosition => $newPosition) {
if (! isset($classMethod->params[$oldPosition]) || ! isset($classMethod->params[$newPosition])) {
continue;
}
$newArguments[$newPosition] = $classMethod->params[$oldPosition];
}
foreach ($newArguments as $newPosition => $argument) {
$classMethod->params[$newPosition] = $argument;
}
}
/**
* @param MethodCall|StaticCall $node
* @param int[] $newArgumentPositions
*/
private function swapArguments(Node $node, array $newArgumentPositions): void
{
$newArguments = [];
foreach ($newArgumentPositions as $oldPosition => $newPosition) {
if (! isset($node->args[$oldPosition]) || ! isset($node->args[$newPosition])) {
continue;
}
$newArguments[$newPosition] = $node->args[$oldPosition];
}
foreach ($newArguments as $newPosition => $argument) {
$node->args[$newPosition] = $argument;
}
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
final class ParentClassToTraits
{
/**
* @var string
*/
private $parentType;
/**
* @var string[]
*/
private $traitNames = [];
/**
* @param string[] $traitNames
*/
public function __construct(string $parentType, array $traitNames)
{
$this->parentType = $parentType;
$this->traitNames = $traitNames;
}
public function getParentType(): string
{
return $this->parentType;
}
/**
* @return string[]
*/
public function getTraitNames(): array
{
// keep the Trait order the way it is in config
return array_reverse($this->traitNames);
}
}

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
final class SingleToManyMethod
{
/**
* @var string
*/
private $class;
/**
* @var string
*/
private $singleMethodName;
/**
* @var string
*/
private $manyMethodName;
public function __construct(string $class, string $singleMethodName, string $manyMethodName)
{
$this->class = $class;
$this->singleMethodName = $singleMethodName;
$this->manyMethodName = $manyMethodName;
}
public function getClass(): string
{
return $this->class;
}
public function getSingleMethodName(): string
{
return $this->singleMethodName;
}
public function getManyMethodName(): string
{
return $this->manyMethodName;
}
}

View File

@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector;
use Iterator;
use Rector\Generic\Rector\ClassMethod\ChangeContractMethodSingleToManyRector;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ChangeContractMethodSingleToManyRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return array<string, mixed[]>
*/
protected function getRectorsWithConfiguration(): array
{
return [
ChangeContractMethodSingleToManyRector::class => [
ChangeContractMethodSingleToManyRector::OLD_TO_NEW_METHOD_BY_TYPE => [
OneToManyInterface::class => [
'getNode' => 'getNodes',
],
],
],
];
}
}

View File

@ -1,34 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class SomeClass implements OneToManyInterface
{
public function getNode(): string
{
return 'Echo_';
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class SomeClass implements OneToManyInterface
{
/**
* @return string[]
*/
public function getNodes(): array
{
return ['Echo_'];
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class NoReturnType implements OneToManyInterface
{
public function getNode()
{
return 'Echo_';
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class NoReturnType implements OneToManyInterface
{
public function getNodes(): array
{
return ['Echo_'];
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class ReturnClassConstFetch implements OneToManyInterface
{
public function getNode(): string
{
return self::class;
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
class ReturnClassConstFetch implements OneToManyInterface
{
/**
* @return string[]
*/
public function getNodes(): array
{
return [self::class];
}
}
?>

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source;
interface OneToManyInterface
{
}

View File

@ -0,0 +1,34 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class SomeClass implements OneToManyInterface
{
public function getNode(): string
{
return 'Echo_';
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class SomeClass implements OneToManyInterface
{
/**
* @return string[]
*/
public function getNodes(): array
{
return ['Echo_'];
}
}
?>

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class MultiReturn implements OneToManyInterface
{
@ -20,9 +20,9 @@ class MultiReturn implements OneToManyInterface
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Fixture;
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeContractMethodSingleToManyRector\Source\OneToManyInterface;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class MultiReturn implements OneToManyInterface
{

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class NoReturnType implements OneToManyInterface
{
public function getNode()
{
return 'Echo_';
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class NoReturnType implements OneToManyInterface
{
public function getNodes(): array
{
return ['Echo_'];
}
}
?>

View File

@ -0,0 +1,34 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class ReturnClassConstFetch implements OneToManyInterface
{
public function getNode(): string
{
return self::class;
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Fixture;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
class ReturnClassConstFetch implements OneToManyInterface
{
/**
* @return string[]
*/
public function getNodes(): array
{
return [self::class];
}
}
?>

View File

@ -2,14 +2,16 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector;
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector;
use Iterator;
use Rector\Generic\Rector\MethodCall\MethodCallRemoverRector;
use Rector\Generic\Rector\ClassMethod\SingleToManyMethodRector;
use Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source\OneToManyInterface;
use Rector\Generic\ValueObject\SingleToManyMethod;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class MethodCallRemoverRectorTest extends AbstractRectorTestCase
final class SingleToManyMethodRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
@ -30,9 +32,9 @@ final class MethodCallRemoverRectorTest extends AbstractRectorTestCase
protected function getRectorsWithConfiguration(): array
{
return [
MethodCallRemoverRector::class => [
MethodCallRemoverRector::METHOD_CALL_REMOVER_ARGUMENT => [
'Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source\Car' => 'getCarType',
SingleToManyMethodRector::class => [
SingleToManyMethodRector::SINGLES_TO_MANY_METHODS => [
new SingleToManyMethod(OneToManyInterface::class, 'getNode', 'getNodes'),
],
],
];

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\SingleToManyMethodRector\Source;
interface OneToManyInterface
{
}

View File

@ -10,6 +10,7 @@ use Rector\Generic\Tests\Rector\Class_\ParentClassToTraitsRector\Source\AnotherP
use Rector\Generic\Tests\Rector\Class_\ParentClassToTraitsRector\Source\ParentObject;
use Rector\Generic\Tests\Rector\Class_\ParentClassToTraitsRector\Source\SecondTrait;
use Rector\Generic\Tests\Rector\Class_\ParentClassToTraitsRector\Source\SomeTrait;
use Rector\Generic\ValueObject\ParentClassToTraits;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -36,8 +37,8 @@ final class ParentClassToTraitsRectorTest extends AbstractRectorTestCase
return [
ParentClassToTraitsRector::class => [
ParentClassToTraitsRector::PARENT_CLASS_TO_TRAITS => [
ParentObject::class => [SomeTrait::class],
AnotherParentObject::class => [SomeTrait::class, SecondTrait::class],
new ParentClassToTraits(ParentObject::class, [SomeTrait::class]),
new ParentClassToTraits(AnotherParentObject::class, [SomeTrait::class, SecondTrait::class]),
],
],
];

View File

@ -1,29 +0,0 @@
<?php
use Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source\Car;
final class AnyClass
{
public function something()
{
$car = new Car();
$car->getCarType()->getType();
}
}
?>
-----
<?php
use Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source\Car;
final class AnyClass
{
public function something()
{
$car = new Car();
$car->getType();
}
}
?>

View File

@ -1,29 +0,0 @@
<?php
use Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source\Driver;
final class AnyOtherClass
{
public function something()
{
$driver = new Driver();
$driver->getCar()->getCarType()->getType();
}
}
?>
-----
<?php
use Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source\Driver;
final class AnyOtherClass
{
public function something()
{
$driver = new Driver();
$driver->getCar()->getType();
}
}
?>

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source;
final class Car
{
/** @var CarType */
private $carType;
public function getCarType() :CarType
{
return $this->carType;
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source;
final class CarType
{
/** @var string */
private $type;
public function getType(): string
{
return $this->type;
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\MethodCallRemoverRector\Source;
final class Driver
{
/** @var Car */
private $car;
public function getCar() :Car
{
return $this->car;
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\StaticCall\SwapClassMethodArgumentsRector\Fixture;
class SomeClass
{
public static function run($first, $second)
{
self::run($first, $second);
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\StaticCall\SwapClassMethodArgumentsRector\Fixture;
class SomeClass
{
public static function run($second, $first)
{
self::run($second, $first);
}
}
?>

View File

@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\StaticCall\SwapClassMethodArgumentsRector;
use Iterator;
use Rector\Generic\Rector\StaticCall\SwapClassMethodArgumentsRector;
use Rector\Generic\Tests\Rector\StaticCall\SwapClassMethodArgumentsRector\Fixture\SomeClass;
use Rector\Generic\ValueObject\SwapClassMethodArguments;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class SwapClassMethodArgumentsRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
/**
* @return array<string, mixed[]>
*/
protected function getRectorsWithConfiguration(): array
{
return [
SwapClassMethodArgumentsRector::class => [
SwapClassMethodArgumentsRector::ARGUMENT_SWAPS => [
new SwapClassMethodArguments(SomeClass::class, 'run', [1, 0]),
],
],
];
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\FuncCall;
namespace Rector\Transform\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
@ -14,14 +14,14 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Generic\Tests\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest
* @see \Rector\Transform\Tests\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest
*/
final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const FUNCTION_TO_NEW = '$functionToNew';
public const FUNCTIONS_TO_NEWS = 'functions_to_news';
/**
* @var string[]
@ -53,7 +53,7 @@ class SomeClass
CODE_SAMPLE
,
[
self::FUNCTION_TO_NEW => [
self::FUNCTIONS_TO_NEWS => [
'collection' => ['Collection'],
],
]
@ -85,8 +85,11 @@ CODE_SAMPLE
return null;
}
/**
* @param array<string, mixed> $configuration
*/
public function configure(array $configuration): void
{
$this->functionToNew = $configuration[self::FUNCTION_TO_NEW] ?? [];
$this->functionToNew = $configuration[self::FUNCTIONS_TO_NEWS] ?? [];
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\FuncCall;
namespace Rector\Transform\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
@ -14,7 +14,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\FuncCallToStaticCallRectorTest
* @see \Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector\FuncCallToStaticCallRectorTest
*/
final class FuncCallToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -7,7 +7,6 @@ namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture\Fixture2;
use Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Source\Translator;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -37,7 +36,12 @@ final class PropertyFetchToMethodCallRectorTest extends AbstractRectorTestCase
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => [
new PropertyFetchToMethodCall(Translator::class, 'locale', 'getLocale', 'setLocale'),
new PropertyFetchToMethodCall('Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture\Fixture2', 'parameter', 'getConfig', null, ['parameter']),
new PropertyFetchToMethodCall(
'Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture\Fixture2',
'parameter',
'getConfig',
null,
['parameter']),
],
],
];

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToNewRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToNewRector\Fixture;
class Fixture
{
@ -14,7 +14,7 @@ class Fixture
-----
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToNewRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToNewRector\Fixture;
class Fixture
{

View File

@ -2,11 +2,11 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToNewRector;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToNewRector;
use Iterator;
use Rector\Generic\Rector\FuncCall\FuncCallToNewRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class FuncCallToNewRectorTest extends AbstractRectorTestCase
@ -31,7 +31,7 @@ final class FuncCallToNewRectorTest extends AbstractRectorTestCase
{
return [
FuncCallToNewRector::class => [
FuncCallToNewRector::FUNCTION_TO_NEW => [
FuncCallToNewRector::FUNCTIONS_TO_NEWS => [
'collection' => ['Collection'],
],
],

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
class Fixture
{
@ -14,7 +14,7 @@ class Fixture
-----
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
class Fixture
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
class Fixture2
{
@ -14,7 +14,7 @@ class Fixture2
-----
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector\Fixture;
class Fixture2
{

View File

@ -2,11 +2,11 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\FuncCall\FuncCallToStaticCallRector;
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToStaticCallRector;
use Iterator;
use Rector\Generic\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
use Rector\Transform\ValueObject\FuncCallToStaticCall;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -9,7 +9,7 @@ use PhpParser\Node\Stmt\ClassConst;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\ValueObject\ClassConstantVisibilityChange;
use Rector\Visibility\ValueObject\ClassConstantVisibilityChange;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

View File

@ -2,21 +2,21 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\ClassMethod;
namespace Rector\Visibility\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\ChangeMethodVisibilityRectorTest
* @see \Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\ChangeMethodVisibilityRectorTest
*/
final class ChangeMethodVisibilityRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\Visibility\ValueObject;
final class ChangeMethodVisibility
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\Visibility\ValueObject;
final class ClassConstantVisibilityChange
{

View File

@ -6,7 +6,7 @@ namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRect
use Iterator;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\ValueObject\ClassConstantVisibilityChange;
use Rector\Visibility\ValueObject\ClassConstantVisibilityChange;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;

View File

@ -2,14 +2,14 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector;
namespace Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Iterator;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ChangeMethodVisibilityRectorTest extends AbstractRectorTestCase

View File

@ -1,6 +1,6 @@
<?php
use Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{
@ -19,7 +19,7 @@ class ClassThatInherits extends ParentObject
-----
<?php
use Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{

View File

@ -1,6 +1,6 @@
<?php
use Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
class ClassThatInherits2 extends ParentObject
{
@ -13,7 +13,7 @@ class ClassThatInherits2 extends ParentObject
-----
<?php
use Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
use Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source\ParentObject;
class ClassThatInherits2 extends ParentObject
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source;
namespace Rector\Visibility\Tests\Rector\ClassMethod\ChangeMethodVisibilityRector\Source;
class ParentObject
{

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Rector\PHPStanExtensions\Tests\Rule\RectorRuleAndValueObjectHaveSameStartsRule\Fixture;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\PHPStanExtensions\Tests\Rule\RectorRuleAndValueObjectHaveSameStartsRule\Source\ConfigureValueObject;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Rector\PHPStanExtensions\Tests\Rule\RectorRuleAndValueObjectHaveSameStartsRule\Fixture;
use Rector\Generic\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\PHPStanExtensions\Tests\Rule\RectorRuleAndValueObjectHaveSameStartsRule\Source\ConfigureValueObject;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;