type; $value = $shell->value(); assert($type instanceof ArrayType || $type instanceof NonEmptyArrayType || $type instanceof IterableType); if ($shell->allowUndefinedValues && $value === null) { return $shell->node([]); } if (! is_iterable($value)) { return $shell->error(new SourceMustBeIterable($value)); } if ($value === [] && $type instanceof NonEmptyArrayType) { return $shell->error(new SourceIsEmptyArray()); } $keyType = $type->keyType(); $subType = $type->subType(); $children = []; $errors = []; foreach ($value as $key => $val) { if (! is_string($key) && ! is_int($key)) { throw new InvalidIterableKeyType($key, $shell->path); } $child = $shell->child((string)$key, $subType); if (! $keyType->accepts($key)) { $children[$key] = $child->error(new InvalidArrayKey($key, $keyType)); } else { $children[$key] = $child->withValue($val)->build(); } if (! $children[$key]->isValid()) { $errors[] = $children[$key]; } } if ($errors !== []) { return $shell->errors($errors); } return $shell->node( array_map( static fn (Node $child) => $child->value(), $children, ), ); } }