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 |
||
21 | class Transaction implements RouteInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | Root |
||
26 | */ |
||
27 | public static function root() |
||
31 | /** |
||
32 | * Initialize transaction |
||
33 | * |
||
34 | * @return array - definition for this route |
||
35 | * |
||
36 | * @static |
||
37 | */ |
||
38 | View Code Duplication | public static function initialize() |
|
48 | /** |
||
49 | * Charge authorization |
||
50 | * |
||
51 | * @static |
||
52 | */ |
||
53 | View Code Duplication | public static function charge() |
|
62 | /** |
||
63 | * Charge token |
||
64 | * |
||
65 | * @static |
||
66 | */ |
||
67 | View Code Duplication | public static function chargeToken() |
|
76 | /** |
||
77 | * Get transaction by ID |
||
78 | * |
||
79 | * @static |
||
80 | */ |
||
81 | public static function fetch() |
||
87 | |||
88 | /** |
||
89 | * List transactions |
||
90 | * |
||
91 | * @static |
||
92 | * @see |
||
93 | * @since |
||
94 | */ |
||
95 | public static function getList() |
||
100 | /** |
||
101 | * Export transactions |
||
102 | * |
||
103 | * @static |
||
104 | * @see |
||
105 | * @since |
||
106 | */ |
||
107 | public static function export() |
||
112 | /* |
||
113 | Get totals |
||
114 | */ |
||
115 | |||
116 | /** |
||
117 | * totals |
||
118 | * Insert description here |
||
119 | * |
||
120 | * @return |
||
121 | * |
||
122 | * @access |
||
123 | * @static |
||
124 | * @see |
||
125 | * @since |
||
126 | */ |
||
127 | public static function totals() |
||
132 | /* |
||
133 | Verify transaction |
||
134 | */ |
||
135 | |||
136 | /** |
||
137 | * verify |
||
138 | * Insert description here |
||
139 | * |
||
140 | * @return |
||
141 | * |
||
142 | * @access |
||
143 | * @static |
||
144 | * @see |
||
145 | * @since |
||
146 | */ |
||
147 | public static function verify() |
||
153 | } |
||
154 |
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.