| Conditions | 26 |
| Paths | > 20000 |
| Total Lines | 80 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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\ProductModel(); |
||
| 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 | $object->setVariants($this->denormalizer->denormalize($data->{'variants'}, 'Starweb\\Api\\Generated\\Model\\ProductVariantModelCollection', 'json', $context)); |
||
|
|
|||
| 82 | } |
||
| 83 | if (property_exists($data, 'bundledProducts')) { |
||
| 84 | $object->setBundledProducts($this->denormalizer->denormalize($data->{'bundledProducts'}, 'Starweb\\Api\\Generated\\Model\\BundledProductsModelCollection', 'json', $context)); |
||
| 85 | } |
||
| 86 | if (property_exists($data, 'mediaFiles')) { |
||
| 87 | $object->setMediaFiles($this->denormalizer->denormalize($data->{'mediaFiles'}, 'Starweb\\Api\\Generated\\Model\\ProductMediaFileLinkModelCollection', 'json', $context)); |
||
| 88 | } |
||
| 89 | if (property_exists($data, 'languages')) { |
||
| 90 | $object->setLanguages($this->denormalizer->denormalize($data->{'languages'}, 'Starweb\\Api\\Generated\\Model\\ProductModelLanguages', 'json', $context)); |
||
| 91 | } |
||
| 92 | if (property_exists($data, 'vatRates')) { |
||
| 93 | $object->setVatRates($this->denormalizer->denormalize($data->{'vatRates'}, 'Starweb\\Api\\Generated\\Model\\ProductVatRateModelCollection', 'json', $context)); |
||
| 94 | } |
||
| 95 | if (property_exists($data, 'categories')) { |
||
| 96 | $object->setCategories($this->denormalizer->denormalize($data->{'categories'}, 'Starweb\\Api\\Generated\\Model\\ProductCategoryLinkModelCollection', 'json', $context)); |
||
| 97 | } |
||
| 98 | if (property_exists($data, 'unit')) { |
||
| 99 | $object->setUnit($this->denormalizer->denormalize($data->{'unit'}, 'Starweb\\Api\\Generated\\Model\\ProductUnitModelItem', 'json', $context)); |
||
| 100 | } |
||
| 101 | if (property_exists($data, 'metaData')) { |
||
| 102 | $object->setMetaData($this->denormalizer->denormalize($data->{'metaData'}, 'Starweb\\Api\\Generated\\Model\\ProductMetaDataModelCollection', 'json', $context)); |
||
| 103 | } |
||
| 104 | return $object; |
||
| 105 | } |
||
| 174 | } |