Skip to content

Commit

Permalink
[TypeDeclaration] Skip possible returns false on ReturnTypeFromStrict…
Browse files Browse the repository at this point in the history
…NewArrayRector (#5654)

* [TypeDeclaration] Skip possible returns false on ReturnTypeFromStrictNewArrayRector

* fix phstan
  • Loading branch information
samsonasik committed Feb 21, 2024
1 parent 6095e32 commit 8038ee1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
@@ -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;
}

}
Expand Up @@ -105,15 +105,15 @@ private function resolveClassStringInUnionType(UnionType $type): UnionType | Arr
$keyType = $unionType->getKeyType();
$itemType = $unionType->getItemType();

if (! $keyType instanceof MixedType && ! $keyType instanceof ConstantIntegerType) {
return $type;
}

if ($itemType instanceof ArrayType) {
$arrayType = new ArrayType(new MixedType(), new MixedType());
return new ArrayType($keyType, $arrayType);
}

if (! $keyType instanceof MixedType && ! $keyType instanceof ConstantIntegerType) {
return $type;
}

if (! $itemType instanceof ClassStringType) {
return $type;
}
Expand Down

0 comments on commit 8038ee1

Please sign in to comment.