Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
29 | class FinTs |
||
30 | { |
||
31 | const DEFAULT_COUNTRY_CODE = 280; |
||
32 | |||
33 | /** @var LoggerInterface */ |
||
34 | protected $logger; |
||
35 | /** @var string */ |
||
36 | protected $server; |
||
37 | /** @var int */ |
||
38 | protected $port; |
||
39 | /** @var string */ |
||
40 | protected $bankCode; |
||
41 | /** @var string */ |
||
42 | protected $username; |
||
43 | /** @var string */ |
||
44 | protected $pin; |
||
45 | /** @var Connection */ |
||
46 | protected $connection; |
||
47 | /** @var AdapterInterface */ |
||
48 | protected $adapter; |
||
49 | /** @var int */ |
||
50 | protected $systemId = 0; |
||
51 | /** @var string */ |
||
52 | protected $bankName; |
||
53 | /** @var string */ |
||
54 | protected $productName; |
||
55 | /** @var string */ |
||
56 | protected $productVersion; |
||
57 | |||
58 | /** |
||
59 | * FinTs constructor. |
||
60 | * @param string $server Base URL (should start with https://) where the bank's server can be reached. |
||
61 | * @param int $port The port to use for the connection. Use 443 for HTTPS. |
||
62 | * @param string $bankCode The bank's identifier (Bankleitzahl). |
||
63 | * @param string $username The username for authentication. This is assigned by the bank initially, but most banks |
||
64 | * allow users to customize it. |
||
65 | * @param string $pin The PIN for authentication. |
||
66 | * @param string $productName Identifies the product (i.e. the application in which the fints-hbci-php library is |
||
67 | * being used). This is used to show users which products/applications have access to their bank account. Note |
||
68 | * that this shouldn't just be an arbitrary string, but rather the registration number obtained from the |
||
69 | * registration on https://www.hbci-zka.de/register/prod_register.htm. |
||
70 | * @param string $productVersion The product version, which can be an arbitrary string, though if your the |
||
71 | * application displays a version number somewhere on its own user interface, it should match that. |
||
72 | * @param LoggerInterface|null $logger |
||
73 | */ |
||
74 | public function __construct( |
||
105 | |||
106 | /** |
||
107 | * Sets the adapter to use. |
||
108 | * |
||
109 | * @param AdapterInterface $adapter |
||
110 | */ |
||
111 | public function setAdapter(AdapterInterface $adapter) |
||
116 | |||
117 | /** |
||
118 | * Gets array of all accounts. |
||
119 | * |
||
120 | * @return Model\Account[] |
||
121 | */ |
||
122 | public function getAccounts() |
||
131 | |||
132 | /** |
||
133 | * Gets array of all SEPA Accounts. |
||
134 | * |
||
135 | * @return Model\SEPAAccount[] |
||
136 | * @throws Adapter\Exception\AdapterException |
||
137 | * @throws Adapter\Exception\CurlException |
||
138 | */ |
||
139 | public function getSEPAAccounts() |
||
157 | |||
158 | /** |
||
159 | * Gets the bank name. |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getBankName() |
||
171 | |||
172 | /** |
||
173 | * Gets statement of account. |
||
174 | * |
||
175 | * @param SEPAAccount $account |
||
176 | * @param \DateTime $from |
||
177 | * @param \DateTime $to |
||
178 | * @return Model\StatementOfAccount\StatementOfAccount|null |
||
179 | * @throws \Exception |
||
180 | */ |
||
181 | public function getStatementOfAccount(SEPAAccount $account, \DateTime $from, \DateTime $to) |
||
223 | |||
224 | /** |
||
225 | * Helper method to create a "Statement of Account Message". |
||
226 | * |
||
227 | * @param Dialog $dialog |
||
228 | * @param SEPAAccount $account |
||
229 | * @param \DateTime $from |
||
230 | * @param \DateTime $to |
||
231 | * @param string|null $touchdown |
||
232 | * @return Message |
||
233 | * @throws \Exception |
||
234 | */ |
||
235 | protected function createStateOfAccountMessage( |
||
324 | |||
325 | /** |
||
326 | * Gets the saldo of given SEPAAccount. |
||
327 | * |
||
328 | * @param SEPAAccount $account |
||
329 | * @return Model\Saldo|null |
||
330 | * @throws Adapter\Exception\AdapterException |
||
331 | * @throws Adapter\Exception\CurlException |
||
332 | * @throws \Exception |
||
333 | */ |
||
334 | public function getSaldo(SEPAAccount $account) |
||
393 | |||
394 | /** |
||
395 | * Helper method to retrieve a pre configured message object. |
||
396 | * Factory for poor people :) |
||
397 | * |
||
398 | * @param Dialog $dialog |
||
399 | * @param array $segments |
||
400 | * @param array $options |
||
401 | * @return Message |
||
402 | */ |
||
403 | protected function getNewMessage(Dialog $dialog, array $segments, array $options) |
||
416 | |||
417 | /** |
||
418 | * Helper method to retrieve a pre configured dialog object. |
||
419 | * Factory for poor people :) |
||
420 | * |
||
421 | * @return Dialog |
||
422 | */ |
||
423 | protected function getDialog() |
||
436 | |||
437 | /** |
||
438 | * Needed for escaping userdata. |
||
439 | * HBCI escape char is "?" |
||
440 | * |
||
441 | * @param string $string |
||
442 | * @return string |
||
443 | */ |
||
444 | 10 | protected function escapeString($string) |
|
452 | } |
||
453 |
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.