Skip to content

Commit 3c2d00a

Browse files
authored
Merge pull request #1599 from simPod/list
Parse list into `list` type instead of `array`
2 parents 4dc94aa + 0c4d24e commit 3c2d00a

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Unreleased
44
- Use symfony/cache for FileSystem cache implementation instead of doctrine/cache
55
- Deprecated the `@ReadOnly` annotation due to `readonly` becoming a keyword in PHP 8.1, use the `@ReadOnlyProperty` annotation instead
66
- Doctrine type `decimal` is now correctly mapped to `string` instead of `float`
7+
- `@var/param list<T>` is now mapped to `list<T>` type instead of `array<int, T>`
78

89
From 3.x to 3.30.0
910
==================

src/Metadata/Driver/DocBlockDriver/DocBlockTypeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function getDocBlocTypeHint($reflector): ?string
140140
if ($this->isSimpleType($type->type, 'list')) {
141141
$resolvedTypes = array_map(fn (TypeNode $node) => $this->resolveTypeFromTypeNode($node, $reflector), $type->genericTypes);
142142

143-
return 'array<int, ' . implode(',', $resolvedTypes) . '>';
143+
return 'list<' . implode(',', $resolvedTypes) . '>';
144144
}
145145

146146
throw new \InvalidArgumentException(sprintf("Can't use non-array generic type %s for collection in %s:%s", (string) $type->type, $reflector->getDeclaringClass()->getName(), $reflector->getName()));

tests/Metadata/Driver/DocBlockDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testInferDocBlockCollectionAsList(): void
8888
$m = $this->resolve(CollectionAsList::class);
8989

9090
self::assertEquals(
91-
['name' => 'array', 'params' => [['name' => 'int', 'params' => []], ['name' => 'string', 'params' => []]]],
91+
['name' => 'list', 'params' => [['name' => 'string', 'params' => []]]],
9292
$m->propertyMetadata['productIds']->type,
9393
);
9494
}

0 commit comments

Comments
 (0)