[Generic] Split rules to their particular categories (#5354)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2021-01-29 00:32:20 +01:00 committed by GitHub
parent a4ed7222f3
commit 34c0f08969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
73 changed files with 684 additions and 623 deletions

View File

@ -157,6 +157,7 @@
"Rector\\Polyfill\\": "rules/polyfill/src",
"Rector\\Compiler\\": "utils/compiler/src",
"Rector\\PostRector\\": "packages/post-rector/src",
"Rector\\Visibility\\": "rules/visibility/src",
"Rector\\Privatization\\": "rules/privatization/src",
"Rector\\RectorGenerator\\": "packages/rector-generator/src",
"Rector\\RemovingStatic\\": "rules/removing-static/src",
@ -254,6 +255,7 @@
"Rector\\NodeTypeResolver\\Tests\\": "packages/node-type-resolver/tests",
"Rector\\Order\\Tests\\": "rules/order/tests",
"Rector\\PHPOffice\\Tests\\": "rules/php-office/tests",
"Rector\\Visibility\\Tests\\": "rules/visibility/tests",
"Rector\\PHPStanExtensions\\": "utils/phpstan-extensions/src",
"Rector\\RuleDocGenerator\\": "utils/rule-doc-generator/src",
"Rector\\PHPStanExtensions\\Tests\\": "utils/phpstan-extensions/tests",

View File

@ -14,25 +14,25 @@ use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameProperty;
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(PropertyToMethodRector::class)
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
// source: https://book.cakephp.org/3.0/en/appendices/3-4-migration-guide.html
new PropertyToMethod('Cake\Network\Request', 'params', 'getAttribute', null, ['params']),
new PropertyToMethod('Cake\Network\Request', 'data', 'getData'),
new PropertyToMethod('Cake\Network\Request', 'query', 'getQueryParams'),
new PropertyToMethod('Cake\Network\Request', 'cookies', 'getCookie'),
new PropertyToMethod('Cake\Network\Request', 'base', 'getAttribute', null, ['base']),
new PropertyToMethod('Cake\Network\Request', 'webroot', 'getAttribute', null, ['webroot']),
new PropertyToMethod('Cake\Network\Request', 'here', 'getAttribute', null, ['here']),
new PropertyFetchToMethodCall('Cake\Network\Request', 'params', 'getAttribute', null, ['params']),
new PropertyFetchToMethodCall('Cake\Network\Request', 'data', 'getData'),
new PropertyFetchToMethodCall('Cake\Network\Request', 'query', 'getQueryParams'),
new PropertyFetchToMethodCall('Cake\Network\Request', 'cookies', 'getCookie'),
new PropertyFetchToMethodCall('Cake\Network\Request', 'base', 'getAttribute', null, ['base']),
new PropertyFetchToMethodCall('Cake\Network\Request', 'webroot', 'getAttribute', null, ['webroot']),
new PropertyFetchToMethodCall('Cake\Network\Request', 'here', 'getAttribute', null, ['here']),
]),
]]);

View File

@ -5,8 +5,8 @@ declare(strict_types=1);
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -23,12 +23,12 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]),
]]);
$services->set(PropertyToMethodRector::class)
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyToMethod('Cake\Controller\Controller', 'name', 'getName', 'setName'),
new PropertyToMethod('Cake\Controller\Controller', 'plugin', 'getPlugin', 'setPlugin'),
new PropertyToMethod('Cake\Form\Form', 'validator', 'getValidator', 'setValidator'),
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyFetchToMethodCall('Cake\Controller\Controller', 'name', 'getName', 'setName'),
new PropertyFetchToMethodCall('Cake\Controller\Controller', 'plugin', 'getPlugin', 'setPlugin'),
new PropertyFetchToMethodCall('Cake\Form\Form', 'validator', 'getValidator', 'setValidator'),
]),
]]);

View File

