mirror of
https://github.com/danog/Valinor.git
synced 2024-11-26 20:24:40 +01:00
misc: transform missing source value to null
in flexible mode
This commit is contained in:
parent
034f1c51e1
commit
92a41a1564
@ -28,7 +28,7 @@ final class ArrayNodeBuilder implements NodeBuilder
|
||||
public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
|
||||
{
|
||||
$type = $shell->type();
|
||||
$value = $shell->hasValue() ? $shell->value() : null;
|
||||
$value = $shell->value();
|
||||
|
||||
assert($type instanceof ArrayType || $type instanceof NonEmptyArrayType || $type instanceof IterableType);
|
||||
|
||||
|
@ -22,12 +22,10 @@ final class IterableNodeBuilder implements NodeBuilder
|
||||
|
||||
public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
|
||||
{
|
||||
if ($shell->hasValue()) {
|
||||
$value = $shell->value();
|
||||
$value = $shell->value();
|
||||
|
||||
if (is_iterable($value) && ! is_array($value)) {
|
||||
$shell = $shell->withValue(iterator_to_array($value));
|
||||
}
|
||||
if (is_iterable($value) && ! is_array($value)) {
|
||||
$shell = $shell->withValue(iterator_to_array($value));
|
||||
}
|
||||
|
||||
return $this->delegate->build($shell, $rootBuilder);
|
||||
|
@ -27,7 +27,7 @@ final class ListNodeBuilder implements NodeBuilder
|
||||
public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
|
||||
{
|
||||
$type = $shell->type();
|
||||
$value = $shell->hasValue() ? $shell->value() : null;
|
||||
$value = $shell->value();
|
||||
|
||||
assert($type instanceof ListType || $type instanceof NonEmptyListType);
|
||||
|
||||
|
@ -23,7 +23,7 @@ final class ScalarNodeBuilder implements NodeBuilder
|
||||
public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
|
||||
{
|
||||
$type = $shell->type();
|
||||
$value = $shell->hasValue() ? $shell->value() : null;
|
||||
$value = $shell->value();
|
||||
|
||||
assert($type instanceof ScalarType);
|
||||
|
||||
|
@ -28,7 +28,7 @@ final class ShapedArrayNodeBuilder implements NodeBuilder
|
||||
public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
|
||||
{
|
||||
$type = $shell->type();
|
||||
$value = $shell->hasValue() ? $shell->value() : null;
|
||||
$value = $shell->value();
|
||||
|
||||
assert($type instanceof ShapedArrayType);
|
||||
|
||||
|
@ -31,13 +31,7 @@ final class StrictNodeBuilder implements NodeBuilder
|
||||
|
||||
if (! $shell->hasValue()) {
|
||||
if ($this->flexible) {
|
||||
if ($type->accepts(null)) {
|
||||
return TreeNode::leaf($shell, null);
|
||||
}
|
||||
|
||||
if ($type->accepts([])) {
|
||||
return TreeNode::leaf($shell, []);
|
||||
}
|
||||
return $this->delegate->build($shell->withValue(null), $rootBuilder);
|
||||
}
|
||||
|
||||
throw new MissingNodeValue($type);
|
||||
|
@ -25,7 +25,7 @@ final class UnionNodeBuilder implements NodeBuilder
|
||||
{
|
||||
$type = $shell->type();
|
||||
|
||||
if (! $type instanceof UnionType || ! $shell->hasValue()) {
|
||||
if (! $type instanceof UnionType) {
|
||||
return $this->delegate->build($shell, $rootBuilder);
|
||||
}
|
||||
|
||||
|
@ -436,8 +436,7 @@ final class FlexibleMappingTest extends IntegrationTest
|
||||
} catch (MappingError $exception) {
|
||||
$error = $exception->node()->children()['bar']->messages()[0];
|
||||
|
||||
self::assertSame('1655449641', $error->code());
|
||||
self::assertSame('Cannot be empty and must be filled with a value matching type `string`.', (string)$error);
|
||||
self::assertSame('Value *missing* is not a valid string.', (string)$error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user