[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:
dobryy 2020-08-28 07:00:03 +02:00 committed by GitHub
parent 5b4797af85
commit f6fba29169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 4 deletions

View File

@ -354,7 +354,6 @@ final class NodeTypeResolver
if ($scope instanceof Scope) {
$arrayType = $scope->getType($expr);
if ($arrayType !== null) {
return $arrayType;
}

View File

@ -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;
}
}

View File

@ -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'

View File

@ -53,7 +53,6 @@ final class ReturnTypeInferer extends AbstractPriorityAwareTypeInferer
}
$type = $this->typeNormalizer->normalizeArrayTypeAndArrayNever($originalType);
$type = $this->typeNormalizer->uniqueateConstantArrayType($type);
$type = $this->typeNormalizer->normalizeArrayOfUnionToUnionArray($type);

View File

@ -41,7 +41,7 @@ final class ReturnUuid
private $amenityBuildings = [];
/**
* @return array<int, \Ramsey\Uuid\UuidInterface>
* @return \Ramsey\Uuid\UuidInterface[]
*/
public function getBuildingIds(): array
{