| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 78 |
| Code Lines | 55 |
| 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 |
||
| 117 | public function normalize($object, $format = null, array $context = array()) |
||
| 118 | { |
||
| 119 | $data = new \stdClass(); |
||
| 120 | if (null !== $object->getProductId()) { |
||
| 121 | $data->{'productId'} = $object->getProductId(); |
||
| 122 | } |
||
| 123 | if (null !== $object->getCreatedAt()) { |
||
| 124 | $data->{'createdAt'} = $object->getCreatedAt(); |
||
| 125 | } |
||
| 126 | $data->{'defaultVatRate'} = $object->getDefaultVatRate(); |
||
| 127 | if (null !== $object->getVisibility()) { |
||
| 128 | $data->{'visibility'} = $object->getVisibility(); |
||
| 129 | } |
||
| 130 | if (null !== $object->getVisibilityPricelistIds()) { |
||
| 131 | $values = array(); |
||
| 132 | foreach ($object->getVisibilityPricelistIds() as $value) { |
||
| 133 | $values[] = $value; |
||
| 134 | } |
||
| 135 | $data->{'visibilityPricelistIds'} = $values; |
||
| 136 | } |
||
| 137 | if (null !== $object->getMoreInfoUrl()) { |
||
| 138 | $data->{'moreInfoUrl'} = $object->getMoreInfoUrl(); |
||
| 139 | } |
||
| 140 | $data->{'manufacturerId'} = $object->getManufacturerId(); |
||
| 141 | $data->{'unitId'} = $object->getUnitId(); |
||
| 142 | $data->{'sortIndex'} = $object->getSortIndex(); |
||
| 143 | if (null !== $object->getType()) { |
||
| 144 | $data->{'type'} = $object->getType(); |
||
| 145 | } |
||
| 146 | if (null !== $object->getIsBackInStockWatchable()) { |
||
| 147 | $data->{'isBackInStockWatchable'} = $object->getIsBackInStockWatchable(); |
||
| 148 | } |
||
| 149 | if (null !== $object->getBundleUseManualPrice()) { |
||
| 150 | $data->{'bundleUseManualPrice'} = $object->getBundleUseManualPrice(); |
||
| 151 | } |
||
| 152 | $data->{'accounting'} = $object->getAccounting(); |
||
| 153 | if (null !== $object->getHasSeveralVariants()) { |
||
| 154 | $data->{'hasSeveralVariants'} = $object->getHasSeveralVariants(); |
||
| 155 | } |
||
| 156 | if (null !== $object->getModifiedAt()) { |
||
| 157 | $data->{'modifiedAt'} = $object->getModifiedAt(); |
||
| 158 | } |
||
| 159 | if (null !== $object->getMediaFiles()) { |
||
| 160 | $values_1 = array(); |
||
| 161 | foreach ($object->getMediaFiles() as $value_1) { |
||
| 162 | $values_1[] = $this->normalizer->normalize($value_1, 'json', $context); |
||
| 163 | } |
||
| 164 | $data->{'mediaFiles'} = $values_1; |
||
| 165 | } |
||
| 166 | if (null !== $object->getLanguages()) { |
||
| 167 | $values_2 = array(); |
||
| 168 | foreach ($object->getLanguages() as $value_2) { |
||
| 169 | $values_2[] = $this->normalizer->normalize($value_2, 'json', $context); |
||
| 170 | } |
||
| 171 | $data->{'languages'} = $values_2; |
||
| 172 | } |
||
| 173 | if (null !== $object->getVatRates()) { |
||
| 174 | $values_3 = array(); |
||
| 175 | foreach ($object->getVatRates() as $value_3) { |
||
| 176 | $values_3[] = $this->normalizer->normalize($value_3, 'json', $context); |
||
| 177 | } |
||
| 178 | $data->{'vatRates'} = $values_3; |
||
| 179 | } |
||
| 180 | if (null !== $object->getCategories()) { |
||
| 181 | $values_4 = array(); |
||
| 182 | foreach ($object->getCategories() as $value_4) { |
||
| 183 | $values_4[] = $this->normalizer->normalize($value_4, 'json', $context); |
||
| 184 | } |
||
| 185 | $data->{'categories'} = $values_4; |
||
| 186 | } |
||
| 187 | if (null !== $object->getMetaData()) { |
||
| 188 | $values_5 = array(); |
||
| 189 | foreach ($object->getMetaData() as $value_5) { |
||
| 190 | $values_5[] = $this->normalizer->normalize($value_5, 'json', $context); |
||
| 191 | } |
||
| 192 | $data->{'metaData'} = $values_5; |
||
| 193 | } |
||
| 194 | return $data; |
||
| 195 | } |
||
| 196 | } |