Skip to content

Commit

Permalink
Add float mul integer type to NumericReturnTypeFromStrictScalarReturn…
Browse files Browse the repository at this point in the history
…sRector (#4376)
  • Loading branch information
TomasVotruba authored Jun 29, 2023
1 parent 9ff2388 commit 29dc584
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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 MulFloatInteger
{
public function resolve(int $first, float $second)
{
return $first * $second;
}
}

?>
-----
<?php

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

final class MulFloatInteger
{
public function resolve(int $first, float $second): float
{
return $first * $second;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ private function refactorBinaryOp(
return $functionLike;
}

if ($binaryOp instanceof Mul) {
if ($leftType instanceof FloatType && $rightType instanceof IntegerType) {
$functionLike->returnType = new Identifier('float');
return $functionLike;
}

if ($leftType instanceof IntegerType && $rightType instanceof FloatType) {
$functionLike->returnType = new Identifier('float');
return $functionLike;
}
}

return null;
}
}

0 comments on commit 29dc584

Please sign in to comment.