Skip to content

Commit 25da8c2

Browse files
committed
[Removing] Deprecate RemoveTraitUseRector as niche, never used and needs context
1 parent 1ee57e1 commit 25da8c2

6 files changed

Lines changed: 8 additions & 114 deletions

File tree

‎phpstan.neon‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ parameters:
236236
identifier: rector.registerRector
237237
paths:
238238
- rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php
239-
- rules/Removing/Rector/Class_/RemoveTraitUseRector.php
240239
- rules/Transform/Rector/String_/StringToClassConstantRector.php
241240

242241
# lack of generic array in nikic/php-parser

‎rules-tests/Removing/Rector/Class_/RemoveTraitUseRector/Fixture/fixture.php.inc‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎rules-tests/Removing/Rector/Class_/RemoveTraitUseRector/RemoveTraitUseRectorTest.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/Removing/Rector/Class_/RemoveTraitUseRector/Source/TraitToBeRemoved.php‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎rules-tests/Removing/Rector/Class_/RemoveTraitUseRector/config/configured_rule.php‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎rules/Removing/Rector/Class_/RemoveTraitUseRector.php‎

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Class_;
99
use PhpParser\Node\Stmt\Trait_;
10-
use PhpParser\Node\Stmt\TraitUse;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1111
use Rector\Contract\Rector\ConfigurableRectorInterface;
12+
use Rector\Exception\ShouldNotHappenException;
1213
use Rector\Rector\AbstractRector;
1314
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
1415
use Rector\RuleDoc\RuleDefinition;
15-
use Webmozart\Assert\Assert;
1616

1717
/**
18-
* @see \Rector\Tests\Removing\Rector\Class_\RemoveTraitUseRector\RemoveTraitUseRectorTest
18+
* @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead.
1919
*/
20-
final class RemoveTraitUseRector extends AbstractRector implements ConfigurableRectorInterface
20+
final class RemoveTraitUseRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2121
{
22-
/**
23-
* @var string[]
24-
*/
25-
private array $traitsToRemove = [];
26-
2722
public function getRuleDefinition(): RuleDefinition
2823
{
2924
return new RuleDefinition('Remove specific traits from code', [
@@ -59,42 +54,16 @@ public function getNodeTypes(): array
5954
*/
6055
public function refactor(Node $node): ?Node
6156
{
62-
$hasChanged = false;
63-
64-
foreach ($node->stmts as $key => $stmt) {
65-
if (! $stmt instanceof TraitUse) {
66-
continue;
67-
}
68-
69-
foreach ($stmt->traits as $traitKey => $trait) {
70-
if (! $this->isNames($trait, $this->traitsToRemove)) {
71-
continue;
72-
}
73-
74-
unset($stmt->traits[$traitKey]);
75-
$hasChanged = true;
76-
}
77-
78-
// remove empty trait uses
79-
if ($stmt->traits === []) {
80-
unset($node->stmts[$key]);
81-
}
82-
}
83-
84-
if ($hasChanged) {
85-
return $node;
86-
}
87-
88-
return null;
57+
throw new ShouldNotHappenException(sprintf(
58+
'"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead',
59+
self::class
60+
));
8961
}
9062

9163
/**
9264
* @param mixed[] $configuration
9365
*/
9466
public function configure(array $configuration): void
9567
{
96-
Assert::allString($configuration);
97-
98-
$this->traitsToRemove = $configuration;
9968
}
10069
}

0 commit comments

Comments
 (0)