mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
Merge pull request #3219 from rectorphp/unfinal-entity
[Restoration] Add RemoveFinalFromEntityRector
This commit is contained in:
commit
05add9f74c
@ -267,7 +267,7 @@
|
||||
"bin/rector dump-rectors > docs/AllRectorsOverview.md",
|
||||
"bin/rector dump-nodes > docs/NodesOverview.md"
|
||||
],
|
||||
"rector-ci": "bin/rector process --config rector-ci.yaml --debug --dry-run",
|
||||
"rector-ci": "bin/rector process --config rector-ci.yaml --dry-run",
|
||||
"rector": "bin/rector process --config rector-ci.yaml --ansi"
|
||||
},
|
||||
"config": {
|
||||
|
@ -1,4 +1,4 @@
|
||||
# All 498 Rectors Overview
|
||||
# All 499 Rectors Overview
|
||||
|
||||
- [Projects](#projects)
|
||||
- [General](#general)
|
||||
@ -8880,6 +8880,27 @@ Convert missing class reference to string
|
||||
|
||||
<br>
|
||||
|
||||
### `RemoveFinalFromEntityRector`
|
||||
|
||||
- class: [`Rector\Restoration\Rector\Class_\RemoveFinalFromEntityRector`](/../master/rules/restoration/src/Rector/Class_/RemoveFinalFromEntityRector.php)
|
||||
- [test fixtures](/../master/rules/restoration/tests/Rector/Class_/RemoveFinalFromEntityRector/Fixture)
|
||||
|
||||
Remove final from Doctrine entities
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
-final class SomeClass
|
||||
+class SomeClass
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## SOLID
|
||||
|
||||
### `ChangeIfElseValueAssignToEarlyReturnRector`
|
||||
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Restoration\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\Restoration\Tests\Rector\Class_\RemoveFinalFromEntityRector\RemoveFinalFromEntityRectorTest
|
||||
*/
|
||||
final class RemoveFinalFromEntityRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Remove final from Doctrine entities', [
|
||||
new CodeSample(
|
||||
<<<'PHP'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
final class SomeClass
|
||||
{
|
||||
}
|
||||
PHP
|
||||
,
|
||||
<<<'PHP'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeClass
|
||||
{
|
||||
}
|
||||
PHP
|
||||
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isDoctrineEntityClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $node->isFinal()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->removeFinal($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Restoration\Tests\Rector\Class_\RemoveFinalFromEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
final class SomeClass
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Restoration\Tests\Rector\Class_\RemoveFinalFromEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeClass
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Restoration\Tests\Rector\Class_\RemoveFinalFromEntityRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\Restoration\Rector\Class_\RemoveFinalFromEntityRector;
|
||||
|
||||
final class RemoveFinalFromEntityRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $file): void
|
||||
{
|
||||
$this->doTestFile($file);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return RemoveFinalFromEntityRector::class;
|
||||
}
|
||||
}
|
@ -44,4 +44,9 @@ trait AbstractRectorTrait
|
||||
|
||||
return ! Strings::contains($name, 'AnonymousClass');
|
||||
}
|
||||
|
||||
protected function removeFinal(Class_ $node): void
|
||||
{
|
||||
$node->flags -= Class_::MODIFIER_FINAL;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user