Skip to content

Commit cddeaad

Browse files
committed
Add PrivatizeFinalClassConstantRector
1 parent e20f1c9 commit cddeaad

File tree

14 files changed

+290
-0
lines changed

14 files changed

+290
-0
lines changed

config/set/privatization.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector;
67
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
78
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
89
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
@@ -12,5 +13,6 @@
1213
PrivatizeLocalGetterToPropertyRector::class,
1314
PrivatizeFinalClassPropertyRector::class,
1415
PrivatizeFinalClassMethodRector::class,
16+
PrivatizeFinalClassConstantRector::class,
1517
]);
1618
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
4+
5+
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Source\AbstractClassWithProtectedClassConst;
6+
7+
final class ChangeParentWithoutCare extends AbstractClassWithProtectedClassConst
8+
{
9+
protected const PROTECTED_LOCAL_CONST = 'local';
10+
}
11+
?>
12+
-----
13+
<?php
14+
15+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
16+
17+
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Source\AbstractClassWithProtectedClassConst;
18+
19+
final class ChangeParentWithoutCare extends AbstractClassWithProtectedClassConst
20+
{
21+
private const PROTECTED_LOCAL_CONST = 'local';
22+
}
23+
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
4+
5+
final class Fixture
6+
{
7+
protected const SOME_CONSTANT = 'some-value';
8+
}
9+
10+
?>
11+
-----
12+
<?php
13+
14+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
15+
16+
final class Fixture
17+
{
18+
private const SOME_CONSTANT = 'some-value';
19+
}
20+
21+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
4+
5+
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Source\AbstractClassWithProtectedClassConst;
6+
7+
final class KeepParentProtectedConst extends AbstractClassWithProtectedClassConst
8+
{
9+
protected const PROTECTED_CONST = 5;
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
4+
5+
/**
6+
* @final
7+
*/
8+
class SkipFinalDocblock
9+
{
10+
protected const SOME_CONSTANT = 'some-value';
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
6+
7+
final class SkipMultiConsts
8+
{
9+
protected const FIRST_VAL = 'a', SECOND_VAL = 'b';
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Fixture;
4+
5+
use Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Source\SomeTraitWithConst;
6+
7+
final class SkipTraitUsed
8+
{
9+
use SomeTraitWithConst;
10+
11+
protected const PROTECTED_TRAIT_CONST = 3;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Rector\Tests\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector\Fixture;
4+
5+
final class SkipUnknownParentClass extends SomeUnknownParent
6+
{
7+
protected const SOME_CONSTANT = 'some-value';
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class PrivatizeFinalClassConstantRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Privatization\Rector\ClassConst\PrivatizeFinalClassConstantRector\Source;
6+
7+
abstract class AbstractClassWithProtectedClassConst
8+
{
9+
protected const PROTECTED_CONST = 3;
10+
}

0 commit comments

Comments
 (0)