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 |
||
7 | class TerrainGenerator |
||
8 | { |
||
9 | /** |
||
10 | * @param int $rows |
||
11 | * @param int $columns |
||
12 | * @param int | null $seed |
||
13 | * @return TerrainCost |
||
14 | */ |
||
15 | public function generate($rows, $columns, $seed = null) |
||
33 | |||
34 | private function validatePositiveInteger($number) |
||
42 | |||
43 | View Code Duplication | private function validateOptionalInteger($number) |
|
51 | } |
||
52 |