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 |
||
13 | class Spk extends Engine |
||
14 | { |
||
15 | /** |
||
16 | * returns the name of the bank. |
||
17 | * |
||
18 | * @return string |
||
19 | */ |
||
20 | protected function parseStatementBank() |
||
24 | |||
25 | /** |
||
26 | * Overloaded: Sparkasse uses 60M and 60F. |
||
27 | * |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | protected function parseStatementStartPrice() |
||
34 | |||
35 | /** |
||
36 | * Overloaded: Sparkasse uses 60M and 60F. |
||
37 | * |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | protected function parseStatementStartTimestamp() |
||
44 | |||
45 | /** |
||
46 | * Overloaded: Sparkasse uses 60M and 60F. |
||
47 | * |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | protected function parseStatementEndTimestamp() |
||
54 | |||
55 | /** |
||
56 | * Overloaded: Sparkasse uses 62M and 62F. |
||
57 | * |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | protected function parseStatementEndPrice() |
||
64 | |||
65 | /** |
||
66 | * Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D |
||
67 | * currency codes last letter is always a letter http://www.xe.com/iso4217.php. |
||
68 | * |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | View Code Duplication | protected function parseTransactionPrice() |
|
82 | |||
83 | /** |
||
84 | * Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D and an "R" for cancellation befor the C/D. |
||
85 | * |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | View Code Duplication | protected function parseTransactionDebitCredit() |
|
99 | |||
100 | /** |
||
101 | * Overloaded: Sparkasse use the Field 61 for cancellations |
||
102 | * |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | protected function parseTransactionCancellation() |
||
115 | |||
116 | /** |
||
117 | * Overloaded: Sparkasse does not have a header line. |
||
118 | * |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | protected function parseStatementData() |
||
130 | |||
131 | /** |
||
132 | * Overloaded: Is applicable if first or second line has :20:STARTUMS or first line has -. |
||
133 | * |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public static function isApplicable($string) |
||
143 | } |
||
144 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.