Conditions | 20 |
Paths | > 20000 |
Total Lines | 67 |
Code Lines | 46 |
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 |
||
106 | public function normalize($object, $format = null, array $context = array()) |
||
107 | { |
||
108 | $data = new \stdClass(); |
||
109 | if (null !== $object->getProductId()) { |
||
110 | $data->{'productId'} = $object->getProductId(); |
||
111 | } |
||
112 | if (null !== $object->getCreatedAt()) { |
||
113 | $data->{'createdAt'} = $object->getCreatedAt(); |
||
114 | } |
||
115 | $data->{'defaultVatRate'} = $object->getDefaultVatRate(); |
||
116 | if (null !== $object->getVisibility()) { |
||
117 | $data->{'visibility'} = $object->getVisibility(); |
||
118 | } |
||
119 | if (null !== $object->getVisibilityPricelistIds()) { |
||
120 | $values = array(); |
||
121 | foreach ($object->getVisibilityPricelistIds() as $value) { |
||
122 | $values[] = $value; |
||
123 | } |
||
124 | $data->{'visibilityPricelistIds'} = $values; |
||
125 | } |
||
126 | if (null !== $object->getMoreInfoUrl()) { |
||
127 | $data->{'moreInfoUrl'} = $object->getMoreInfoUrl(); |
||
128 | } |
||
129 | $data->{'manufacturerId'} = $object->getManufacturerId(); |
||
130 | $data->{'unitId'} = $object->getUnitId(); |
||
131 | $data->{'sortIndex'} = $object->getSortIndex(); |
||
132 | if (null !== $object->getType()) { |
||
133 | $data->{'type'} = $object->getType(); |
||
134 | } |
||
135 | if (null !== $object->getIsBackInStockWatchable()) { |
||
136 | $data->{'isBackInStockWatchable'} = $object->getIsBackInStockWatchable(); |
||
137 | } |
||
138 | if (null !== $object->getBundleUseManualPrice()) { |
||
139 | $data->{'bundleUseManualPrice'} = $object->getBundleUseManualPrice(); |
||
140 | } |
||
141 | $data->{'accounting'} = $object->getAccounting(); |
||
142 | if (null !== $object->getHasSeveralVariants()) { |
||
143 | $data->{'hasSeveralVariants'} = $object->getHasSeveralVariants(); |
||
144 | } |
||
145 | if (null !== $object->getModifiedAt()) { |
||
146 | $data->{'modifiedAt'} = $object->getModifiedAt(); |
||
147 | } |
||
148 | if (null !== $object->getVariants()) { |
||
149 | $data->{'variants'} = $this->normalizer->normalize($object->getVariants(), 'json', $context); |
||
150 | } |
||
151 | if (null !== $object->getBundledProducts()) { |
||
152 | $data->{'bundledProducts'} = $this->normalizer->normalize($object->getBundledProducts(), 'json', $context); |
||
153 | } |
||
154 | if (null !== $object->getMediaFiles()) { |
||
155 | $data->{'mediaFiles'} = $this->normalizer->normalize($object->getMediaFiles(), 'json', $context); |
||
156 | } |
||
157 | if (null !== $object->getLanguages()) { |
||
158 | $data->{'languages'} = $this->normalizer->normalize($object->getLanguages(), 'json', $context); |
||
159 | } |
||
160 | if (null !== $object->getVatRates()) { |
||
161 | $data->{'vatRates'} = $this->normalizer->normalize($object->getVatRates(), 'json', $context); |
||
162 | } |
||
163 | if (null !== $object->getCategories()) { |
||
164 | $data->{'categories'} = $this->normalizer->normalize($object->getCategories(), 'json', $context); |
||
165 | } |
||
166 | if (null !== $object->getUnit()) { |
||
167 | $data->{'unit'} = $this->normalizer->normalize($object->getUnit(), 'json', $context); |
||
168 | } |
||
169 | if (null !== $object->getMetaData()) { |
||
170 | $data->{'metaData'} = $this->normalizer->normalize($object->getMetaData(), 'json', $context); |
||
171 | } |
||
172 | return $data; |
||
173 | } |
||
174 | } |