-
-
Notifications
You must be signed in to change notification settings - Fork 742
Closed
rectorphp/rector-src
#7153Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | v2.1.4 |
When using RenameCastRector, parentheses around expressions are removed incorrectly, changing the meaning of the code.
Minimal PHP Code Causing Issue
- $val = (integer) ($i * $i);
+ $val = (int) $i * $i; // incorrect: parentheses removedExpected Behaviour
- $val = (integer) ($i * $i);
+ $val = (int) ($i * $i); // correct: parentheses preservedI tried creating a reproduction link with the following configs, but keep getting greeted with the Expected config should return callable RectorConfig instance warning:
Reproduction
final class DemoFile
{
public function run(float $i): int
{
return (integer) ($i * $i);
}
}<?php
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\Cast\Double;
use PhpParser\Node\Expr\Cast\Int_;
use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;
use Rector\Renaming\Rector\Cast\RenameCastRector;
use Rector\Renaming\ValueObject\RenameCast;
return RectorConfig::configure()
->withConfiguredRule(
RenameCastRector::class,
[
new RenameCast(Int_::class, Int_::KIND_INTEGER, Int_::KIND_INT),
new RenameCast(Bool_::class, Bool_::KIND_BOOLEAN, Bool_::KIND_BOOL),
new RenameCast(Double::class, Double::KIND_DOUBLE, Double::KIND_FLOAT),
],
)
->withPhpVersion(PhpVersion::PHP_84);Reactions are currently unavailable