Skip to content

Commit 38d4db3

Browse files
committed
[Transform] Deprecate FuncCallToNewRector as niche, never used and needs context
1 parent 411cdf4 commit 38d4db3

5 files changed

Lines changed: 8 additions & 98 deletions

File tree

‎phpstan.neon‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ parameters:
238238
- rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php
239239
- rules/Removing/Rector/Class_/RemoveTraitUseRector.php
240240
- rules/Renaming/Rector/StaticCall/RenameStaticMethodRector.php
241-
- rules/Transform/Rector/FuncCall/FuncCallToNewRector.php
242-
- rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php
243241
- rules/Transform/Rector/String_/StringToClassConstantRector.php
244242

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

‎rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/Fixture/fixture.php.inc‎

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

‎rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/FuncCallToNewRectorTest.php‎

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

‎rules-tests/Transform/Rector/FuncCall/FuncCallToNewRector/config/configured_rule.php‎

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

‎rules/Transform/Rector/FuncCall/FuncCallToNewRector.php‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\FuncCall;
9-
use PhpParser\Node\Expr\New_;
10-
use PhpParser\Node\Name\FullyQualified;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1110
use Rector\Contract\Rector\ConfigurableRectorInterface;
11+
use Rector\Exception\ShouldNotHappenException;
1212
use Rector\Rector\AbstractRector;
1313
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
1414
use Rector\RuleDoc\RuleDefinition;
15-
use Webmozart\Assert\Assert;
1615

1716
/**
18-
* @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest
17+
* @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead.
1918
*/
20-
final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface
19+
final class FuncCallToNewRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2120
{
22-
/**
23-
* @var string[]
24-
*/
25-
private array $functionToNew = [];
26-
2721
public function getRuleDefinition(): RuleDefinition
2822
{
2923
return new RuleDefinition('Change configured function calls to new Instance', [
@@ -68,30 +62,16 @@ public function getNodeTypes(): array
6862
*/
6963
public function refactor(Node $node): ?Node
7064
{
71-
$funcName = $this->getName($node);
72-
if ($funcName === null) {
73-
return null;
74-
}
75-
76-
$new = $this->functionToNew[strtolower($funcName)] ?? null;
77-
if ($new === null) {
78-
return null;
79-
}
80-
81-
return new New_(new FullyQualified($new), $node->args);
65+
throw new ShouldNotHappenException(sprintf(
66+
'"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead',
67+
self::class
68+
));
8269
}
8370

8471
/**
8572
* @param mixed[] $configuration
8673
*/
8774
public function configure(array $configuration): void
8875
{
89-
Assert::allString($configuration);
90-
91-
// keyed by lowercased function name (function names are case-insensitive)
92-
$this->functionToNew = [];
93-
foreach ($configuration as $function => $new) {
94-
$this->functionToNew[strtolower($function)] = $new;
95-
}
9676
}
9777
}

0 commit comments

Comments
 (0)