Specify optional array keys in `ConfigReturnTypeExtension`
parent
509c0fffbe
commit
3b204cb6f2
|
@ -123,19 +123,23 @@ final class ConfigReturnTypeExtension implements DynamicMethodReturnTypeExtensio
|
||||||
if (isset($def['properties'])) {
|
if (isset($def['properties'])) {
|
||||||
$keyNames = [];
|
$keyNames = [];
|
||||||
$valTypes = [];
|
$valTypes = [];
|
||||||
|
$optionalKeys = [];
|
||||||
|
$propIndex = 0;
|
||||||
foreach ($def['properties'] as $propName => $propdef) {
|
foreach ($def['properties'] as $propName => $propdef) {
|
||||||
$keyNames[] = new ConstantStringType($propName);
|
$keyNames[] = new ConstantStringType($propName);
|
||||||
$valType = $this->parseType($propdef, $path.'.'.$propName);
|
$valType = $this->parseType($propdef, $path.'.'.$propName);
|
||||||
if (!isset($def['required']) || !in_array($propName, $def['required'], true)) {
|
if (!isset($def['required']) || !in_array($propName, $def['required'], true)) {
|
||||||
$valType = TypeCombinator::addNull($valType);
|
$valType = TypeCombinator::addNull($valType);
|
||||||
|
$optionalKeys[] = $propIndex;
|
||||||
}
|
}
|
||||||
$valTypes[] = $valType;
|
$valTypes[] = $valType;
|
||||||
|
$propIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addlPropType !== null) {
|
if ($addlPropType !== null) {
|
||||||
$types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes));
|
$types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes));
|
||||||
} else {
|
} else {
|
||||||
$types[] = new ConstantArrayType($keyNames, $valTypes);
|
$types[] = new ConstantArrayType($keyNames, $valTypes, [0], $optionalKeys);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$types[] = new ArrayType(new StringType(), $addlPropType ?? new MixedType());
|
$types[] = new ArrayType(new StringType(), $addlPropType ?? new MixedType());
|
||||||
|
|
Loading…
Reference in New Issue