type; $value = $shell->value(); assert($type instanceof ListType || $type instanceof NonEmptyListType); if ($shell->allowUndefinedValues && $value === null) { $value = []; } if (! is_iterable($value)) { return $shell->error(new SourceMustBeIterable($value)); } if ($value === [] && $type instanceof NonEmptyListType) { return $shell->error(new SourceIsEmptyList()); } $subType = $type->subType(); $expected = 0; $children = []; $errors = []; foreach ($value as $key => $val) { if (! is_string($key) && ! is_int($key)) { throw new InvalidIterableKeyType($key, $shell->path); } if ($shell->allowNonSequentialList || $key === $expected) { $child = $shell->child((string)$expected, $subType); $childNode = $children[$expected] = $child->withValue($val)->build(); } else { $child = $shell->child((string)$key, $subType); $childNode = $children[$key] = $child->error(new InvalidListKey($key, $expected)); } if (! $childNode->isValid()) { $errors[] = $childNode; } $expected++; } if ($errors !== []) { return $shell->errors($errors); } return $shell->node( array_map( static fn (Node $child) => $child->value(), $children, ), ); } }