Conditions | 18 |
Paths | 18 |
Total Lines | 53 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |
||
156 | protected function parseTransactionType() |
||
157 | { |
||
158 | $code = $this->parseTransactionCode(); |
||
159 | switch ($code) { |
||
160 | case 541: |
||
161 | case 544: |
||
162 | case 102: // "Betaalopdracht IDEAL" |
||
163 | case 547: |
||
164 | $result = TransactionType::get(TransactionType::SEPA_TRANSFER); |
||
165 | break; |
||
166 | |||
167 | case 504: |
||
168 | case 691: |
||
169 | $result = TransactionType::get(TransactionType::SAVINGS_TRANSFER); |
||
170 | break; |
||
171 | case 64: |
||
172 | $result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT); |
||
173 | break; |
||
174 | case 93: |
||
175 | $result = TransactionType::get(TransactionType::BANK_COSTS); |
||
176 | break; |
||
177 | case 13: |
||
178 | case 12: |
||
179 | case 30: |
||
180 | $result = TransactionType::get(TransactionType::PAYMENT_TERMINAL); |
||
181 | break; |
||
182 | case 29: |
||
183 | case 31: |
||
184 | $result = TransactionType::get(TransactionType::ATM_WITHDRAWAL); |
||
185 | break; |
||
186 | case "MSC": |
||
187 | $result = TransactionType::get(TransactionType::BANK_INTEREST); |
||
188 | break; |
||
189 | case 404: // "Buitenland transactie credit" |
||
190 | if (stripos($this->getCurrentTransactionData(), 'eurobetaling') !== false) { |
||
191 | $result = TransactionType::get(TransactionType::SEPA_TRANSFER); |
||
192 | } else { |
||
193 | $result = TransactionType::get(TransactionType::TRANSFER); |
||
194 | } |
||
195 | |||
196 | break; |
||
197 | case 79: // "Acceptgiro Mobiel Bankieren" |
||
198 | $result = TransactionType::get(TransactionType::UNKNOWN); |
||
199 | break; |
||
200 | |||
201 | default: |
||
202 | var_dump($code); |
||
203 | var_dump($this->getCurrentTransactionData()); die(); |
||
204 | throw new \RuntimeException("Don't know code $code for RABOBANK"); |
||
205 | } |
||
206 | |||
207 | return $result; |
||
208 | } |
||
209 | |||
211 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.