Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Skip possible returns false on ReturnTypeFromStrict…
…NewArrayRector (#5654) * [TypeDeclaration] Skip possible returns false on ReturnTypeFromStrictNewArrayRector * fix phstan
- Loading branch information
1 parent
6095e32
commit 8038ee1
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...lassMethod/ReturnTypeFromStrictNewArrayRector/Fixture/skip_possible_returns_false.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector\Fixture; | ||
|
||
final class SkipPossibleReturnFalse | ||
{ | ||
public function couldUpdate(\stdClass $pricesItem, AbstractDocument $document) | ||
{ | ||
$return = []; | ||
$couldUpdate = false; | ||
|
||
foreach ($document as $compareKey => $compareValue) { | ||
|
||
$return[$compareKey] = [ | ||
$compareValue, | ||
$pricesItem->$compareKey === null | ||
? 'NULL' | ||
: (float) $pricesItem->$compareKey, | ||
]; | ||
|
||
$isSame = bccomp( | ||
(string) ($pricesItem->$compareKey), | ||
(string) ($compareValue), | ||
2 | ||
); | ||
|
||
if (!empty($isSame) && !$couldUpdate) { | ||
$couldUpdate = true; | ||
} | ||
} | ||
|
||
if ($couldUpdate) { | ||
return $return; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters