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 |
||
11 | class Rabo extends Engine |
||
12 | { |
||
13 | /** |
||
14 | * returns the name of the bank. |
||
15 | * |
||
16 | * @return string |
||
17 | */ |
||
18 | protected function parseStatementBank() |
||
22 | |||
23 | /** |
||
24 | * Overloaded: Rabo has different way of storing account info. |
||
25 | * |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | View Code Duplication | protected function parseTransactionAccount() |
|
46 | |||
47 | /** |
||
48 | * Overloaded: Rabo has different way of storing account name. |
||
49 | * |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | protected function parseTransactionAccountName() |
||
53 | { |
||
54 | $results = []; |
||
55 | // SEPA MT940 Structured |
||
56 | View Code Duplication | if (preg_match('#/NAME/(.+?)\n?/(REMI|ADDR|ISDT|CSID)/#ms', $this->getCurrentTransactionData(), $results)) { |
|
57 | $accountName = trim($results[1]); |
||
58 | if (!empty($accountName)) { |
||
59 | return $this->sanitizeAccountName($accountName); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | View Code Duplication | if (preg_match('/^:61:.*? (.+)/m', $this->getCurrentTransactionData(), $results)) { |
|
64 | $accountName = trim($results[1]); |
||
65 | if (!empty($accountName)) { |
||
66 | return $this->sanitizeAccountName($accountName); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | View Code Duplication | if (preg_match('/(.*) Betaalautomaat/', $this->parseTransactionDescription(), $results)) { |
|
71 | $accountName = trim($results[1]); |
||
72 | if (!empty($accountName)) { |
||
73 | return $this->sanitizeAccountName($accountName); |
||
74 | } |
||
75 | } |
||
76 | return ''; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Overloaded: Rabo has different way of storing transaction value timestamps (ymd). |
||
81 | * |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | View Code Duplication | protected function parseTransactionEntryTimestamp() |
|
85 | { |
||
86 | $results = []; |
||
87 | if (preg_match('/^:60F:[C|D]([\d]{6})/m', $this->getCurrentStatementData(), $results) && !empty($results[1])) { |
||
88 | return $this->sanitizeTimestamp($results[1], 'ymd'); |
||
89 | } |
||
90 | |||
91 | return 0; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Overloaded: Rabo has different way of storing transaction value timestamps (ymd). |
||
96 | * |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | View Code Duplication | protected function parseTransactionValueTimestamp() |
|
108 | |||
109 | /** |
||
110 | * Overloaded: Rabo uses longer strings for accountnumbers. |
||
111 | * |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | protected function sanitizeAccount($string) |
||
123 | |||
124 | /** |
||
125 | * Overloaded: Rabo encapsulates the description with /REMI/ for SEPA. |
||
126 | * |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | protected function sanitizeDescription($string) |
||
151 | |||
152 | /** |
||
153 | * Overloaded: Is applicable if first line has :940:. |
||
154 | * |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public static function isApplicable($string) |
||
163 | } |
||
164 |
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.