Conditions | 34 |
Paths | 48 |
Total Lines | 97 |
Code Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
116 | public function setParameter($key, $value) |
||
117 | { |
||
118 | switch ((string) $key) { |
||
119 | // limited values |
||
120 | case 'action': |
||
121 | case 'lang': |
||
122 | $allowedValues = array(); |
||
123 | $allowedValues['action'] = array('START', 'CONFIRM'); |
||
124 | $allowedValues['lang'] = array('NL', 'FR', 'EN', 'DE', 'Default'); |
||
125 | |||
126 | if (!in_array($value, $allowedValues[$key])) { |
||
127 | throw new BpostInvalidValueException($key, $value, $allowedValues[$key]); |
||
128 | } |
||
129 | $this->parameters[$key] = $value; |
||
130 | break; |
||
131 | |||
132 | // maximum 2 chars |
||
133 | case 'customerCountry': |
||
134 | if (mb_strlen($value) > 2) { |
||
135 | throw new BpostInvalidLengthException($key, mb_strlen($value), 2); |
||
136 | } |
||
137 | $this->parameters[$key] = (string) $value; |
||
138 | break; |
||
139 | |||
140 | // maximum 8 chars |
||
141 | case 'customerStreetNumber': |
||
142 | case 'customerBox': |
||
143 | if (mb_strlen($value) > 8) { |
||
144 | throw new BpostInvalidLengthException($key, mb_strlen($value), 8); |
||
145 | } |
||
146 | $this->parameters[$key] = (string) $value; |
||
147 | break; |
||
148 | |||
149 | // maximum 20 chars |
||
150 | case 'customerPhoneNumber': |
||
151 | if (mb_strlen($value) > 20) { |
||
152 | throw new BpostInvalidLengthException($key, mb_strlen($value), 20); |
||
153 | } |
||
154 | $this->parameters[$key] = (string) $value; |
||
155 | break; |
||
156 | |||
157 | // maximum 32 chars |
||
158 | case 'customerPostalCode': |
||
159 | if (mb_strlen($value) > 32) { |
||
160 | throw new BpostInvalidLengthException($key, mb_strlen($value), 32); |
||
161 | } |
||
162 | $this->parameters[$key] = (string) $value; |
||
163 | break; |
||
164 | |||
165 | // maximum 40 chars |
||
166 | case 'customerFirstName': |
||
167 | case 'customerLastName': |
||
168 | case 'customerCompany': |
||
169 | case 'customerStreet': |
||
170 | case 'customerCity': |
||
171 | if (mb_strlen($value) > 40) { |
||
172 | throw new BpostInvalidLengthException($key, mb_strlen($value), 40); |
||
173 | } |
||
174 | $this->parameters[$key] = (string) $value; |
||
175 | break; |
||
176 | |||
177 | // maximum 50 chars |
||
178 | case 'orderReference': |
||
179 | case 'costCenter': |
||
180 | case 'customerEmail': |
||
181 | if (mb_strlen($value) > 50) { |
||
182 | throw new BpostInvalidLengthException($key, mb_strlen($value), 50); |
||
183 | } |
||
184 | $this->parameters[$key] = (string) $value; |
||
185 | break; |
||
186 | |||
187 | // integers |
||
188 | case 'orderTotalPrice': |
||
189 | case 'orderWeight': |
||
190 | $this->parameters[$key] = (int) $value; |
||
191 | break; |
||
192 | |||
193 | // array |
||
194 | case 'orderLine': |
||
195 | if (!isset($this->parameters[$key])) { |
||
196 | $this->parameters[$key] = array(); |
||
197 | } |
||
198 | $this->parameters[$key][] = $value; |
||
199 | break; |
||
200 | |||
201 | // unknown |
||
202 | case 'deliveryMethodOverrides': |
||
203 | case 'extra': |
||
204 | case 'extraSecure': |
||
205 | case 'confirmUrl': |
||
206 | case 'cancelUrl': |
||
207 | case 'errorUrl': |
||
208 | default: |
||
209 | if (is_array($value)) { |
||
210 | sort($value); |
||
211 | } |
||
212 | $this->parameters[$key] = $value; |
||
213 | } |
||
216 |