File tree Expand file tree Collapse file tree 6 files changed +39
-46
lines changed
commercetools-import-tests Expand file tree Collapse file tree 6 files changed +39
-46
lines changed Original file line number Diff line number Diff line change 1- hash =64beef3a8f3cb2824ae9a2dffbed72ce612fbe87
1+ hash =90d341d55aa4d2b4820623d19bb2a069ed8cae03
Original file line number Diff line number Diff line change 1- hash =469c219cf815f2368aa427a54d7677e00ce0c1d0
1+ hash =90d341d55aa4d2b4820623d19bb2a069ed8cae03
Original file line number Diff line number Diff line change 1- hash =469c219cf815f2368aa427a54d7677e00ce0c1d0
1+ hash =90d341d55aa4d2b4820623d19bb2a069ed8cae03
Original file line number Diff line number Diff line change 88
99namespace Commercetools \Import \Models \Customfields ;
1010
11- use Commercetools \Base \DateTimeImmutableCollection ;
12- use Commercetools \Base \JsonObject ;
11+ use Commercetools \Base \CMap ;
1312
14- interface FieldContainer extends JsonObject
13+ interface FieldContainer extends CMap
1514{
16- public const FIELD_PATTERN0 = '// ' ;
1715}
Original file line number Diff line number Diff line change 99namespace Commercetools \Import \Models \Customfields ;
1010
1111use Commercetools \Base \Builder ;
12- use Commercetools \Base \DateTimeImmutableCollection ;
13- use Commercetools \Base \JsonObject ;
14- use Commercetools \Base \JsonObjectModel ;
15- use Commercetools \Base \MapperFactory ;
12+ use Commercetools \Base \MapperMap ;
1613use stdClass ;
1714
1815/**
1916 * @implements Builder<FieldContainer>
17+ * @extends MapperMap<FieldContainer>
2018 */
21- final class FieldContainerBuilder implements Builder
19+ final class FieldContainerBuilder extends MapperMap implements Builder
2220{
23- public function build (): FieldContainer
21+ /**
22+ * @psalm-return callable(string):?FieldContainer
23+ */
24+ protected function mapper ()
2425 {
25- return new FieldContainerModel (
26- );
26+ return
27+ /**
28+ * @psalm-return ?FieldContainer
29+ */
30+ function (string $ key ) {
31+ $ data = $ this ->get ($ key );
32+ if ($ data instanceof stdClass) {
33+ $ data = FieldContainerModel::of ($ data );
34+ }
35+ return $ data ;
36+ };
2737 }
2838
29- public static function of (): FieldContainerBuilder
39+ /**
40+ * @return FieldContainer
41+ */
42+ public function build ()
3043 {
31- return new self ( );
44+ return new FieldContainerModel ( $ this -> toArray () );
3245 }
3346}
Original file line number Diff line number Diff line change 88
99namespace Commercetools \Import \Models \Customfields ;
1010
11- use Commercetools \Base \DateTimeImmutableCollection ;
12- use Commercetools \Base \JsonObject ;
13- use Commercetools \Base \JsonObjectModel ;
14- use Commercetools \Base \MapperFactory ;
15- use stdClass ;
11+ use Commercetools \Base \MapperMap ;
1612
1713/**
1814 * @internal
1915 */
20- final class FieldContainerModel extends JsonObjectModel implements FieldContainer
16+ final class FieldContainerModel extends MapperMap implements FieldContainer
2117{
2218 /**
23- * @psalm-suppress MissingParamType
19+ * @psalm-return callable(string):?mixed
2420 */
25- public function __construct (
26- ) {
27- }
28-
29-
30-
31-
32- /**
33- * @return mixed
34- */
35- public function by (string $ key )
21+ protected function mapper ()
3622 {
37- $ data = $ this ->raw ($ key );
38- if (is_null ($ data )) {
39- return null ;
40- }
41- if (preg_match (FieldContainer::FIELD_PATTERN0 , $ key ) === 1 ) {
42- /** @psalm-var stdClass|array<string, mixed> $data */
43-
44- return CustomFieldModel::of ($ data );
45- }
46-
47- return $ data ;
23+ return
24+ /**
25+ * @psalm-return ?mixed
26+ */
27+ function (string $ key ) {
28+ return $ this ->get ($ key );
29+ };
4830 }
4931}
You can’t perform that action at this time.
0 commit comments