Skip to content

Commit 1f1cb35

Browse files
authored
[CodeQuality] Handle with parentheses on SimplifyIfReturnBoolRector (#6871)
* [CodeQuality] Handle with parentheses on SimplifyIfReturnBoolRector * [CodeQuality] Handle with parentheses on SimplifyIfReturnBoolRector * Fix phpstan
1 parent a59e869 commit 1f1cb35

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,6 @@ parameters:
325325

326326
# list vs array
327327
- '#Parameter (.*?) expects list<(.*?)>, array<(.*?)> given#'
328+
329+
- identifier: symplify.noConstructorOverride
330+
path: src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector\Fixture;
4+
5+
final class WithParentheses
6+
{
7+
public static function isLeapyear(int $year): bool
8+
{
9+
if (($year % 400) == 0 || (($year & 4) == 0 && ($year % 100) != 0)) {
10+
return true;
11+
}
12+
return false;
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector\Fixture;
21+
22+
final class WithParentheses
23+
{
24+
public static function isLeapyear(int $year): bool
25+
{
26+
return ($year % 400) == 0 || (($year & 4) == 0 && ($year % 100) != 0);
27+
}
28+
}
29+
30+
?>

rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Rector\BetterPhpDocParser\Comment\CommentsMerger;
1818
use Rector\CodeQuality\NodeManipulator\ExprBoolCaster;
1919
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
20-
use Rector\NodeTypeResolver\Node\AttributeKey;
2120
use Rector\PhpParser\Node\Value\ValueResolver;
2221
use Rector\PhpParser\Printer\BetterStandardPrinter;
2322
use Rector\Rector\AbstractRector;
@@ -106,7 +105,6 @@ public function refactor(Node $node): ?Node
106105
continue;
107106
}
108107

109-
$if->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null);
110108
$this->commentsMerger->keepComments($newReturn, [$if, $return, $ifInnerNode]);
111109

112110
// remove previous IF

0 commit comments

Comments
 (0)