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 |
||
5 | class Mt940Parser |
||
6 | { |
||
7 | /** |
||
8 | * Parse the MT940 file format and return it as an readable array |
||
9 | * |
||
10 | * @param string $filePath |
||
11 | * |
||
12 | * @return array |
||
13 | * |
||
14 | * @throws \Exception |
||
15 | */ |
||
16 | public function parse($filePath) |
||
23 | |||
24 | /** |
||
25 | * Convert the file content into an array structure |
||
26 | * |
||
27 | * @param string $filePath |
||
28 | * |
||
29 | * @return array |
||
30 | * |
||
31 | * @throws \RuntimeException If the file cannot be opened |
||
32 | */ |
||
33 | private function prepareFile($filePath) |
||
68 | |||
69 | /** |
||
70 | * Convert the prepared array into an easily readable form |
||
71 | * |
||
72 | * @param array $preparedArray |
||
73 | * |
||
74 | * @return array |
||
75 | * |
||
76 | * @throws \Exception |
||
77 | */ |
||
78 | private function parseContent($preparedArray) |
||
132 | |||
133 | /** |
||
134 | * @param string $tagContent |
||
135 | * |
||
136 | * @return string |
||
137 | * |
||
138 | * @throws \Exception |
||
139 | */ |
||
140 | View Code Duplication | private function parseStatementIdentifier($tagContent) |
|
150 | |||
151 | /** |
||
152 | * @param string $tagContent |
||
153 | * |
||
154 | * @return string |
||
155 | * |
||
156 | * @throws \Exception |
||
157 | */ |
||
158 | View Code Duplication | private function parseAccountNumber($tagContent) |
|
168 | |||
169 | /** |
||
170 | * @param string $tagContent |
||
171 | * |
||
172 | * @return string |
||
173 | * |
||
174 | * @throws \Exception |
||
175 | */ |
||
176 | View Code Duplication | private function parseStatementNumber($tagContent) |
|
186 | |||
187 | /** |
||
188 | * @param string $tagContent |
||
189 | * |
||
190 | * @return array |
||
191 | * |
||
192 | * @throws \Exception |
||
193 | */ |
||
194 | private function parseBalance($tagContent) |
||
207 | |||
208 | /** |
||
209 | * @param string $tagContent |
||
210 | * |
||
211 | * @return array |
||
212 | * |
||
213 | * @throws \Exception |
||
214 | */ |
||
215 | private function parseTransaction($tagContent) |
||
243 | |||
244 | /** |
||
245 | * @param string $tagContent |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | private function parseTransactionDetails($tagContent) |
||
253 | } |
||
254 |