PaymentMethodModelNormalizer::denormalize()   F
last analyzed

Complexity

Conditions 17
Paths 16385

Size

Total Lines 53
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 17
eloc 35
c 1
b 0
f 1
nc 16385
nop 4
dl 0
loc 53
rs 1.0499

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Starweb\Api\Generated\Normalizer;
4
5
use Jane\JsonSchemaRuntime\Reference;
6
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
7
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
8
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
9
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
10
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
11
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
12
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
13
class PaymentMethodModelNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
14
{
15
    use DenormalizerAwareTrait;
16
    use NormalizerAwareTrait;
17
    public function supportsDenormalization($data, $type, $format = null)
18
    {
19
        return $type === 'Starweb\\Api\\Generated\\Model\\PaymentMethodModel';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\PaymentMethodModel';
24
    }
25
    public function denormalize($data, $class, $format = null, array $context = array())
26
    {
27
        if (!is_object($data)) {
28
            throw new InvalidArgumentException();
29
        }
30
        $object = new \Starweb\Api\Generated\Model\PaymentMethodModel();
31
        if (property_exists($data, 'paymentMethodId')) {
32
            $object->setPaymentMethodId($data->{'paymentMethodId'});
33
        }
34
        if (property_exists($data, 'idCode')) {
35
            $object->setIdCode($data->{'idCode'});
36
        }
37
        if (property_exists($data, 'active')) {
38
            $object->setActive($data->{'active'});
39
        }
40
        if (property_exists($data, 'fee')) {
41
            $object->setFee($data->{'fee'});
42
        }
43
        if (property_exists($data, 'validForCountries')) {
44
            $object->setValidForCountries($data->{'validForCountries'});
45
        }
46
        if (property_exists($data, 'validCountriesSelected')) {
47
            $values = array();
48
            foreach ($data->{'validCountriesSelected'} as $value) {
49
                $values[] = $value;
50
            }
51
            $object->setValidCountriesSelected($values);
52
        }
53
        if (property_exists($data, 'validForMinItemsSubtotal')) {
54
            $object->setValidForMinItemsSubtotal($data->{'validForMinItemsSubtotal'});
55
        }
56
        if (property_exists($data, 'validForMaxItemsSubtotal')) {
57
            $object->setValidForMaxItemsSubtotal($data->{'validForMaxItemsSubtotal'});
58
        }
59
        if (property_exists($data, 'validForMinWeight')) {
60
            $object->setValidForMinWeight($data->{'validForMinWeight'});
61
        }
62
        if (property_exists($data, 'validForMaxWeight')) {
63
            $object->setValidForMaxWeight($data->{'validForMaxWeight'});
64
        }
65
        if (property_exists($data, 'validForShippingMethods')) {
66
            $object->setValidForShippingMethods($data->{'validForShippingMethods'});
67
        }
68
        if (property_exists($data, 'validForCustomerType')) {
69
            $object->setValidForCustomerType($data->{'validForCustomerType'});
70
        }
71
        if (property_exists($data, 'isClickAndCollect')) {
72
            $object->setIsClickAndCollect($data->{'isClickAndCollect'});
73
        }
74
        if (property_exists($data, 'languages')) {
75
            $object->setLanguages($this->denormalizer->denormalize($data->{'languages'}, 'Starweb\\Api\\Generated\\Model\\PaymentMethodLanguageModelCollection', 'json', $context));
0 ignored issues
show
Bug introduced by
It seems like $this->denormalizer->den...ion', 'json', $context) can also be of type array; however, parameter $languages of Starweb\Api\Generated\Mo...odModel::setLanguages() does only seem to accept Starweb\Api\Generated\Mo...LanguageModelCollection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
            $object->setLanguages(/** @scrutinizer ignore-type */ $this->denormalizer->denormalize($data->{'languages'}, 'Starweb\\Api\\Generated\\Model\\PaymentMethodLanguageModelCollection', 'json', $context));
Loading history...
76
        }
77
        return $object;
78
    }
79
    public function normalize($object, $format = null, array $context = array())
80
    {
81
        $data = new \stdClass();
82
        if (null !== $object->getPaymentMethodId()) {
83
            $data->{'paymentMethodId'} = $object->getPaymentMethodId();
84
        }
85
        if (null !== $object->getIdCode()) {
86
            $data->{'idCode'} = $object->getIdCode();
87
        }
88
        if (null !== $object->getActive()) {
89
            $data->{'active'} = $object->getActive();
90
        }
91
        if (null !== $object->getFee()) {
92
            $data->{'fee'} = $object->getFee();
93
        }
94
        if (null !== $object->getValidForCountries()) {
95
            $data->{'validForCountries'} = $object->getValidForCountries();
96
        }
97
        if (null !== $object->getValidCountriesSelected()) {
98
            $values = array();
99
            foreach ($object->getValidCountriesSelected() as $value) {
100
                $values[] = $value;
101
            }
102
            $data->{'validCountriesSelected'} = $values;
103
        }
104
        $data->{'validForMinItemsSubtotal'} = $object->getValidForMinItemsSubtotal();
105
        $data->{'validForMaxItemsSubtotal'} = $object->getValidForMaxItemsSubtotal();
106
        $data->{'validForMinWeight'} = $object->getValidForMinWeight();
107
        $data->{'validForMaxWeight'} = $object->getValidForMaxWeight();
108
        if (null !== $object->getValidForShippingMethods()) {
109
            $data->{'validForShippingMethods'} = $object->getValidForShippingMethods();
110
        }
111
        $data->{'validForCustomerType'} = $object->getValidForCustomerType();
112
        if (null !== $object->getIsClickAndCollect()) {
113
            $data->{'isClickAndCollect'} = $object->getIsClickAndCollect();
114
        }
115
        if (null !== $object->getLanguages()) {
116
            $data->{'languages'} = $this->normalizer->normalize($object->getLanguages(), 'json', $context);
117
        }
118
        return $data;
119
    }
120
}