Skip to content

Commit

Permalink
Add bitwise or to NumericReturnTypeFromStrictScalarReturnsRector (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Jun 20, 2023
1 parent 41184e1 commit 9b9321c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector\Fixture;

final class BitwiseOr
{
public function resolve(int $first, int $second)
{
return $first | $second;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector\Fixture;

final class BitwiseOr
{
public function resolve(int $first, int $second): int
{
return $first | $second;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\BitwiseAnd;
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
use PhpParser\Node\Expr\BinaryOp\Minus;
use PhpParser\Node\Expr\BinaryOp\Mod;
use PhpParser\Node\Expr\BinaryOp\Mul;
Expand Down Expand Up @@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node
}

// @see https://chat.openai.com/share/a9e4fb74-5366-4c4c-9998-d6caeb8b5acc
if ($return->expr instanceof Minus || $return->expr instanceof Plus || $return->expr instanceof Mul || $return->expr instanceof Mod || $return->expr instanceof BitwiseAnd || $return->expr instanceof ShiftRight || $return->expr instanceof ShiftLeft) {
if ($return->expr instanceof Minus || $return->expr instanceof Plus || $return->expr instanceof Mul || $return->expr instanceof Mod || $return->expr instanceof BitwiseAnd || $return->expr instanceof ShiftRight || $return->expr instanceof ShiftLeft || $return->expr instanceof BitwiseOr) {
return $this->refactorBinaryOp($return->expr, $node);
}

Expand Down

0 comments on commit 9b9321c

Please sign in to comment.