Conditions | 14 |
Paths | 512 |
Total Lines | 52 |
Code Lines | 37 |
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 |
||
91 | public function normalize($object, $format = null, array $context = array()) |
||
92 | { |
||
93 | $data = new \stdClass(); |
||
94 | if (null !== $object->getSku()) { |
||
95 | $data->{'sku'} = $object->getSku(); |
||
96 | } |
||
97 | if (null !== $object->getIsActive()) { |
||
98 | $data->{'isActive'} = $object->getIsActive(); |
||
99 | } |
||
100 | if (null !== $object->getSortIndex()) { |
||
101 | $data->{'sortIndex'} = $object->getSortIndex(); |
||
102 | } |
||
103 | $data->{'stockStatusId'} = $object->getStockStatusId(); |
||
104 | $data->{'stockQuantity'} = $object->getStockQuantity(); |
||
105 | $data->{'weightInKg'} = $object->getWeightInKg(); |
||
106 | $data->{'costPrice'} = $object->getCostPrice(); |
||
107 | if (null !== $object->getEan()) { |
||
108 | $data->{'ean'} = $object->getEan(); |
||
109 | } |
||
110 | if (null !== $object->getMpn()) { |
||
111 | $data->{'mpn'} = $object->getMpn(); |
||
112 | } |
||
113 | $data->{'imageFileId'} = $object->getImageFileId(); |
||
114 | if (null !== $object->getAttributeValueLinks()) { |
||
115 | $values = array(); |
||
116 | foreach ($object->getAttributeValueLinks() as $value) { |
||
117 | $values[] = $value; |
||
118 | } |
||
119 | $data->{'attributeValueLinks'} = $values; |
||
120 | } |
||
121 | if (null !== $object->getVolumePricingInheritancePricelistIds()) { |
||
122 | $values_1 = array(); |
||
123 | foreach ($object->getVolumePricingInheritancePricelistIds() as $value_1) { |
||
124 | $values_1[] = $value_1; |
||
125 | } |
||
126 | $data->{'volumePricingInheritancePricelistIds'} = $values_1; |
||
127 | } |
||
128 | if (null !== $object->getPrices()) { |
||
129 | $values_2 = array(); |
||
130 | foreach ($object->getPrices() as $value_2) { |
||
131 | $values_2[] = $this->normalizer->normalize($value_2, 'json', $context); |
||
132 | } |
||
133 | $data->{'prices'} = $values_2; |
||
134 | } |
||
135 | if (null !== $object->getAttributeValues()) { |
||
136 | $values_3 = array(); |
||
137 | foreach ($object->getAttributeValues() as $value_3) { |
||
138 | $values_3[] = $this->normalizer->normalize($value_3, 'json', $context); |
||
139 | } |
||
140 | $data->{'attributeValues'} = $values_3; |
||
141 | } |
||
142 | return $data; |
||
143 | } |
||
144 | } |