| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 105 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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\ProductModelUpdatable(); |
||
| 31 | if (property_exists($data, 'productId')) { |
||
| 32 | $object->setProductId($data->{'productId'}); |
||
| 33 | } |
||
| 34 | if (property_exists($data, 'createdAt')) { |
||
| 35 | $object->setCreatedAt($data->{'createdAt'}); |
||
| 36 | } |
||
| 37 | if (property_exists($data, 'defaultVatRate')) { |
||
| 38 | $object->setDefaultVatRate($data->{'defaultVatRate'}); |
||
| 39 | } |
||
| 40 | if (property_exists($data, 'visibility')) { |
||
| 41 | $object->setVisibility($data->{'visibility'}); |
||
| 42 | } |
||
| 43 | if (property_exists($data, 'visibilityPricelistIds')) { |
||
| 44 | $values = array(); |
||
| 45 | foreach ($data->{'visibilityPricelistIds'} as $value) { |
||
| 46 | $values[] = $value; |
||
| 47 | } |
||
| 48 | $object->setVisibilityPricelistIds($values); |
||
| 49 | } |
||
| 50 | if (property_exists($data, 'moreInfoUrl')) { |
||
| 51 | $object->setMoreInfoUrl($data->{'moreInfoUrl'}); |
||
| 52 | } |
||
| 53 | if (property_exists($data, 'manufacturerId')) { |
||
| 54 | $object->setManufacturerId($data->{'manufacturerId'}); |
||
| 55 | } |
||
| 56 | if (property_exists($data, 'unitId')) { |
||
| 57 | $object->setUnitId($data->{'unitId'}); |
||
| 58 | } |
||
| 59 | if (property_exists($data, 'sortIndex')) { |
||
| 60 | $object->setSortIndex($data->{'sortIndex'}); |
||
| 61 | } |
||
| 62 | if (property_exists($data, 'type')) { |
||
| 63 | $object->setType($data->{'type'}); |
||
| 64 | } |
||
| 65 | if (property_exists($data, 'isBackInStockWatchable')) { |
||
| 66 | $object->setIsBackInStockWatchable($data->{'isBackInStockWatchable'}); |
||
| 67 | } |
||
| 68 | if (property_exists($data, 'bundleUseManualPrice')) { |
||
| 69 | $object->setBundleUseManualPrice($data->{'bundleUseManualPrice'}); |
||
| 70 | } |
||
| 71 | if (property_exists($data, 'accounting')) { |
||
| 72 | $object->setAccounting($data->{'accounting'}); |
||
| 73 | } |
||
| 74 | if (property_exists($data, 'hasSeveralVariants')) { |
||
| 75 | $object->setHasSeveralVariants($data->{'hasSeveralVariants'}); |
||
| 76 | } |
||
| 77 | if (property_exists($data, 'modifiedAt')) { |
||
| 78 | $object->setModifiedAt($data->{'modifiedAt'}); |
||
| 79 | } |
||
| 80 | if (property_exists($data, 'variants')) { |
||
| 81 | $values_1 = array(); |
||
| 82 | foreach ($data->{'variants'} as $value_1) { |
||
| 83 | $values_1[] = $this->denormalizer->denormalize($value_1, 'Starweb\\Api\\Generated\\Model\\ProductVariantModel', 'json', $context); |
||
| 84 | } |
||
| 85 | $object->setVariants($values_1); |
||
| 86 | } |
||
| 87 | if (property_exists($data, 'bundledProducts')) { |
||
| 88 | $values_2 = array(); |
||
| 89 | foreach ($data->{'bundledProducts'} as $value_2) { |
||
| 90 | $values_2[] = $this->denormalizer->denormalize($value_2, 'Starweb\\Api\\Generated\\Model\\BundledProductsModel', 'json', $context); |
||
| 91 | } |
||
| 92 | $object->setBundledProducts($values_2); |
||
| 93 | } |
||
| 94 | if (property_exists($data, 'mediaFiles')) { |
||
| 95 | $values_3 = array(); |
||
| 96 | foreach ($data->{'mediaFiles'} as $value_3) { |
||
| 97 | $values_3[] = $this->denormalizer->denormalize($value_3, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModel', 'json', $context); |
||
| 98 | } |
||
| 99 | $object->setMediaFiles($values_3); |
||
| 100 | } |
||
| 101 | if (property_exists($data, 'languages')) { |
||
| 102 | $values_4 = array(); |
||
| 103 | foreach ($data->{'languages'} as $value_4) { |
||
| 104 | $values_4[] = $this->denormalizer->denormalize($value_4, 'Starweb\\Api\\Generated\\Model\\ProductLanguageModel', 'json', $context); |
||
| 105 | } |
||
| 106 | $object->setLanguages($values_4); |
||
| 107 | } |
||
| 108 | if (property_exists($data, 'vatRates')) { |
||
| 109 | $values_5 = array(); |
||
| 110 | foreach ($data->{'vatRates'} as $value_5) { |
||
| 111 | $values_5[] = $this->denormalizer->denormalize($value_5, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModel', 'json', $context); |
||
| 112 | } |
||
| 113 | $object->setVatRates($values_5); |
||
| 114 | } |
||
| 115 | if (property_exists($data, 'categories')) { |
||
| 116 | $values_6 = array(); |
||
| 117 | foreach ($data->{'categories'} as $value_6) { |
||
| 118 | $values_6[] = $this->denormalizer->denormalize($value_6, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModel', 'json', $context); |
||
| 119 | } |
||
| 120 | $object->setCategories($values_6); |
||
| 121 | } |
||
| 122 | if (property_exists($data, 'metaData')) { |
||
| 123 | $values_7 = array(); |
||
| 124 | foreach ($data->{'metaData'} as $value_7) { |
||
| 125 | $values_7[] = $this->denormalizer->denormalize($value_7, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelUpdatable', 'json', $context); |
||
| 126 | } |
||
| 127 | $object->setMetaData($values_7); |
||
| 128 | } |
||
| 129 | return $object; |
||
| 130 | } |
||
| 224 | } |