@ -7,10 +7,10 @@ use Rector\CakePHP\Rector\Property\ChangeSnakedFixtureNameToPascalRector;
use Rector\CakePHP\ValueObject\ModalToGetSet;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\Rector\MethodCall\MethodCallToAnotherMethodCallWithArgumentsRector;
use Rector\Transform\ValueObject\MethodCallToAnotherMethodCallWithArguments;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -29,28 +29,33 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]),
]]);
$services->set(PropertyToMethodRector::class)
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyToMethod('Cake\Http\Client\Response', 'body', 'getStringBody'),
new PropertyToMethod('Cake\Http\Client\Response', 'json', 'getJson'),
new PropertyToMethod('Cake\Http\Client\Response', 'xml', 'getXml'),
new PropertyToMethod('Cake\Http\Client\Response', 'cookies', 'getCookies'),
new PropertyToMethod('Cake\Http\Client\Response', 'code', 'getStatusCode'),
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyFetchToMethodCall('Cake\Http\Client\Response', 'body', 'getStringBody'),
new PropertyFetchToMethodCall('Cake\Http\Client\Response', 'json', 'getJson'),
new PropertyFetchToMethodCall('Cake\Http\Client\Response', 'xml', 'getXml'),
new PropertyFetchToMethodCall('Cake\Http\Client\Response', 'cookies', 'getCookies'),
new PropertyFetchToMethodCall('Cake\Http\Client\Response', 'code', 'getStatusCode'),
new PropertyToMethod('Cake\View\View', 'request', 'getRequest', 'setRequest'),
new PropertyToMethod('Cake\View\View', 'response', 'getResponse', 'setResponse'),
new PropertyToMethod('Cake\View\View', 'templatePath', 'getTemplatePath', 'setTemplatePath'),
new PropertyToMethod('Cake\View\View', 'template', 'getTemplate', 'setTemplate'),
new PropertyToMethod('Cake\View\View', 'layout', 'getLayout', 'setLayout'),
new PropertyToMethod('Cake\View\View', 'layoutPath', 'getLayoutPath', 'setLayoutPath'),
new PropertyToMethod('Cake\View\View', 'autoLayout', 'isAutoLayoutEnabled', 'enableAutoLayout'),
new PropertyToMethod('Cake\View\View', 'theme', 'getTheme', 'setTheme'),
new PropertyToMethod('Cake\View\View', 'subDir', 'getSubDir', 'setSubDir'),
new PropertyToMethod('Cake\View\View', 'plugin', 'getPlugin', 'setPlugin'),
new PropertyToMethod('Cake\View\View', 'name', 'getName', 'setName'),
new PropertyToMethod('Cake\View\View', 'elementCache', 'getElementCache', 'setElementCache'),
new PropertyToMethod('Cake\View\View', 'helpers', 'helpers'),
new PropertyFetchToMethodCall('Cake\View\View', 'request', 'getRequest', 'setRequest'),
new PropertyFetchToMethodCall('Cake\View\View', 'response', 'getResponse', 'setResponse'),
new PropertyFetchToMethodCall('Cake\View\View', 'templatePath', 'getTemplatePath', 'setTemplatePath'),
new PropertyFetchToMethodCall('Cake\View\View', 'template', 'getTemplate', 'setTemplate'),
new PropertyFetchToMethodCall('Cake\View\View', 'layout', 'getLayout', 'setLayout'),
new PropertyFetchToMethodCall('Cake\View\View', 'layoutPath', 'getLayoutPath', 'setLayoutPath'),
new PropertyFetchToMethodCall(
'Cake\View\View',
'autoLayout',
'isAutoLayoutEnabled',
'enableAutoLayout'
),
new PropertyFetchToMethodCall('Cake\View\View', 'theme', 'getTheme', 'setTheme'),
new PropertyFetchToMethodCall('Cake\View\View', 'subDir', 'getSubDir', 'setSubDir'),
new PropertyFetchToMethodCall('Cake\View\View', 'plugin', 'getPlugin', 'setPlugin'),
new PropertyFetchToMethodCall('Cake\View\View', 'name', 'getName', 'setName'),
new PropertyFetchToMethodCall('Cake\View\View', 'elementCache', 'getElementCache', 'setElementCache'),
new PropertyFetchToMethodCall('Cake\View\View', 'helpers', 'helpers'),
]),
]]);

View File

@ -4,12 +4,12 @@ declare(strict_types=1);
use Rector\Architecture\Rector\MethodCall\ReplaceParentRepositoryCallsByRepositoryPropertyRector;
use Rector\Architecture\Rector\MethodCall\ServiceLocatorToDIRector;
use Rector\DeadDocBlock\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Doctrine\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector;
use Rector\Doctrine\Rector\ClassMethod\ServiceEntityRepositoryParentCallToDIRector;
use Rector\DoctrineCodeQuality\Rector\Class_\MoveRepositoryFromParentToConstructorRector;
use Rector\Generic\Rector\Class_\AddPropertyByParentRector;
use Rector\Generic\Rector\Class_\RemoveParentRector;
use Rector\Generic\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Generic\ValueObject\AddPropertyByParent;
use Rector\Transform\Rector\MethodCall\MethodCallToPropertyFetchRector;
use Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector;

View File

