1: <?php
2:
3: declare(strict_types=1);
4:
5: /*
6: * This file has been auto generated by Jane,
7: *
8: * Do no edit it directly.
9: */
10:
11: namespace NxSys\Library\Clients\Brex\API\Team\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Team\Runtime\Normalizer\ValidatorTrait;
16: use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
17: use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
18: use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19: use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
20: use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
21: use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22:
23: class CardMailingAddressNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
24: {
25: use DenormalizerAwareTrait;
26: use NormalizerAwareTrait;
27: use CheckArray;
28: use ValidatorTrait;
29:
30: public function supportsDenormalization($data, $type, $format = null): bool
31: {
32: return $type === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CardMailingAddress';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Team\\Model\\CardMailingAddress';
38: }
39:
40: /**
41: * @return mixed
42: */
43: public function denormalize($data, $class, $format = null, array $context = [])
44: {
45: if (isset($data['$ref'])) {
46: return new Reference($data['$ref'], $context['document-origin']);
47: }
48: if (isset($data['$recursiveRef'])) {
49: return new Reference($data['$recursiveRef'], $context['document-origin']);
50: }
51: $object = new \NxSys\Library\Clients\Brex\API\Team\Model\CardMailingAddress();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('line1', $data) && $data['line1'] !== null) {
56: $object->setLine1($data['line1']);
57: unset($data['line1']);
58: } elseif (\array_key_exists('line1', $data) && $data['line1'] === null) {
59: $object->setLine1(null);
60: }
61: if (\array_key_exists('line2', $data) && $data['line2'] !== null) {
62: $object->setLine2($data['line2']);
63: unset($data['line2']);
64: } elseif (\array_key_exists('line2', $data) && $data['line2'] === null) {
65: $object->setLine2(null);
66: }
67: if (\array_key_exists('city', $data) && $data['city'] !== null) {
68: $object->setCity($data['city']);
69: unset($data['city']);
70: } elseif (\array_key_exists('city', $data) && $data['city'] === null) {
71: $object->setCity(null);
72: }
73: if (\array_key_exists('state', $data) && $data['state'] !== null) {
74: $object->setState($data['state']);
75: unset($data['state']);
76: } elseif (\array_key_exists('state', $data) && $data['state'] === null) {
77: $object->setState(null);
78: }
79: if (\array_key_exists('country', $data) && $data['country'] !== null) {
80: $object->setCountry($data['country']);
81: unset($data['country']);
82: } elseif (\array_key_exists('country', $data) && $data['country'] === null) {
83: $object->setCountry(null);
84: }
85: if (\array_key_exists('postal_code', $data) && $data['postal_code'] !== null) {
86: $object->setPostalCode($data['postal_code']);
87: unset($data['postal_code']);
88: } elseif (\array_key_exists('postal_code', $data) && $data['postal_code'] === null) {
89: $object->setPostalCode(null);
90: }
91: if (\array_key_exists('phone_number', $data) && $data['phone_number'] !== null) {
92: $object->setPhoneNumber($data['phone_number']);
93: unset($data['phone_number']);
94: } elseif (\array_key_exists('phone_number', $data) && $data['phone_number'] === null) {
95: $object->setPhoneNumber(null);
96: }
97: foreach ($data as $key => $value) {
98: if (preg_match('/.*/', (string) $key)) {
99: $object[$key] = $value;
100: }
101: }
102:
103: return $object;
104: }
105:
106: /**
107: * @return array|string|int|float|bool|\ArrayObject|null
108: */
109: public function normalize($object, $format = null, array $context = [])
110: {
111: $data = [];
112: if ($object->isInitialized('line1') && null !== $object->getLine1()) {
113: $data['line1'] = $object->getLine1();
114: }
115: if ($object->isInitialized('line2') && null !== $object->getLine2()) {
116: $data['line2'] = $object->getLine2();
117: }
118: if ($object->isInitialized('city') && null !== $object->getCity()) {
119: $data['city'] = $object->getCity();
120: }
121: if ($object->isInitialized('state') && null !== $object->getState()) {
122: $data['state'] = $object->getState();
123: }
124: if ($object->isInitialized('country') && null !== $object->getCountry()) {
125: $data['country'] = $object->getCountry();
126: }
127: if ($object->isInitialized('postalCode') && null !== $object->getPostalCode()) {
128: $data['postal_code'] = $object->getPostalCode();
129: }
130: if ($object->isInitialized('phoneNumber') && null !== $object->getPhoneNumber()) {
131: $data['phone_number'] = $object->getPhoneNumber();
132: }
133: foreach ($object as $key => $value) {
134: if (preg_match('/.*/', (string) $key)) {
135: $data[$key] = $value;
136: }
137: }
138:
139: return $data;
140: }
141: }
142: