Skip to content

Commit b833312

Browse files
committed
Add support for non-empty-array with generics
1 parent 8fb2f28 commit b833312

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/TypeResolver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ
392392
case 'array':
393393
return $this->createArray($type->genericTypes, $context);
394394

395+
case 'non-empty-array':
396+
return new NonEmptyArray(...array_reverse($this->createTypesByTypeNodes($type->genericTypes, $context)));
397+
395398
case 'class-string':
396399
$subType = $this->createType($type->genericTypes[0], $context);
397400
if (!$subType instanceof Object_ || $subType->getFqsen() === null) {

tests/unit/TypeResolverTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,29 @@ public function genericsProvider(): array
10811081
)
10821082
),
10831083
],
1084+
[
1085+
'non-empty-array<string|int>',
1086+
new NonEmptyArray(
1087+
new Compound(
1088+
[
1089+
new String_(),
1090+
new Integer(),
1091+
]
1092+
)
1093+
),
1094+
],
1095+
[
1096+
'non-empty-array<string|int, Foo\\Bar>',
1097+
new NonEmptyArray(
1098+
new Object_(new Fqsen('\\phpDocumentor\\Foo\\Bar')),
1099+
new Compound(
1100+
[
1101+
new String_(),
1102+
new Integer(),
1103+
]
1104+
)
1105+
),
1106+
],
10841107
[
10851108
'Collection<array-key, int>[]',
10861109
new Array_(
@@ -1107,6 +1130,10 @@ public function genericsProvider(): array
11071130
'List<Foo>',
11081131
new List_(new Object_(new Fqsen('\\phpDocumentor\\Foo'))),
11091132
],
1133+
[
1134+
'non-empty-list<Foo>',
1135+
new NonEmptyList(new Object_(new Fqsen('\\phpDocumentor\\Foo'))),
1136+
],
11101137
[
11111138
'int<1, 100>',
11121139
new IntegerRange('1', '100'),

0 commit comments

Comments
 (0)