mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
Merge pull request #3103 from rectorphp/move-privatization-constant
move constant privatization to privatization set
This commit is contained in:
commit
1c30867c18
@ -2,3 +2,4 @@ services:
|
||||
Rector\Privatization\Rector\ClassMethod\PrivatizeLocalOnlyMethodRector: null
|
||||
Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector: null
|
||||
Rector\Privatization\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector: null
|
||||
Rector\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector: null
|
||||
|
@ -1,7 +1,5 @@
|
||||
services:
|
||||
Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector: null
|
||||
|
||||
Rector\SOLID\Rector\ClassConst\PrivatizeLocalClassConstantRector: null
|
||||
Rector\SOLID\Rector\Class_\MakeUnusedClassesWithChildrenAbstractRector: null
|
||||
Rector\SOLID\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector: null
|
||||
Rector\SOLID\Rector\ClassMethod\ChangeReadOnlyVariableWithDefaultValueToConstantRector: null
|
||||
|
@ -7834,6 +7834,28 @@ Remove php version checks if they are passed
|
||||
|
||||
## Privatization
|
||||
|
||||
### `PrivatizeLocalClassConstantRector`
|
||||
|
||||
- class: [`Rector\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector`](/../master/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php)
|
||||
- [test fixtures](/../master/rules/privatization/tests/Rector/ClassConst/PrivatizeLocalClassConstantRector/Fixture)
|
||||
|
||||
Finalize every class constant that is used only locally
|
||||
|
||||
```diff
|
||||
class ClassWithConstantUsedOnlyHere
|
||||
{
|
||||
- const LOCAL_ONLY = true;
|
||||
+ private const LOCAL_ONLY = true;
|
||||
|
||||
public function isLocalOnly()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `PrivatizeLocalGetterToPropertyRector`
|
||||
|
||||
- class: [`Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector`](/../master/rules/privatization/src/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php)
|
||||
@ -8657,28 +8679,6 @@ Classes that have no children nor are used, should have abstract
|
||||
|
||||
<br>
|
||||
|
||||
### `PrivatizeLocalClassConstantRector`
|
||||
|
||||
- class: [`Rector\SOLID\Rector\ClassConst\PrivatizeLocalClassConstantRector`](/../master/rules/solid/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php)
|
||||
- [test fixtures](/../master/rules/solid/tests/Rector/ClassConst/PrivatizeLocalClassConstantRector/Fixture)
|
||||
|
||||
Finalize every class constant that is used only locally
|
||||
|
||||
```diff
|
||||
class ClassWithConstantUsedOnlyHere
|
||||
{
|
||||
- const LOCAL_ONLY = true;
|
||||
+ private const LOCAL_ONLY = true;
|
||||
|
||||
public function isLocalOnly()
|
||||
{
|
||||
return self::LOCAL_ONLY;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### `RemoveAlwaysElseRector`
|
||||
|
||||
- class: [`Rector\SOLID\Rector\If_\RemoveAlwaysElseRector`](/../master/rules/solid/src/Rector/If_/RemoveAlwaysElseRector.php)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\SOLID\Rector\ClassConst;
|
||||
namespace Rector\Privatization\Rector\ClassConst;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
@ -17,7 +17,7 @@ use Rector\SOLID\Reflection\ParentConstantReflectionResolver;
|
||||
use Rector\SOLID\ValueObject\ConstantVisibility;
|
||||
|
||||
/**
|
||||
* @see \Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\PrivatizeLocalClassConstantRectorTest
|
||||
* @see \Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\PrivatizeLocalClassConstantRectorTest
|
||||
*/
|
||||
final class PrivatizeLocalClassConstantRector extends AbstractRector
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedOnlyHere
|
||||
{
|
||||
@ -16,7 +16,7 @@ class ClassWithConstantUsedOnlyHere
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedOnlyHere
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface InterfaceWithConstant
|
||||
{
|
||||
@ -19,7 +19,7 @@ class ClassExtendingInterface implements InterfaceWithConstant
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface InterfaceWithConstant
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface YetAnotherInterfaceWithConstant
|
||||
{
|
||||
@ -27,7 +27,7 @@ class YetForeigner
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface YetAnotherInterfaceWithConstant
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface AnotherInterfaceWithConstant
|
||||
{
|
||||
@ -27,7 +27,7 @@ class Foreigner
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
interface AnotherInterfaceWithConstant
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedSomewhereElse
|
||||
{
|
||||
@ -19,7 +19,7 @@ class ForeignConstantAddictUser
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class ClassWithConstantUsedSomewhereElse
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
// The class using the constant must be parsed first
|
||||
class ForeignConstantAddictUser2
|
||||
@ -25,7 +25,7 @@ class ClassWithConstantUsedSomewhereElse2 extends ClassWithConstantUsedSomewhere
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
// The class using the constant must be parsed first
|
||||
class ForeignConstantAddictUser2
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class OverridingProtectedConstantClass extends DeclaringProtectedConstantClass
|
||||
{
|
||||
@ -24,7 +24,7 @@ class DeclaringProtectedConstantClass
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class OverridingProtectedConstantClass extends DeclaringProtectedConstantClass
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MiddleExtendingClass extends DeclaringPublicConstantClass
|
||||
{
|
||||
@ -28,7 +28,7 @@ class PublicConstantUser
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MiddleExtendingClass extends DeclaringPublicConstantClass
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MakeConstantProtected
|
||||
{
|
||||
@ -22,7 +22,7 @@ class ConstantUser extends MakeConstantProtected
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class MakeConstantProtected
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class FirstParent
|
||||
{
|
||||
@ -23,7 +23,7 @@ final class FirstBorn extends SecondParent
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class FirstParent
|
||||
{
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractInBetweenVariableParentClassUser;
|
||||
use Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractVariableParentClassUser;
|
||||
|
||||
class SkipMultiInheritance extends AbstractInBetweenVariableParentClassUser
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const SHORT_NAME = '@Id';
|
||||
}
|
||||
|
||||
class TheVariableUse
|
||||
{
|
||||
public function run(AbstractVariableParentClassUser $value)
|
||||
{
|
||||
return $value::SHORT_NAME;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class SkipMulti
|
||||
{
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\SomeProtectedParentClass;
|
||||
|
||||
class SkipParentClassProtected extends SomeProtectedParentClass
|
||||
{
|
||||
protected const SOME_CONST = 'changed_value';
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\CodingStyle\Tests\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Fixture\ParentClass;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
class UsesConstant
|
||||
{
|
@ -2,11 +2,11 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\SOLID\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
use Rector\Privatization\Rector\ClassConst\PrivatizeLocalClassConstantRector;
|
||||
|
||||
final class PrivatizeLocalClassConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractInBetweenVariableParentClassUser extends AbstractVariableParentClassUser
|
||||
{
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractVariableParentClassUser
|
||||
{
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class SomeProtectedParentClass
|
||||
{
|
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractInBetweenVariableParentClassUser;
|
||||
use Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\AbstractVariableParentClassUser;
|
||||
|
||||
class SkipMultiInheritance extends AbstractInBetweenVariableParentClassUser
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const SHORT_NAME = '@Id';
|
||||
}
|
||||
|
||||
class TheVariableUse
|
||||
{
|
||||
public function run(AbstractVariableParentClassUser $value)
|
||||
{
|
||||
return $value::SHORT_NAME;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
|
||||
|
||||
use Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source\SomeProtectedParentClass;
|
||||
|
||||
class SkipParentClassProtected extends SomeProtectedParentClass
|
||||
{
|
||||
protected const SOME_CONST = 'changed_value';
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
|
||||
|
||||
abstract class AbstractVariableParentClassUser
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user