Skip to content

Commit 5cb4bc5

Browse files
authored
[Transform] Deprecate ConstFetchToClassConstFetchRector as niche and never used (#8771)
* [Transform] Deprecate ConstFetchToClassConstFetchRector as niche and never used * mark ConstFetchToClassConstFetch VO as @api to skip unused-public
1 parent 8bf6146 commit 5cb4bc5

5 files changed

Lines changed: 14 additions & 80 deletions

File tree

‎rules-tests/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector/ConstFetchToClassConstFetchTest.php‎

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

‎rules-tests/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector/Fixture/fixture1.php.inc‎

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

‎rules-tests/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector/config/configured_rule.php‎

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

‎rules/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector.php‎

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\ClassConstFetch;
99
use PhpParser\Node\Expr\ConstFetch;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1011
use Rector\Contract\Rector\ConfigurableRectorInterface;
12+
use Rector\Exception\ShouldNotHappenException;
1113
use Rector\Rector\AbstractRector;
1214
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
1315
use Rector\RuleDoc\RuleDefinition;
1416
use Rector\Transform\ValueObject\ConstFetchToClassConstFetch;
15-
use Webmozart\Assert\Assert;
1617

1718
/**
18-
* @see Rector\Tests\Transform\Rector\ConstFetch\ConstFetchToClassConstFetchRector\ConstFetchToClassConstFetchTest
19+
* @deprecated This rule is deprecated, as too niche and never used. A global const name can be reused across unrelated contexts and does not map cleanly to a single class constant. Use a custom rule scoped to your exact case instead.
1920
*/
20-
final class ConstFetchToClassConstFetchRector extends AbstractRector implements ConfigurableRectorInterface
21+
final class ConstFetchToClassConstFetchRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2122
{
22-
/**
23-
* @var array<string, ConstFetchToClassConstFetch[]>
24-
*/
25-
private array $constFetchToClassConstsByOldName = [];
26-
2723
public function getRuleDefinition(): RuleDefinition
2824
{
2925
return new RuleDefinition('Change const fetch to class const fetch', [
@@ -43,28 +39,16 @@ public function getNodeTypes(): array
4339
*/
4440
public function refactor(Node $node): ?ClassConstFetch
4541
{
46-
$constName = $this->getName($node);
47-
if ($constName === null) {
48-
return null;
49-
}
50-
51-
foreach ($this->constFetchToClassConstsByOldName[strtolower($constName)] ?? [] as $constFetchToClassConst) {
52-
return $this->nodeFactory->createClassConstFetch(
53-
$constFetchToClassConst->getNewClassName(),
54-
$constFetchToClassConst->getNewConstName()
55-
);
56-
}
57-
58-
return null;
42+
throw new ShouldNotHappenException(sprintf(
43+
'"%s" rule is deprecated, as too niche and never used; use a custom rule scoped to your exact case instead',
44+
self::class
45+
));
5946
}
6047

48+
/**
49+
* @param mixed[] $configuration
50+
*/
6151
public function configure(array $configuration): void
6252
{
63-
Assert::allIsAOf($configuration, ConstFetchToClassConstFetch::class);
64-
65-
$this->constFetchToClassConstsByOldName = [];
66-
foreach ($configuration as $constFetchToClassConst) {
67-
$this->constFetchToClassConstsByOldName[strtolower($constFetchToClassConst->getOldConstName())][] = $constFetchToClassConst;
68-
}
6953
}
7054
}

‎rules/Transform/ValueObject/ConstFetchToClassConstFetch.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Rector\Validation\RectorAssert;
88

9+
/**
10+
* @api kept for deprecated ConstFetchToClassConstFetchRector code sample
11+
*/
912
final readonly class ConstFetchToClassConstFetch
1013
{
1114
public function __construct(

0 commit comments

Comments
 (0)