Skip to content

Commit 34ee695

Browse files
authored
[Transform] Deprecate NewToStaticCallRector as too niche and requiring careful context (#8768)
1 parent 56d303c commit 34ee695

8 files changed

Lines changed: 10 additions & 189 deletions

File tree

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/Fixture/fixture.php.inc‎

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

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/Fixture/skip_another_class.php.inc‎

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

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/NewToStaticCallRectorTest.php‎

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

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/Source/FromNewClass.php‎

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

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/Source/IntoStaticClass.php‎

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

‎rules-tests/Transform/Rector/New_/NewToStaticCallRector/config/configured_rule.php‎

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

‎rules/Transform/Rector/New_/NewToStaticCallRector.php‎

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\New_;
9-
use Rector\Contract\Rector\ConfigurableRectorInterface;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
1011
use Rector\Rector\AbstractRector;
11-
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
12+
use Rector\RuleDoc\CodeSample\CodeSample;
1213
use Rector\RuleDoc\RuleDefinition;
13-
use Rector\Transform\ValueObject\NewToStaticCall;
14-
use Webmozart\Assert\Assert;
1514

1615
/**
17-
* @see \Rector\Tests\Transform\Rector\New_\NewToStaticCallRector\NewToStaticCallRectorTest
16+
* @deprecated This rule is deprecated, as too niche, never used, and requires careful context to pick the correct static call. Write a custom rule for the exact project case instead.
1817
*/
19-
final class NewToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface
18+
final class NewToStaticCallRector extends AbstractRector implements DeprecatedInterface
2019
{
21-
/**
22-
* @var NewToStaticCall[]
23-
*/
24-
private array $typeToStaticCalls = [];
25-
2620
public function getRuleDefinition(): RuleDefinition
2721
{
2822
return new RuleDefinition('Change new Object to static call', [
29-
new ConfiguredCodeSample(
23+
new CodeSample(
3024
<<<'CODE_SAMPLE'
3125
class SomeClass
3226
{
@@ -46,8 +40,6 @@ public function run()
4640
}
4741
}
4842
CODE_SAMPLE
49-
,
50-
[new NewToStaticCall('Cookie', 'Cookie', 'create')]
5143
),
5244
]);
5345
}
@@ -65,28 +57,9 @@ public function getNodeTypes(): array
6557
*/
6658
public function refactor(Node $node): ?Node
6759
{
68-
foreach ($this->typeToStaticCalls as $typeToStaticCall) {
69-
if (! $this->isObjectType($node->class, $typeToStaticCall->getObjectType())) {
70-
continue;
71-
}
72-
73-
return $this->nodeFactory->createStaticCall(
74-
$typeToStaticCall->getStaticCallClass(),
75-
$typeToStaticCall->getStaticCallMethod(),
76-
$node->args
77-
);
78-
}
79-
80-
return null;
81-
}
82-
83-
/**
84-
* @param mixed[] $configuration
85-
*/
86-
public function configure(array $configuration): void
87-
{
88-
Assert::allIsAOf($configuration, NewToStaticCall::class);
89-
90-
$this->typeToStaticCalls = $configuration;
60+
throw new ShouldNotHappenException(sprintf(
61+
'"%s" rule is deprecated, as too niche and never used. Write a custom rule for the exact project case instead',
62+
self::class
63+
));
9164
}
9265
}

‎rules/Transform/ValueObject/NewToStaticCall.php‎

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

0 commit comments

Comments
 (0)