mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-20 06:38:46 +01:00
[Type Declaration] The smallest possible fixture fixed ReturnUuid (#4044)
* the smallest possible fixture fixed * fix default key integer Co-authored-by: TomasVotruba <tomas.vot@gmail.com>
This commit is contained in:
parent
5b4797af85
commit
f6fba29169
@ -354,7 +354,6 @@ final class NodeTypeResolver
|
||||
|
||||
if ($scope instanceof Scope) {
|
||||
$arrayType = $scope->getType($expr);
|
||||
|
||||
if ($arrayType !== null) {
|
||||
return $arrayType;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\Constant\ConstantIntegerType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\NeverType;
|
||||
use PHPStan\Type\Type;
|
||||
@ -119,6 +120,11 @@ final class ArrayTypeMapper implements TypeMapperInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
// skip simple arrays, like "string[]", from converting to obvious "array<int, string>"
|
||||
if ($this->isIntegerKeyAndNonNestedArray($arrayType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($arrayType->getKeyType() instanceof NeverType) {
|
||||
return false;
|
||||
}
|
||||
@ -170,4 +176,13 @@ final class ArrayTypeMapper implements TypeMapperInterface
|
||||
|
||||
return implode('|', $unionedTypesAsString);
|
||||
}
|
||||
|
||||
private function isIntegerKeyAndNonNestedArray(ArrayType $arrayType): bool
|
||||
{
|
||||
if (! $arrayType->getKeyType() instanceof IntegerType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $arrayType->getItemType() instanceof ArrayType;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace Rector\CodingStyle\Tests\Rector\ClassConst\VarConstantCommentRector\Fi
|
||||
final class ExplicitKeyArray
|
||||
{
|
||||
/**
|
||||
* @var array<int, string>
|
||||
* @var string[]
|
||||
*/
|
||||
const VALUES_WITH_KEYS = [
|
||||
100 => 'hi'
|
||||
|
@ -53,7 +53,6 @@ final class ReturnTypeInferer extends AbstractPriorityAwareTypeInferer
|
||||
}
|
||||
|
||||
$type = $this->typeNormalizer->normalizeArrayTypeAndArrayNever($originalType);
|
||||
|
||||
$type = $this->typeNormalizer->uniqueateConstantArrayType($type);
|
||||
$type = $this->typeNormalizer->normalizeArrayOfUnionToUnionArray($type);
|
||||
|
||||
|
@ -41,7 +41,7 @@ final class ReturnUuid
|
||||
private $amenityBuildings = [];
|
||||
|
||||
/**
|
||||
* @return array<int, \Ramsey\Uuid\UuidInterface>
|
||||
* @return \Ramsey\Uuid\UuidInterface[]
|
||||
*/
|
||||
public function getBuildingIds(): array
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user