Skip to content

Commit 3b1df04

Browse files
authored
deprecate RealToFloatTypeCastRector over RenameCastRector (rectorphp#7500)
1 parent b9aecce commit 3b1df04

File tree

7 files changed

+12
-93
lines changed

7 files changed

+12
-93
lines changed

rules-tests/Php74/Rector/Double/RealToFloatTypeCastRector/Fixture/fixture.php.inc

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

rules-tests/Php74/Rector/Double/RealToFloatTypeCastRector/RealToFloatTypeCastRectorTest.php

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

rules-tests/Php74/Rector/Double/RealToFloatTypeCastRector/config/configured_rule.php

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

rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ private function cleanCastedExpr(Expr $expr): Expr
137137

138138
private function hasCallLikeInAssignExpr(Expr $expr): bool
139139
{
140-
return (bool) $this->betterNodeFinder->findFirst(
141-
$expr,
142-
$this->sideEffectNodeDetector->detectCallExpr(...)
143-
);
140+
return (bool) $this->betterNodeFinder->findFirst($expr, $this->sideEffectNodeDetector->detectCallExpr(...));
144141
}
145142

146143
/**

rules/DeadCode/SideEffect/SideEffectNodeDetector.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ public function detect(Expr $expr): bool
4848
return true;
4949
}
5050

51-
return (bool) $this->betterNodeFinder->findFirst(
52-
$expr,
53-
$this->detectCallExpr(...)
54-
);
51+
return (bool) $this->betterNodeFinder->findFirst($expr, $this->detectCallExpr(...));
5552
}
5653

5754
public function detectCallExpr(Node $node): bool

rules/Php74/Rector/Double/RealToFloatTypeCastRector.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
namespace Rector\Php74\Rector\Double;
66

7+
use Rector\Renaming\Rector\Cast\RenameCastRector;
78
use PhpParser\Node;
89
use PhpParser\Node\Expr\Cast\Double;
9-
use Rector\NodeTypeResolver\Node\AttributeKey;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
11+
use Rector\Exception\ShouldNotHappenException;
1012
use Rector\Rector\AbstractRector;
1113
use Rector\ValueObject\PhpVersionFeature;
1214
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
1315
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1416
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1517

1618
/**
17-
* @see \Rector\Tests\Php74\Rector\Double\RealToFloatTypeCastRector\RealToFloatTypeCastRectorTest
19+
* @deprecated Use same but configurable `Rector\Renaming\Rector\Cast\RenameCastRector` with configuration instead
1820
*/
19-
final class RealToFloatTypeCastRector extends AbstractRector implements MinPhpVersionInterface
21+
final class RealToFloatTypeCastRector extends AbstractRector implements MinPhpVersionInterface, DeprecatedInterface
2022
{
2123
public function provideMinPhpVersion(): int
2224
{
@@ -67,14 +69,9 @@ public function getNodeTypes(): array
6769
*/
6870
public function refactor(Node $node): ?Node
6971
{
70-
$kind = $node->getAttribute(AttributeKey::KIND);
71-
if ($kind !== Double::KIND_REAL) {
72-
return null;
73-
}
74-
75-
$node->setAttribute(AttributeKey::KIND, Double::KIND_FLOAT);
76-
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
77-
78-
return $node;
72+
throw new ShouldNotHappenException(sprintf(
73+
'This rule is deprecated. Use configurable "%s" rule instead.',
74+
RenameCastRector::class,
75+
));
7976
}
8077
}

src/Util/ArrayParametersMerger.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ final class ArrayParametersMerger
1515
public function merge(mixed $left, mixed $right): mixed
1616
{
1717
if (is_array($left) && is_array($right)) {
18-
return $this->mergeLeftToRightWithCallable(
19-
$left,
20-
$right,
21-
$this->merge(...)
22-
);
18+
return $this->mergeLeftToRightWithCallable($left, $right, $this->merge(...));
2319
}
2420

2521
if ($left !== null) {

0 commit comments

Comments
 (0)