Conditions | 11 |
Paths | 1024 |
Total Lines | 34 |
Code Lines | 22 |
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 |
||
63 | public function normalize($object, $format = null, array $context = array()) |
||
64 | { |
||
65 | $data = new \stdClass(); |
||
66 | if (null !== $object->getItemId()) { |
||
67 | $data->{'itemId'} = $object->getItemId(); |
||
68 | } |
||
69 | if (null !== $object->getSku()) { |
||
70 | $data->{'sku'} = $object->getSku(); |
||
71 | } |
||
72 | if (null !== $object->getDescription()) { |
||
73 | $data->{'description'} = $object->getDescription(); |
||
74 | } |
||
75 | if (null !== $object->getQuantity()) { |
||
76 | $data->{'quantity'} = $object->getQuantity(); |
||
77 | } |
||
78 | if (null !== $object->getUnitSymbol()) { |
||
79 | $data->{'unitSymbol'} = $object->getUnitSymbol(); |
||
80 | } |
||
81 | if (null !== $object->getUnitPrice()) { |
||
82 | $data->{'unitPrice'} = $object->getUnitPrice(); |
||
83 | } |
||
84 | if (null !== $object->getVatRate()) { |
||
85 | $data->{'vatRate'} = $object->getVatRate(); |
||
86 | } |
||
87 | if (null !== $object->getDiscount()) { |
||
88 | $data->{'discount'} = $object->getDiscount(); |
||
89 | } |
||
90 | if (null !== $object->getDiscountType()) { |
||
91 | $data->{'discountType'} = $object->getDiscountType(); |
||
92 | } |
||
93 | if (null !== $object->getSortIndex()) { |
||
94 | $data->{'sortIndex'} = $object->getSortIndex(); |
||
95 | } |
||
96 | return $data; |
||
97 | } |
||
98 | } |