Skip to content

Commit d7d5db3

Browse files
committed
[Transform] Deprecate StringToClassConstantRector as niche, never used and needs context
1 parent 1ee57e1 commit d7d5db3

7 files changed

Lines changed: 11 additions & 116 deletions

File tree

‎phpstan.neon‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ parameters:
237237
paths:
238238
- rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php
239239
- rules/Removing/Rector/Class_/RemoveTraitUseRector.php
240-
- rules/Transform/Rector/String_/StringToClassConstantRector.php
241240

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

‎rules-tests/Transform/Rector/String_/StringToClassConstantRector/Fixture/fixture.php.inc‎

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

‎rules-tests/Transform/Rector/String_/StringToClassConstantRector/Fixture/skip_not_found_in_enum_case.php.inc‎

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

‎rules-tests/Transform/Rector/String_/StringToClassConstantRector/StringToClassConstantRectorTest.php‎

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

‎rules-tests/Transform/Rector/String_/StringToClassConstantRector/config/configured_rule.php‎

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

‎rules/Transform/Rector/String_/StringToClassConstantRector.php‎

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,19 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Scalar\String_;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
910
use Rector\Contract\Rector\ConfigurableRectorInterface;
10-
use Rector\PhpParser\Node\Value\ValueResolver;
11+
use Rector\Exception\ShouldNotHappenException;
1112
use Rector\Rector\AbstractRector;
1213
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
1314
use Rector\RuleDoc\RuleDefinition;
1415
use Rector\Transform\ValueObject\StringToClassConstant;
15-
use Webmozart\Assert\Assert;
1616

1717
/**
18-
* @see \Rector\Tests\Transform\Rector\String_\StringToClassConstantRector\StringToClassConstantRectorTest
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 StringToClassConstantRector extends AbstractRector implements ConfigurableRectorInterface
20+
final class StringToClassConstantRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2121
{
22-
/**
23-
* @var StringToClassConstant[]
24-
*/
25-
private array $stringsToClassConstants = [];
26-
27-
public function __construct(
28-
private readonly ValueResolver $valueResolver
29-
) {
30-
}
31-
3222
public function getRuleDefinition(): RuleDefinition
3323
{
3424
return new RuleDefinition('Change strings to specific constants', [
@@ -71,27 +61,16 @@ public function getNodeTypes(): array
7161
*/
7262
public function refactor(Node $node): ?Node
7363
{
74-
foreach ($this->stringsToClassConstants as $stringToClassConstant) {
75-
if (! $this->valueResolver->isValue($node, $stringToClassConstant->getString())) {
76-
continue;
77-
}
78-
79-
return $this->nodeFactory->createClassConstFetch(
80-
$stringToClassConstant->getClass(),
81-
$stringToClassConstant->getConstant()
82-
);
83-
}
84-
85-
return null;
64+
throw new ShouldNotHappenException(sprintf(
65+
'"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead',
66+
self::class
67+
));
8668
}
8769

8870
/**
8971
* @param mixed[] $configuration
9072
*/
9173
public function configure(array $configuration): void
9274
{
93-
Assert::allIsAOf($configuration, StringToClassConstant::class);
94-
95-
$this->stringsToClassConstants = $configuration;
9675
}
9776
}

‎rules/Transform/ValueObject/StringToClassConstant.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 used in deprecated StringToClassConstantRector configs
11+
*/
912
final readonly class StringToClassConstant
1013
{
1114
public function __construct(

0 commit comments

Comments
 (0)