@ -2,9 +2,9 @@
declare(strict_types=1);
use Rector\Generic\Rector\String_\StringToClassConstantRector;
use Rector\Generic\ValueObject\StringToClassConstant;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
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\String_\StringToClassConstantRector;
use Rector\Generic\ValueObject\StringToClassConstant;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
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\ChangeMethodVisibilityRector;
use Rector\Generic\Rector\Expression\MethodCallToReturnRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ChangeMethodVisibility;
use Rector\Generic\ValueObject\MethodCallToReturn;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\Transform\Rector\Expression\MethodCallToReturnRector;
use Rector\Transform\ValueObject\MethodCallToReturn;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -8,7 +8,6 @@ use PHPStan\Type\UnionType;
use Rector\Composer\Rector\ChangePackageVersionComposerRector;
use Rector\Composer\Rector\RemovePackageComposerRector;
use Rector\Composer\ValueObject\PackageAndVersion;
use Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Nette\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
@ -16,6 +15,7 @@ use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -6885,10 +6885,10 @@ Change visibility of constant from parent class.
:wrench: **configure it!**
- class: `Rector\Generic\Rector\ClassConst\ChangeConstantVisibilityRector`
- class: `Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector`
```php
use Rector\Generic\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Generic\ValueObject\ClassConstantVisibilityChange;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -7020,10 +7020,10 @@ Change visibility of property from parent class.
:wrench: **configure it!**
- class: `Rector\Generic\Rector\Property\ChangePropertyVisibilityRector`
- class: `Rector\Visibility\Rector\Property\ChangePropertyVisibilityRector`
```php
use Rector\Generic\Rector\Property\ChangePropertyVisibilityRector;
use Rector\Visibility\Rector\Property\ChangePropertyVisibilityRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -7063,10 +7063,10 @@ Change magic array access add to `$list,` to explicit `$list->$addMethod(...)`
:wrench: **configure it!**
- class: `Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector`
- class: `Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector`
```php
use Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -7324,10 +7324,10 @@ Wrap method call to return
:wrench: **configure it!**
- class: `Rector\Generic\Rector\Expression\MethodCallToReturnRector`
- class: `Rector\Transform\Rector\Expression\MethodCallToReturnRector`
```php
use Rector\Generic\Rector\Expression\MethodCallToReturnRector;
use Rector\Transform\Rector\Expression\MethodCallToReturnRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -7371,15 +7371,15 @@ Replaces creating object instances with "new" keyword with factory method.
- class: `Rector\Generic\Rector\New_\NewObjectToFactoryCreateRector`
```php
use Rector\Generic\Rector\New_\NewObjectToFactoryCreateRector;
use Rector\Transform\Rector\New_\NewToMethodCallRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(NewObjectToFactoryCreateRector::class)
$services->set(NewToMethodCallRector::class)
->call('configure', [[
NewObjectToFactoryCreateRector::OBJECT_TO_FACTORY_METHOD => [
NewToMethodCallRector::NEWS_TO_METHOD_CALLS => [
'MyClass' => [
'class' => 'MyClassFactory',
'method' => 'create',
@ -7488,10 +7488,10 @@ Remove annotation by names
:wrench: **configure it!**
- class: `Rector\Generic\Rector\ClassLike\RemoveAnnotationRector`
- class: `Rector\DeadDocBlock\Rector\ClassLike\RemoveAnnotationRector`
```php
use Rector\Generic\Rector\ClassLike\RemoveAnnotationRector;
use Rector\DeadDocBlock\Rector\ClassLike\RemoveAnnotationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -7691,17 +7691,17 @@ Replaces constant by value
- class: `Rector\Generic\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector`
```php
use Rector\Generic\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector;
use Rector\Generic\ValueObject\ClassConstFetchToValue;
use Rector\Transform\Rector\ClassConstFetch\ClassConstFetchToStringRector;
use Rector\Transform\ValueObject\ClassConstFetchToValue;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameClassConstantsUseToStringsRector::class)
$services->set(ClassConstFetchToStringRector::class)
->call('configure', [[
RenameClassConstantsUseToStringsRector::CLASS_CONST_FETCHES_TO_VALUES => ValueObjectInliner::inline([
ClassConstFetchToStringRector::CLASS_CONST_FETCHES_TO_VALUES => ValueObjectInliner::inline([
new ClassConstFetchToValue('Nette\Configurator', 'DEVELOPMENT', 'development'),
new ClassConstFetchToValue('Nette\Configurator', 'PRODUCTION', 'production'),
]),
@ -7753,11 +7753,11 @@ Changes strings to specific constants
:wrench: **configure it!**
- class: `Rector\Generic\Rector\String_\StringToClassConstantRector`
- class: `Rector\Transform\Rector\String_\StringToClassConstantRector`
```php
use Rector\Generic\Rector\String_\StringToClassConstantRector;
use Rector\Generic\ValueObject\StringToClassConstant;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -16383,18 +16383,18 @@ Replaces properties assign calls be defined methods.
- class: `Rector\Transform\Rector\Assign\PropertyToMethodRector`
```php
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(PropertyToMethodRector::class)
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyToMethod('SomeObject', 'property', 'getProperty', [], 'setProperty'),
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyFetchToMethodCall('SomeObject', 'property', 'getProperty', [], 'setProperty'),
]),
]]);
};
@ -16412,18 +16412,18 @@ return static function (ContainerConfigurator $containerConfigurator): void {
<br>
```php
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(PropertyToMethodRector::class)
$services->set(PropertyFetchToMethodCallRector::class)
->call('configure', [[
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyToMethod('SomeObject', 'property', 'getConfig', ['someArg'], null),
PropertyFetchToMethodCallRector::PROPERTIES_TO_METHOD_CALLS => ValueObjectInliner::inline([
new PropertyFetchToMethodCall('SomeObject', 'property', 'getConfig', ['someArg'], null),
]),
]]);
};

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\ClassLike;
namespace Rector\DeadDocBlock\Rector\ClassLike;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
@ -18,7 +18,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector\RemoveAnnotationRectorTest
* @see \Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector\RemoveAnnotationRectorTest
*/
final class RemoveAnnotationRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -0,0 +1,22 @@
<?php
namespace Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
/**
* @method getName()
*/
final class Fixture
{
}
?>
-----
<?php
namespace Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
final class Fixture
{
}
?>

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
namespace Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
use JMS\DiExtraBundle\Annotation as DI;
@ -21,7 +21,7 @@ final class RemoveByType
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
namespace Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
use JMS\DiExtraBundle\Annotation as DI;

View File

@ -2,11 +2,11 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector;
namespace Rector\DeadDocBlock\Tests\Rector\ClassLike\RemoveAnnotationRector;
use Iterator;
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\JMS\JMSInjectParamsTagValueNode;
use Rector\Generic\Rector\ClassLike\RemoveAnnotationRector;
use Rector\DeadDocBlock\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -1,35 +0,0 @@
<?php
use Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Source\Translator;
class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->locale;
// update locale
$this->locale = $locale;
}
}
?>
-----
<?php
use Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Source\Translator;
class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->getLocale();
// update locale
$this->setLocale($locale);
}
}
?>

