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 Result |
||
| 6 | { |
||
| 7 | private $size; |
||
| 8 | private $duration; |
||
| 9 | private $hasSolution; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @param int $size |
||
| 13 | * @param int $duration |
||
| 14 | * @param bool $hasSolution |
||
| 15 | */ |
||
| 16 | public function __construct($size, $duration, $hasSolution) |
||
| 22 | |||
| 23 | public function getSize() |
||
| 27 | |||
| 28 | public function getDuration() |
||
| 32 | |||
| 33 | public function hasSolution() |
||
| 37 | |||
| 38 | View Code Duplication | private function filterSize($size) |
|
| 48 | |||
| 49 | View Code Duplication | private function filterDuration($duration) |
|
| 59 | |||
| 60 | private function filterHasSolution($hasSolution) |
||
| 64 | } |
||
| 65 |