Merge pull request #3103 from rectorphp/move-privatization-constant

move constant privatization to privatization set
This commit is contained in:
Tomas Votruba 2020-03-29 20:14:55 +02:00 committed by GitHub
commit 1c30867c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 95 additions and 96 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
class SkipMulti
{

View File

@ -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';
}

View File

@ -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;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Fixture;
class UsesConstant
{

View File

@ -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
{

View File

@ -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
{

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Rector\Privatization\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
abstract class AbstractVariableParentClassUser
{
}

View File

@ -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
{

View File

@ -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;
}
}

View File

@ -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';
}

View File

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\SOLID\Tests\Rector\ClassConst\PrivatizeLocalClassConstantRector\Source;
abstract class AbstractVariableParentClassUser
{
}