| Total Complexity | 41 |
| Total Lines | 108 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ProductVariantPutRequestModelNormalizer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProductVariantPutRequestModelNormalizer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class ProductVariantPutRequestModelNormalizer 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\\ProductVariantPutRequestModel'; |
||
| 20 | } |
||
| 21 | public function supportsNormalization($data, $format = null) |
||
| 24 | } |
||
| 25 | public function denormalize($data, $class, $format = null, array $context = array()) |
||
| 26 | { |
||
| 27 | if (!is_object($data)) { |
||
| 28 | return null; |
||
| 29 | } |
||
| 30 | $object = new \Starweb\Api\Generated\Model\ProductVariantPutRequestModel(); |
||
| 31 | if (property_exists($data, 'sku') && $data->{'sku'} !== null) { |
||
| 32 | $object->setSku($data->{'sku'}); |
||
| 33 | } |
||
| 34 | if (property_exists($data, 'externalId') && $data->{'externalId'} !== null) { |
||
| 35 | $object->setExternalId($data->{'externalId'}); |
||
| 36 | } |
||
| 37 | if (property_exists($data, 'externalIdType') && $data->{'externalIdType'} !== null) { |
||
| 38 | $object->setExternalIdType($data->{'externalIdType'}); |
||
| 39 | } |
||
| 40 | if (property_exists($data, 'isActive') && $data->{'isActive'} !== null) { |
||
| 41 | $object->setIsActive($data->{'isActive'}); |
||
| 42 | } |
||
| 43 | if (property_exists($data, 'sortIndex') && $data->{'sortIndex'} !== null) { |
||
| 44 | $object->setSortIndex($data->{'sortIndex'}); |
||
| 45 | } |
||
| 46 | if (property_exists($data, 'stockStatusId') && $data->{'stockStatusId'} !== null) { |
||
| 47 | $object->setStockStatusId($data->{'stockStatusId'}); |
||
| 48 | } |
||
| 49 | if (property_exists($data, 'stockQuantity') && $data->{'stockQuantity'} !== null) { |
||
| 50 | $object->setStockQuantity($data->{'stockQuantity'}); |
||
| 51 | } |
||
| 52 | if (property_exists($data, 'weightInKg') && $data->{'weightInKg'} !== null) { |
||
| 53 | $object->setWeightInKg($data->{'weightInKg'}); |
||
| 54 | } |
||
| 55 | if (property_exists($data, 'costPrice') && $data->{'costPrice'} !== null) { |
||
| 56 | $object->setCostPrice($data->{'costPrice'}); |
||
| 57 | } |
||
| 58 | if (property_exists($data, 'ean') && $data->{'ean'} !== null) { |
||
| 59 | $object->setEan($data->{'ean'}); |
||
| 60 | } |
||
| 61 | if (property_exists($data, 'mpn') && $data->{'mpn'} !== null) { |
||
| 62 | $object->setMpn($data->{'mpn'}); |
||
| 63 | } |
||
| 64 | if (property_exists($data, 'imageFileId') && $data->{'imageFileId'} !== null) { |
||
| 65 | $object->setImageFileId($data->{'imageFileId'}); |
||
| 66 | } |
||
| 67 | if (property_exists($data, 'attributeValueLinks') && $data->{'attributeValueLinks'} !== null) { |
||
| 68 | $values = array(); |
||
| 69 | foreach ($data->{'attributeValueLinks'} as $value) { |
||
| 70 | $values[] = $value; |
||
| 71 | } |
||
| 72 | $object->setAttributeValueLinks($values); |
||
| 73 | } |
||
| 74 | if (property_exists($data, 'volumePricingInheritancePricelistIds') && $data->{'volumePricingInheritancePricelistIds'} !== null) { |
||
| 75 | $values_1 = array(); |
||
| 76 | foreach ($data->{'volumePricingInheritancePricelistIds'} as $value_1) { |
||
| 77 | $values_1[] = $value_1; |
||
| 78 | } |
||
| 79 | $object->setVolumePricingInheritancePricelistIds($values_1); |
||
| 80 | } |
||
| 81 | return $object; |
||
| 82 | } |
||
| 83 | public function normalize($object, $format = null, array $context = array()) |
||
| 121 | } |
||
| 122 | } |