diff --git a/src/Mapper/Tree/Builder/ArrayNodeBuilder.php b/src/Mapper/Tree/Builder/ArrayNodeBuilder.php index 2e3de61..87a32da 100644 --- a/src/Mapper/Tree/Builder/ArrayNodeBuilder.php +++ b/src/Mapper/Tree/Builder/ArrayNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/IterableNodeBuilder.php b/src/Mapper/Tree/Builder/IterableNodeBuilder.php index 08397d8..2b5fb0b 100644 --- a/src/Mapper/Tree/Builder/IterableNodeBuilder.php +++ b/src/Mapper/Tree/Builder/IterableNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/ListNodeBuilder.php b/src/Mapper/Tree/Builder/ListNodeBuilder.php index 97631b6..d37a4bc 100644 --- a/src/Mapper/Tree/Builder/ListNodeBuilder.php +++ b/src/Mapper/Tree/Builder/ListNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/ScalarNodeBuilder.php b/src/Mapper/Tree/Builder/ScalarNodeBuilder.php index a976b8f..6ccb2db 100644 --- a/src/Mapper/Tree/Builder/ScalarNodeBuilder.php +++ b/src/Mapper/Tree/Builder/ScalarNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/ShapedArrayNodeBuilder.php b/src/Mapper/Tree/Builder/ShapedArrayNodeBuilder.php index 989f303..a64134a 100644 --- a/src/Mapper/Tree/Builder/ShapedArrayNodeBuilder.php +++ b/src/Mapper/Tree/Builder/ShapedArrayNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/StrictNodeBuilder.php b/src/Mapper/Tree/Builder/StrictNodeBuilder.php index f603804..52a5594 100644 --- a/src/Mapper/Tree/Builder/StrictNodeBuilder.php +++ b/src/Mapper/Tree/Builder/StrictNodeBuilder.php @@ -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); diff --git a/src/Mapper/Tree/Builder/UnionNodeBuilder.php b/src/Mapper/Tree/Builder/UnionNodeBuilder.php index 702af7f..12e723a 100644 --- a/src/Mapper/Tree/Builder/UnionNodeBuilder.php +++ b/src/Mapper/Tree/Builder/UnionNodeBuilder.php @@ -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); } diff --git a/tests/Integration/Mapping/Other/FlexibleMappingTest.php b/tests/Integration/Mapping/Other/FlexibleMappingTest.php index 4ec777c..a7f3df5 100644 --- a/tests/Integration/Mapping/Other/FlexibleMappingTest.php +++ b/tests/Integration/Mapping/Other/FlexibleMappingTest.php @@ -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); } } }