Conditions | 11 |
Paths | 512 |
Total Lines | 40 |
Code Lines | 28 |
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 |
||
79 | public function normalize($object, $format = null, array $context = array()) |
||
80 | { |
||
81 | $data = new \stdClass(); |
||
82 | if (null !== $object->getPaymentMethodId()) { |
||
83 | $data->{'paymentMethodId'} = $object->getPaymentMethodId(); |
||
84 | } |
||
85 | if (null !== $object->getIdCode()) { |
||
86 | $data->{'idCode'} = $object->getIdCode(); |
||
87 | } |
||
88 | if (null !== $object->getActive()) { |
||
89 | $data->{'active'} = $object->getActive(); |
||
90 | } |
||
91 | if (null !== $object->getFee()) { |
||
92 | $data->{'fee'} = $object->getFee(); |
||
93 | } |
||
94 | if (null !== $object->getValidForCountries()) { |
||
95 | $data->{'validForCountries'} = $object->getValidForCountries(); |
||
96 | } |
||
97 | if (null !== $object->getValidCountriesSelected()) { |
||
98 | $values = array(); |
||
99 | foreach ($object->getValidCountriesSelected() as $value) { |
||
100 | $values[] = $value; |
||
101 | } |
||
102 | $data->{'validCountriesSelected'} = $values; |
||
103 | } |
||
104 | $data->{'validForMinItemsSubtotal'} = $object->getValidForMinItemsSubtotal(); |
||
105 | $data->{'validForMaxItemsSubtotal'} = $object->getValidForMaxItemsSubtotal(); |
||
106 | $data->{'validForMinWeight'} = $object->getValidForMinWeight(); |
||
107 | $data->{'validForMaxWeight'} = $object->getValidForMaxWeight(); |
||
108 | if (null !== $object->getValidForShippingMethods()) { |
||
109 | $data->{'validForShippingMethods'} = $object->getValidForShippingMethods(); |
||
110 | } |
||
111 | $data->{'validForCustomerType'} = $object->getValidForCustomerType(); |
||
112 | if (null !== $object->getIsClickAndCollect()) { |
||
113 | $data->{'isClickAndCollect'} = $object->getIsClickAndCollect(); |
||
114 | } |
||
115 | if (null !== $object->getLanguages()) { |
||
116 | $data->{'languages'} = $this->normalizer->normalize($object->getLanguages(), 'json', $context); |
||
117 | } |
||
118 | return $data; |
||
119 | } |
||
120 | } |