Skip to content

Commit 3b43170

Browse files
committed
narrow only lists
1 parent ac4de81 commit 3b43170

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/PHPStan/Analyser/nsrt/list-count.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ protected function testOptionalKeysInUnion($row): void
282282
/**
283283
* @param array{string}|array{0: int, 1?: string|null} $row
284284
*/
285-
protected function testOptionalKeysInTaggedUnion($row): void
285+
protected function testOptionalKeysInListsOfTaggedUnion($row): void
286286
{
287287
if (count($row) === 0) {
288288
assertType('*NEVER*', $row);
@@ -309,4 +309,34 @@ protected function testOptionalKeysInTaggedUnion($row): void
309309
}
310310
}
311311

312+
/**
313+
* @param array{string}|array{0: int, 3?: string|null} $row
314+
*/
315+
protected function testOptionalKeysInUnionArray($row): void
316+
{
317+
if (count($row) === 0) {
318+
assertType('*NEVER*', $row);
319+
} else {
320+
assertType('array{0: int, 3?: string|null}|array{string}', $row);
321+
}
322+
323+
if (count($row) === 1) {
324+
assertType('array{0: int, 3?: string|null}|array{string}', $row);
325+
} else {
326+
assertType('array{0: int, 3?: string|null}', $row);
327+
}
328+
329+
if (count($row) === 2) {
330+
assertType('array{0: int, 3?: string|null}', $row);
331+
} else {
332+
assertType('array{0: int, 3?: string|null}|array{string}', $row);
333+
}
334+
335+
if (count($row) === 3) {
336+
assertType('*NEVER*', $row);
337+
} else {
338+
assertType('array{0: int, 3?: string|null}|array{string}', $row);
339+
}
340+
}
341+
312342
}

0 commit comments

Comments
 (0)