@@ -16,21 +16,24 @@ class ItemMapper implements SchemaMapperInterface
16
16
{
17
17
private EmbeddedObjectMapper $ embeddedObjectMapper ;
18
18
19
- public function __construct (EmbeddedObjectMapper $ embeddedObjectMapper )
19
+ private EmbeddedNullableObjectMapper $ embeddedNullableObjectMapper ;
20
+
21
+ public function __construct (EmbeddedObjectMapper $ embeddedObjectMapper , EmbeddedNullableObjectMapper $ embeddedNullableObjectMapper )
20
22
{
21
- $ this ->embeddedObjectMapper = $ embeddedObjectMapper ;
23
+ $ this ->embeddedObjectMapper = $ embeddedObjectMapper ;
24
+ $ this ->embeddedNullableObjectMapper = $ embeddedNullableObjectMapper ;
22
25
}
23
26
24
27
/**
25
28
* @throws UnexpectedResponseBodyException
26
29
*/
27
30
public function toSchema (array $ payload ): Item
28
31
{
29
- $ missingFields = \implode (', ' , \array_diff (['mandatoryInteger ' , 'mandatoryString ' , 'mandatoryEnum ' , 'mandatoryDate ' , 'mandatoryNullableDate ' , 'mandatoryFloat ' , 'mandatoryBoolean ' , 'mandatoryArray ' , 'mandatoryObject ' ], \array_keys ($ payload )));
32
+ $ missingFields = \implode (', ' , \array_diff (['mandatoryInteger ' , 'mandatoryString ' , 'mandatoryEnum ' , 'mandatoryDate ' , 'mandatoryNullableDate ' , 'mandatoryFloat ' , 'mandatoryBoolean ' , 'mandatoryArray ' , 'mandatoryObject ' , ' mandatoryNullableObject ' ], \array_keys ($ payload )));
30
33
if (! empty ($ missingFields )) {
31
34
throw new UnexpectedResponseBodyException ('Required attributes for `Item` missing in the response body: ' . $ missingFields );
32
35
}
33
- $ schema = new Item ($ payload ['mandatoryInteger ' ], $ payload ['mandatoryString ' ], $ payload ['mandatoryEnum ' ], new DateTimeImmutable ($ payload ['mandatoryDate ' ]), $ payload ['mandatoryNullableDate ' ] !== null ? new DateTimeImmutable ($ payload ['mandatoryNullableDate ' ]) : null , $ payload ['mandatoryFloat ' ], $ payload ['mandatoryBoolean ' ], $ payload ['mandatoryArray ' ], $ this ->embeddedObjectMapper ->toSchema ($ payload ['mandatoryObject ' ]));
36
+ $ schema = new Item ($ payload ['mandatoryInteger ' ], $ payload ['mandatoryString ' ], $ payload ['mandatoryEnum ' ], new DateTimeImmutable ($ payload ['mandatoryDate ' ]), $ payload ['mandatoryNullableDate ' ] !== null ? new DateTimeImmutable ($ payload ['mandatoryNullableDate ' ]) : null , $ payload ['mandatoryFloat ' ], $ payload ['mandatoryBoolean ' ], $ payload ['mandatoryArray ' ], $ this ->embeddedObjectMapper ->toSchema ($ payload ['mandatoryObject ' ]), $ payload [ ' mandatoryNullableObject ' ] !== null ? $ this -> embeddedNullableObjectMapper -> toSchema ( $ payload [ ' mandatoryNullableObject ' ]) : null );
34
37
if (isset ($ payload ['optionalInteger ' ])) {
35
38
$ schema ->setOptionalInteger ($ payload ['optionalInteger ' ]);
36
39
}
0 commit comments