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\Transactions\Normalizer;
12:
13: use Jane\Component\JsonSchemaRuntime\Reference;
14: use NxSys\Library\Clients\Brex\API\Transactions\Runtime\Normalizer\CheckArray;
15: use NxSys\Library\Clients\Brex\API\Transactions\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 CashAccountNormalizer 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\\Transactions\\Model\\CashAccount';
33: }
34:
35: public function supportsNormalization($data, $format = null): bool
36: {
37: return is_object($data) && get_class($data) === 'NxSys\\Library\\Clients\\Brex\\API\\Transactions\\Model\\CashAccount';
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\Transactions\Model\CashAccount();
52: if (null === $data || false === \is_array($data)) {
53: return $object;
54: }
55: if (\array_key_exists('id', $data)) {
56: $object->setId($data['id']);
57: unset($data['id']);
58: }
59: if (\array_key_exists('name', $data)) {
60: $object->setName($data['name']);
61: unset($data['name']);
62: }
63: if (\array_key_exists('status', $data)) {
64: $object->setStatus($data['status']);
65: unset($data['status']);
66: }
67: if (\array_key_exists('current_balance', $data)) {
68: $object->setCurrentBalance($this->denormalizer->denormalize($data['current_balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Transactions\\Model\\Money', 'json', $context));
69: unset($data['current_balance']);
70: }
71: if (\array_key_exists('available_balance', $data)) {
72: $object->setAvailableBalance($this->denormalizer->denormalize($data['available_balance'], 'NxSys\\Library\\Clients\\Brex\\API\\Transactions\\Model\\Money', 'json', $context));
73: unset($data['available_balance']);
74: }
75: if (\array_key_exists('account_number', $data)) {
76: $object->setAccountNumber($data['account_number']);
77: unset($data['account_number']);
78: }
79: if (\array_key_exists('routing_number', $data)) {
80: $object->setRoutingNumber($data['routing_number']);
81: unset($data['routing_number']);
82: }
83: if (\array_key_exists('primary', $data)) {
84: $object->setPrimary($data['primary']);
85: unset($data['primary']);
86: }
87: foreach ($data as $key => $value) {
88: if (preg_match('/.*/', (string) $key)) {
89: $object[$key] = $value;
90: }
91: }
92:
93: return $object;
94: }
95:
96: /**
97: * @return array|string|int|float|bool|\ArrayObject|null
98: */
99: public function normalize($object, $format = null, array $context = [])
100: {
101: $data = [];
102: $data['id'] = $object->getId();
103: $data['name'] = $object->getName();
104: if ($object->isInitialized('status') && null !== $object->getStatus()) {
105: $data['status'] = $object->getStatus();
106: }
107: $data['current_balance'] = $this->normalizer->normalize($object->getCurrentBalance(), 'json', $context);
108: $data['available_balance'] = $this->normalizer->normalize($object->getAvailableBalance(), 'json', $context);
109: $data['account_number'] = $object->getAccountNumber();
110: $data['routing_number'] = $object->getRoutingNumber();
111: $data['primary'] = $object->getPrimary();
112: foreach ($object as $key => $value) {
113: if (preg_match('/.*/', (string) $key)) {
114: $data[$key] = $value;
115: }
116: }
117:
118: return $data;
119: }
120: }
121: