OrderItemModelNormalizer::normalize()   F
last analyzed

Complexity

Conditions 11
Paths 1024

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 11
eloc 22
c 1
b 0
f 1
nc 1024
nop 3
dl 0
loc 34
rs 3.15

How to fix   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 OrderItemModelNormalizer 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\\OrderItemModel';
20
    }
21
    public function supportsNormalization($data, $format = null)
22
    {
23
        return get_class($data) === 'Starweb\\Api\\Generated\\Model\\OrderItemModel';
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\OrderItemModel();
31
        if (property_exists($data, 'itemId')) {
32
            $object->setItemId($data->{'itemId'});
33
        }
34
        if (property_exists($data, 'sku')) {
35
            $object->setSku($data->{'sku'});
36
        }
37
        if (property_exists($data, 'description')) {
38
            $object->setDescription($data->{'description'});
39
        }
40
        if (property_exists($data, 'quantity')) {
41
            $object->setQuantity($data->{'quantity'});
42
        }
43
        if (property_exists($data, 'unitSymbol')) {
44
            $object->setUnitSymbol($data->{'unitSymbol'});
45
        }
46
        if (property_exists($data, 'unitPrice')) {
47
            $object->setUnitPrice($data->{'unitPrice'});
48
        }
49
        if (property_exists($data, 'vatRate')) {
50
            $object->setVatRate($data->{'vatRate'});
51
        }
52
        if (property_exists($data, 'discount')) {
53
            $object->setDiscount($data->{'discount'});
54
        }
55
        if (property_exists($data, 'discountType')) {
56
            $object->setDiscountType($data->{'discountType'});
57
        }
58
        if (property_exists($data, 'sortIndex')) {
59
            $object->setSortIndex($data->{'sortIndex'});
60
        }
61
        return $object;
62
    }
63
    public function normalize($object, $format = null, array $context = array())
64
    {
65
        $data = new \stdClass();
66
        if (null !== $object->getItemId()) {
67
            $data->{'itemId'} = $object->getItemId();
68
        }
69
        if (null !== $object->getSku()) {
70
            $data->{'sku'} = $object->getSku();
71
        }
72
        if (null !== $object->getDescription()) {
73
            $data->{'description'} = $object->getDescription();
74
        }
75
        if (null !== $object->getQuantity()) {
76
            $data->{'quantity'} = $object->getQuantity();
77
        }
78
        if (null !== $object->getUnitSymbol()) {
79
            $data->{'unitSymbol'} = $object->getUnitSymbol();
80
        }
81
        if (null !== $object->getUnitPrice()) {
82
            $data->{'unitPrice'} = $object->getUnitPrice();
83
        }
84
        if (null !== $object->getVatRate()) {
85
            $data->{'vatRate'} = $object->getVatRate();
86
        }
87
        if (null !== $object->getDiscount()) {
88
            $data->{'discount'} = $object->getDiscount();
89
        }
90
        if (null !== $object->getDiscountType()) {
91
            $data->{'discountType'} = $object->getDiscountType();
92
        }
93
        if (null !== $object->getSortIndex()) {
94
            $data->{'sortIndex'} = $object->getSortIndex();
95
        }
96
        return $data;
97
    }
98
}