View File

@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
class ClassWithInvalidConstants extends ParentObject
{
public const TO_BE_PUBLIC_CONSTANT = 1;
public const TO_BE_PROTECTED_CONSTANT = 2;
protected const TO_BE_PRIVATE_CONSTANT = 3;
}
?>
-----
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
class ClassWithInvalidConstants extends ParentObject
{
public const TO_BE_PUBLIC_CONSTANT = 1;
protected const TO_BE_PROTECTED_CONSTANT = 2;
private const TO_BE_PRIVATE_CONSTANT = 3;
}
?>

View File

@ -1,21 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
class Fixture2
{
public const TO_BE_PRIVATE_CONSTANT = 1;
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
class Fixture2
{
private const TO_BE_PRIVATE_CONSTANT = 1;
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Fixture;
use Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Source\OldClassWithConstants;
class ClassWithExternalConstant
{
public function getValue()
{
return OldClassWithConstants::DEVELOPMENT;
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Fixture;
use Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Source\OldClassWithConstants;
class ClassWithExternalConstant
{
public function getValue()
{
return 'development';
}
}
?>

View File

@ -1,22 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
/**
* @method getName()
*/
final class Fixture
{
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\ClassLike\RemoveAnnotationRector\Fixture;
final class Fixture
{
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
use Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
class SomeClass
{
public function run(ReturnDeny $returnDeny)
{
$returnDeny->deny();
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
use Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
class SomeClass
{
public function run(ReturnDeny $returnDeny)
{
return $returnDeny->deny();
}
}
?>

View File

@ -1,34 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Fixture;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClass;
final class SomeController
{
public function default()
{
new MyClass('abcd');
$class = new MyClass('abcd');
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Fixture;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClass;
final class SomeController
{
public function __construct(private \Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory $myClassFactory)
{
}
public function default()
{
$this->myClassFactory->create('abcd');
$class = $this->myClassFactory->create('abcd');
}
}
?>

View File

@ -1,47 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Fixture;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClass;
final class SomeOtherController
{
/**
* @var \Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory
*/
private $mySomeFactory;
public function __construct(\Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory $mySomeFactory)
{
$this->mySomeFactory = $mySomeFactory;
}
public function default()
{
new MyClass('abcd');
$class = new MyClass('abcd');
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Fixture;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClass;
final class SomeOtherController
{
/**
* @var \Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory
*/
private $mySomeFactory;
public function __construct(\Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory $mySomeFactory)
{
$this->mySomeFactory = $mySomeFactory;
}
public function default()
{
$this->mySomeFactory->create('abcd');
$class = $this->mySomeFactory->create('abcd');
}
}
?>

View File

@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector;
use Iterator;
use Rector\Generic\Rector\New_\NewObjectToFactoryCreateRector;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClass;
use Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source\MyClassFactory;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class NewObjectToFactoryCreateRectorTest 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 [
NewObjectToFactoryCreateRector::class => [
NewObjectToFactoryCreateRector::OBJECT_TO_FACTORY_METHOD => [
MyClass::class => [
'class' => MyClassFactory::class,
'method' => 'create',
],
],
],
];
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{
public $toBeProtectedProperty;
protected $toBePrivateProperty;
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{
protected $toBeProtectedProperty;
private $toBePrivateProperty;
}
?>

View File

@ -1,25 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInheritsAgain extends ParentObject
{
private static $toBePublicStaticProperty;
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInheritsAgain extends ParentObject
{
public static $toBePublicStaticProperty;
}
?>

View File

@ -1,21 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
class Fixture3
{
private static $toBePublicStaticProperty;
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
class Fixture3
{
public static $toBePublicStaticProperty;
}
?>

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\Assign;
namespace Rector\Transform\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
@ -18,7 +18,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\DimFetchAssignToMethodCallRectorTest
* @see \Rector\Transform\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\DimFetchAssignToMethodCallRectorTest
*/
final class DimFetchAssignToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
{
@ -35,7 +35,7 @@ final class DimFetchAssignToMethodCallRector extends AbstractRector implements C
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change magic array access add to $list, to explicit $list->$addMethod(...)',
'Change magic array access add to $list[], to explicit $list->addMethod(...)',
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
@ -47,8 +47,7 @@ class RouterFactory
public static function createRouter()
{
$routeList = new RouteList();
$routeList[] = new Route('<module>/<presenter>/<action>[/<id>]', 'Homepage:default');
return $routeList;
$routeList[] = new Route('...');
}
}
CODE_SAMPLE
@ -61,8 +60,7 @@ class RouterFactory
public static function createRouter()
{
$routeList = new RouteList();
$routeList->addRoute('<module>/<presenter>/<action>[/<id>]', 'Homepage:default');
return $routeList;
$routeList->addRoute('...');
}
}
CODE_SAMPLE

View File

@ -11,15 +11,15 @@ use PhpParser\Node\Expr\Variable;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\Transform\ValueObject\PropertyToMethod;
use Rector\Transform\ValueObject\PropertyFetchToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\PropertyToMethodRectorTest
* @see \Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\PropertyFetchToMethodCallRectorTest
*/
final class PropertyToMethodRector extends AbstractRector implements ConfigurableRectorInterface
final class PropertyFetchToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
@ -27,7 +27,7 @@ final class PropertyToMethodRector extends AbstractRector implements Configurabl
public const PROPERTIES_TO_METHOD_CALLS = 'properties_to_method_calls';
/**
* @var PropertyToMethod[]
* @var PropertyFetchToMethodCall[]
*/
private $propertiesToMethodCalls = [];
@ -35,13 +35,13 @@ final class PropertyToMethodRector extends AbstractRector implements Configurabl
{
$firstConfiguration = [
self::PROPERTIES_TO_METHOD_CALLS => [
new PropertyToMethod('SomeObject', 'property', 'getProperty', 'setProperty'),
new PropertyFetchToMethodCall('SomeObject', 'property', 'getProperty', 'setProperty'),
],
];
$secondConfiguration = [
self::PROPERTIES_TO_METHOD_CALLS => [
new PropertyToMethod('SomeObject', 'property', 'getConfig', null, ['someArg']),
new PropertyFetchToMethodCall('SomeObject', 'property', 'getConfig', null, ['someArg']),
],
];
return new RuleDefinition('Replaces properties assign calls be defined methods.', [
@ -96,10 +96,13 @@ CODE_SAMPLE
return null;
}
/**
* @param array<string, PropertyFetchToMethodCall[]> $configuration
*/
public function configure(array $configuration): void
{
$propertiesToMethodCalls = $configuration[self::PROPERTIES_TO_METHOD_CALLS] ?? [];
Assert::allIsInstanceOf($propertiesToMethodCalls, PropertyToMethod::class);
Assert::allIsInstanceOf($propertiesToMethodCalls, PropertyFetchToMethodCall::class);
$this->propertiesToMethodCalls = $propertiesToMethodCalls;
}
@ -109,7 +112,7 @@ CODE_SAMPLE
$propertyFetchNode = $assign->var;
$propertyToMethodCall = $this->matchPropertyFetchCandidate($propertyFetchNode);
if (! $propertyToMethodCall instanceof PropertyToMethod) {
if (! $propertyToMethodCall instanceof PropertyFetchToMethodCall) {
return null;
}
@ -131,7 +134,7 @@ CODE_SAMPLE
$propertyFetchNode = $assign->expr;
$propertyToMethodCall = $this->matchPropertyFetchCandidate($propertyFetchNode);
if (! $propertyToMethodCall instanceof PropertyToMethod) {
if (! $propertyToMethodCall instanceof PropertyFetchToMethodCall) {
return null;
}
@ -150,7 +153,7 @@ CODE_SAMPLE
return $assign;
}
private function matchPropertyFetchCandidate(PropertyFetch $propertyFetch): ?PropertyToMethod
private function matchPropertyFetchCandidate(PropertyFetch $propertyFetch): ?PropertyFetchToMethodCall
{
foreach ($this->propertiesToMethodCalls as $propertyToMethodCall) {
if (! $this->isObjectType($propertyFetch->var, $propertyToMethodCall->getOldType())) {

View File

@ -2,22 +2,22 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\ClassConstFetch;
namespace Rector\Transform\Rector\ClassConstFetch;
use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\ClassConstFetchToValue;
use Rector\Transform\ValueObject\ClassConstFetchToValue;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\RenameClassConstantsUseToStringsRectorTest
* @see \Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\ClassConstFetchToStringRectorTest
*/
final class RenameClassConstantsUseToStringsRector extends AbstractRector implements ConfigurableRectorInterface
final class ClassConstFetchToStringRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\Expression;
namespace Rector\Transform\Rector\Expression;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
@ -10,14 +10,14 @@ use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\MethodCallToReturn;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\ValueObject\MethodCallToReturn;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\MethodCallToReturnRectorTest
* @see \Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\MethodCallToReturnRectorTest
*/
final class MethodCallToReturnRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\New_;
namespace Rector\Transform\Rector\New_;
use Nette\Utils\Strings;
use PhpParser\Node;
@ -15,24 +15,26 @@ use PHPStan\Type\ObjectType;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\ValueObject\NewToMethodCall;
use ReflectionClass;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\NewObjectToFactoryCreateRectorTest
* @see \Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\NewToMethodCallRectorTest
*/
final class NewObjectToFactoryCreateRector extends AbstractRector implements ConfigurableRectorInterface
final class NewToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @var string
*/
public const OBJECT_TO_FACTORY_METHOD = '$objectToFactoryMethod';
public const NEWS_TO_METHOD_CALLS = 'news_to_method_calls';
/**
* @var string[][]
* @var NewToMethodCall[]
*/
private $objectToFactoryMethod = [];
private $newsToMethodCalls = [];
public function getRuleDefinition(): RuleDefinition
{
@ -62,12 +64,7 @@ class SomeClass
CODE_SAMPLE
,
[
self::OBJECT_TO_FACTORY_METHOD => [
'MyClass' => [
'class' => 'MyClassFactory',
'method' => 'create',
],
],
self::NEWS_TO_METHOD_CALLS => [new NewToMethodCall('MyClass', 'MyClassFactory', 'create')],
]
),
]);
@ -86,52 +83,55 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
foreach ($this->objectToFactoryMethod as $object => $factoryInfo) {
if (! $this->isObjectType($node, $object)) {
foreach ($this->newsToMethodCalls as $newToMethodCall) {
if (! $this->isObjectType($node, $newToMethodCall->getNewType())) {
continue;
}
$factoryClass = $factoryInfo['class'];
$factoryMethod = $factoryInfo['method'];
$serviceType = $newToMethodCall->getServiceType();
$className = $node->getAttribute(AttributeKey::CLASS_NAME);
if ($className === $factoryClass) {
if ($className === $serviceType) {
continue;
}
/** @var Class_ $classNode */
$classNode = $node->getAttribute(AttributeKey::CLASS_NODE);
$propertyName = $this->getExistingFactoryPropertyName($classNode, $factoryClass);
$propertyName = $this->getExistingFactoryPropertyName($classNode, $serviceType);
if ($propertyName === null) {
$propertyName = $this->getFactoryPropertyName($factoryClass);
$propertyName = $this->getFactoryPropertyName($serviceType);
$factoryObjectType = new ObjectType($factoryClass);
$factoryObjectType = new ObjectType($serviceType);
$this->addConstructorDependencyToClass($classNode, $factoryObjectType, $propertyName);
}
return new MethodCall(
new PropertyFetch(new Variable('this'), $propertyName),
$factoryMethod,
$node->args
);
$propertyFetch = new PropertyFetch(new Variable('this'), $propertyName);
return new MethodCall($propertyFetch, $newToMethodCall->getServiceMethod(), $node->args);
}
return $node;
}
/**
* @param array<string, NewToMethodCall[]> $configuration
*/
public function configure(array $configuration): void
{
$this->objectToFactoryMethod = $configuration[self::OBJECT_TO_FACTORY_METHOD] ?? [];
$newsToMethodCalls = $configuration[self::NEWS_TO_METHOD_CALLS] ?? [];
Assert::allIsInstanceOf($newsToMethodCalls, NewToMethodCall::class);
$this->newsToMethodCalls = $newsToMethodCalls;
}
private function getExistingFactoryPropertyName(Class_ $class, string $factoryClass): ?string
{
foreach ($class->getProperties() as $property) {
if ($this->isObjectType($property, $factoryClass)) {
return (string) $property->props[0]->name;
if (! $this->isObjectType($property, $factoryClass)) {
continue;
}
return $this->getName($property);
}
return null;

View File

@ -2,19 +2,19 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\String_;
namespace Rector\Transform\Rector\String_;
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\StringToClassConstant;
use Rector\Transform\ValueObject\StringToClassConstant;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\String_\StringToClassConstantRector\StringToClassConstantRectorTest
* @see \Rector\Transform\Tests\Rector\String_\StringToClassConstantRector\StringToClassConstantRectorTest
*/
final class StringToClassConstantRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

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

View File

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

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\ValueObject;
final class NewToMethodCall
{
/**
* @var string
*/
private $newType;
/**
* @var string
*/
private $serviceType;
/**
* @var string
*/
private $serviceMethod;
public function __construct(string $newType, string $serviceType, string $serviceMethod)
{
$this->newType = $newType;
$this->serviceType = $serviceType;
$this->serviceMethod = $serviceMethod;
}
public function getNewType(): string
{
return $this->newType;
}
public function getServiceType(): string
{
return $this->serviceType;
}
public function getServiceMethod(): string
{
return $this->serviceMethod;
}
}

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Rector\Transform\ValueObject;
final class PropertyToMethod
final class PropertyFetchToMethodCall
{
/**
* @var string

View File

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

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\Assign\DimFetchAssignToMethodCallRector;
namespace Rector\Transform\Tests\Rector\Assign\DimFetchAssignToMethodCallRector;
use Iterator;
use Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class DimFetchAssignToMethodCallRectorTest extends AbstractRectorTestCase

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\Fixture;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;
@ -19,7 +19,7 @@ class RouterFactory
-----
<?php
namespace Rector\Generic\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\Fixture;
namespace Rector\Transform\Tests\Rector\Assign\DimFetchAssignToMethodCallRector\Fixture;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

View File

@ -0,0 +1,39 @@
<?php
namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Source\Translator;
final class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->locale;
// update locale
$this->locale = $locale;
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Source\Translator;
final class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->getLocale();
// update locale
$this->setLocale($locale);
}
}
?>

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Fixture;
namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture;
final class Fixture2
{
@ -16,7 +16,7 @@ final class Fixture2
-----
<?php
namespace Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Fixture;
namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Fixture;
final class Fixture2
{

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
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;
final class PropertyFetchToMethodCallRectorTest 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 [
PropertyFetchToMethodCallRector::class => [
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']),
],
],
];
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\Assign\PropertyFetchToMethodCallRector\Source;
class Translator
{
public $locale;
}

View File

@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\Assign\PropertyToMethodRector;
use Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Source\Translator;
use Rector\Transform\ValueObject\PropertyToMethod;
use Symplify\SmartFileSystem\SmartFileInfo;
final class PropertyToMethodRectorTest 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 [
PropertyToMethodRector::class => [
PropertyToMethodRector::PROPERTIES_TO_METHOD_CALLS => [
new PropertyToMethod(Translator::class, 'locale', 'getLocale', 'setLocale'),
new PropertyToMethod(
'Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Fixture\Fixture2',
'parameter',
'getConfig',
null,
['parameter']
),
],
],
];
}
}

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\Assign\PropertyToMethodRector\Source;
class Translator
{
}

View File

@ -2,16 +2,16 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector;
namespace Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector;
use Iterator;
use Rector\Generic\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector;
use Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Source\OldClassWithConstants;
use Rector\Generic\ValueObject\ClassConstFetchToValue;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\ClassConstFetch\ClassConstFetchToStringRector;
use Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Source\OldClassWithConstants;
use Rector\Transform\ValueObject\ClassConstFetchToValue;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RenameClassConstantsUseToStringsRectorTest extends AbstractRectorTestCase
final class ClassConstFetchToStringRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
@ -32,8 +32,8 @@ final class RenameClassConstantsUseToStringsRectorTest extends AbstractRectorTes
protected function getRectorsWithConfiguration(): array
{
return [
RenameClassConstantsUseToStringsRector::class => [
RenameClassConstantsUseToStringsRector::CLASS_CONST_FETCHES_TO_VALUES => [
ClassConstFetchToStringRector::class => [
ClassConstFetchToStringRector::CLASS_CONST_FETCHES_TO_VALUES => [
new ClassConstFetchToValue(OldClassWithConstants::class, 'DEVELOPMENT', 'development'),
new ClassConstFetchToValue(OldClassWithConstants::class, 'PRODUCTION', 'production'),
],

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Fixture;
use Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Source\OldClassWithConstants;
class ClassWithExternalConstant
{
public function getValue()
{
return OldClassWithConstants::DEVELOPMENT;
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Fixture;
use Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Source\OldClassWithConstants;
class ClassWithExternalConstant
{
public function getValue()
{
return 'development';
}
}
?>

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassConstFetch\RenameClassConstantsUseToStringsRector\Source;
namespace Rector\Transform\Tests\Rector\ClassConstFetch\ClassConstFetchToStringRector\Source;
final class OldClassWithConstants
{

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
use Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
class SomeClass
{
public function run(ReturnDeny $returnDeny)
{
$returnDeny->deny();
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
use Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
class SomeClass
{
public function run(ReturnDeny $returnDeny)
{
return $returnDeny->deny();
}
}
?>

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
namespace Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Fixture;
use Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
use Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
class SkipAlreadyReturn
{

View File

@ -2,13 +2,13 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector;
namespace Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector;
use Iterator;
use Rector\Generic\Rector\Expression\MethodCallToReturnRector;
use Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
use Rector\Generic\ValueObject\MethodCallToReturn;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\Expression\MethodCallToReturnRector;
use Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Source\ReturnDeny;
use Rector\Transform\ValueObject\MethodCallToReturn;
use Symplify\SmartFileSystem\SmartFileInfo;
final class MethodCallToReturnRectorTest extends AbstractRectorTestCase

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\Expression\MethodCallToReturnRector\Source;
namespace Rector\Transform\Tests\Rector\Expression\MethodCallToReturnRector\Source;
final class ReturnDeny
{

View File

@ -0,0 +1,34 @@
<?php
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClass;
final class SomeController
{
public function default()
{
new MyClass('abcd');
$class = new MyClass('abcd');
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClass;
final class SomeController
{
public function __construct(private \Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory $myClassFactory)
{
}
public function default()
{
$this->myClassFactory->create('abcd');
$class = $this->myClassFactory->create('abcd');
}
}
?>

View File

@ -0,0 +1,47 @@
<?php
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClass;
final class SomeOtherController
{
/**
* @var \Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory
*/
private $mySomeFactory;
public function __construct(\Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory $mySomeFactory)
{
$this->mySomeFactory = $mySomeFactory;
}
public function default()
{
new MyClass('abcd');
$class = new MyClass('abcd');
}
}
?>
-----
<?php
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Fixture;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClass;
final class SomeOtherController
{
/**
* @var \Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory
*/
private $mySomeFactory;
public function __construct(\Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory $mySomeFactory)
{
$this->mySomeFactory = $mySomeFactory;
}
public function default()
{
$this->mySomeFactory->create('abcd');
$class = $this->mySomeFactory->create('abcd');
}
}
?>

View File

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\New_\NewToMethodCallRector;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClass;
use Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source\MyClassFactory;
use Rector\Transform\ValueObject\NewToMethodCall;
use Symplify\SmartFileSystem\SmartFileInfo;
final class NewToMethodCallRectorTest 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 [
NewToMethodCallRector::class => [
NewToMethodCallRector::NEWS_TO_METHOD_CALLS => [
new NewToMethodCall(MyClass::class, MyClassFactory::class, 'create'),
],
],
];
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source;
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source;
final class MyClass
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\New_\NewObjectToFactoryCreateRector\Source;
namespace Rector\Transform\Tests\Rector\New_\NewToMethodCallRector\Source;
final class MyClassFactory
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\String_\StringToClassConstantRector\Fixture;
namespace Rector\Transform\Tests\Rector\String_\StringToClassConstantRector\Fixture;
final class Fixture
{
@ -17,7 +17,7 @@ final class Fixture
-----
<?php
namespace Rector\Generic\Tests\Rector\String_\StringToClassConstantRector\Fixture;
namespace Rector\Transform\Tests\Rector\String_\StringToClassConstantRector\Fixture;
final class Fixture
{

View File

@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\String_\StringToClassConstantRector;
namespace Rector\Transform\Tests\Rector\String_\StringToClassConstantRector;
use Iterator;
use Rector\Generic\Rector\String_\StringToClassConstantRector;
use Rector\Generic\ValueObject\StringToClassConstant;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\String_\StringToClassConstantRector;
use Rector\Transform\ValueObject\StringToClassConstant;
use Symplify\SmartFileSystem\SmartFileInfo;
final class StringToClassConstantRectorTest extends AbstractRectorTestCase

View File

@ -2,7 +2,7 @@
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
final class ConfigurationWithStringStringArray
@ -29,7 +29,7 @@ final class ConfigurationWithStringStringArray
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Rector\Generic\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
final class ConfigurationWithStringStringArray

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\ClassConst;
namespace Rector\Visibility\Rector\ClassConst;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassConst;
@ -15,7 +15,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\ChangeConstantVisibilityRectorTest
* @see \Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\ChangeConstantVisibilityRectorTest
*/
final class ChangeConstantVisibilityRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\Property;
namespace Rector\Visibility\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
@ -15,7 +15,7 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\ChangePropertyVisibilityRectorTest
* @see \Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\ChangePropertyVisibilityRectorTest
*/
final class ChangePropertyVisibilityRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -2,14 +2,14 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector;
namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector;
use Iterator;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
use Rector\Generic\ValueObject\ClassConstantVisibilityChange;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ChangeConstantVisibilityRectorTest extends AbstractRectorTestCase
@ -47,7 +47,7 @@ final class ChangeConstantVisibilityRectorTest extends AbstractRectorTestCase
Visibility::PRIVATE
),
new ClassConstantVisibilityChange(
'Rector\Generic\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture\Fixture2',
'Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture\Fixture2',
'TO_BE_PRIVATE_CONSTANT',
Visibility::PRIVATE
),

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
final class ClassWithInvalidConstants extends ParentObject
{
public const TO_BE_PUBLIC_CONSTANT = 1;
public const TO_BE_PROTECTED_CONSTANT = 2;
protected const TO_BE_PRIVATE_CONSTANT = 3;
}
?>
-----
<?php
declare(strict_types=1);
namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Source\ParentObject;
final class ClassWithInvalidConstants extends ParentObject
{
public const TO_BE_PUBLIC_CONSTANT = 1;
protected const TO_BE_PROTECTED_CONSTANT = 2;
private const TO_BE_PRIVATE_CONSTANT = 3;
}
?>

View File

@ -0,0 +1,21 @@
<?php
namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
class Fixture2
{
public const TO_BE_PRIVATE_CONSTANT = 1;
}
?>
-----
<?php
namespace Rector\Visibility\Tests\Rector\ClassConst\ChangeConstantVisibilityRector\Fixture;
class Fixture2
{
private const TO_BE_PRIVATE_CONSTANT = 1;
}
?>

View File

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

View File

@ -2,13 +2,13 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector;
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector;
use Iterator;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\Property\ChangePropertyVisibilityRector;
use Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Visibility\Rector\Property\ChangePropertyVisibilityRector;
use Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
use Symplify\SmartFileSystem\SmartFileInfo;
final class ChangePropertyVisibilityRectorTest extends AbstractRectorTestCase
@ -40,7 +40,7 @@ final class ChangePropertyVisibilityRectorTest extends AbstractRectorTestCase
'toBePrivateProperty' => Visibility::PRIVATE,
'toBePublicStaticProperty' => Visibility::PUBLIC,
],
'Rector\Generic\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture\Fixture3' => [
'Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture\Fixture3' => [
'toBePublicStaticProperty' => Visibility::PUBLIC,
],
],

View File

@ -0,0 +1,29 @@
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{
public $toBeProtectedProperty;
protected $toBePrivateProperty;
}
?>
-----
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInherits extends ParentObject
{
protected $toBeProtectedProperty;
private $toBePrivateProperty;
}
?>

View File

@ -0,0 +1,25 @@
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInheritsAgain extends ParentObject
{
private static $toBePublicStaticProperty;
}
?>
-----
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
use Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Source\ParentObject;
class ClassThatInheritsAgain extends ParentObject
{
public static $toBePublicStaticProperty;
}
?>

View File

@ -0,0 +1,21 @@
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
class Fixture3
{
private static $toBePublicStaticProperty;
}
?>
-----
<?php
namespace Rector\Visibility\Tests\Rector\Property\ChangePropertyVisibilityRector\Fixture;
class Fixture3
{
public static $toBePublicStaticProperty;
}
?>

View File

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

View File

@ -540,6 +540,16 @@ final class NodeFactory
return $param;
}
public function createFalse(): ConstFetch
{
return new ConstFetch(new Name('false'));
}
public function createTrue(): ConstFetch
{
return new ConstFetch(new Name('true'));
}
private function createClassConstFetchFromName(Name $className, string $constantName): ClassConstFetch
{
$classConstFetch = $this->builderFactory->classConstFetch($className, $constantName);

View File

@ -76,12 +76,12 @@ trait NodeFactoryTrait
protected function createFalse(): ConstFetch
{
return new ConstFetch(new Name('false'));
return $this->nodeFactory->createFalse();
}
protected function createTrue(): ConstFetch
{
return new ConstFetch(new Name('true'));
return $this->nodeFactory->createTrue();
}
/**