Skip to content

Commit 29cb907

Browse files
committed
add rector + test
1 parent eb48166 commit 29cb907

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\RectorCompatTests\Rector;
6+
7+
use PhpParser\Modifiers;
8+
use PhpParser\Node;
9+
use PhpParser\Node\Stmt\Class_;
10+
use Rector\Rector\AbstractRector;
11+
12+
final class MakeClassFinalRector extends AbstractRector
13+
{
14+
/**
15+
* @return array<class-string<Class_>>
16+
*/
17+
public function getNodeTypes(): array
18+
{
19+
return [Class_::class];
20+
}
21+
22+
/**
23+
* @param Class_ $node
24+
*/
25+
public function refactor(Node $node)
26+
{
27+
if ($node->isFinal()) {
28+
return null;
29+
}
30+
31+
$node->flags |= Modifiers::FINAL;
32+
33+
return $node;
34+
}
35+
}

tests/PHPStan/CustomPHPStanRule/CustomPHPStanRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ protected function getRule(): Rule
2121
{
2222
return new CustomPHPStanRule();
2323
}
24-
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\RectorCompatTests\Tests\Rector\MakeClassFinalRector\Fixture;
4+
5+
class SomeNonFinalClass
6+
{
7+
}
8+
9+
?>
10+
-----
11+
<?php
12+
13+
namespace Rector\RectorCompatTests\Tests\Rector\MakeClassFinalRector\Fixture;
14+
15+
final class SomeNonFinalClass
16+
{
17+
}
18+
19+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\RectorCompatTests\Tests\Rector\MakeClassFinalRector;
4+
5+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
6+
7+
final class MakeClassFinalRectorTest extends AbstractRectorTestCase
8+
{
9+
public function test(): void
10+
{
11+
$this->doTestFile(__DIR__ . '/Fixture/some_non_final_class.php.inc');
12+
}
13+
14+
public function provideConfigFilePath(): string
15+
{
16+
return __DIR__ . '/config/configured_rule.php';
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\RectorCompatTests\Rector\MakeClassFinalRector;
7+
8+
return RectorConfig::configure()
9+
->withRules([MakeClassFinalRector::class]);

0 commit comments

Comments
 (0)