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 |
||
| 3 | class CoC_LogEntry |
||
| 4 | { |
||
| 5 | protected $logEntry; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Constructor of CoC_Warlog |
||
| 9 | * |
||
| 10 | * @logEntry $logEntry, obtained by Warlog.class.php |
||
| 11 | */ |
||
| 12 | public function __construct($logEntry) |
||
| 16 | |||
| 17 | protected function getLogEntry() |
||
| 21 | |||
| 22 | public function getResult() |
||
| 26 | |||
| 27 | public function getEndTime() |
||
| 31 | |||
| 32 | public function getTeamSize() |
||
| 36 | |||
| 37 | public function getClanTag() |
||
| 41 | |||
| 42 | public function getClanName() |
||
| 46 | |||
| 47 | View Code Duplication | public function getClanBadeUrl($size = "") |
|
| 65 | |||
| 66 | public function getClanLevel() |
||
| 70 | |||
| 71 | public function getClanAttacks() |
||
| 75 | |||
| 76 | public function getClanStars() |
||
| 80 | |||
| 81 | public function getDestructionPercentage() |
||
| 85 | |||
| 86 | public function getExpEarned() |
||
| 90 | |||
| 91 | public function getOpponentTag() |
||
| 95 | |||
| 96 | public function getOpponentName() |
||
| 100 | |||
| 101 | View Code Duplication | public function getOpponentBadgeUrls($size = "") |
|
| 119 | |||
| 120 | public function getOpponentLevel() |
||
| 124 | |||
| 125 | public function getOpponentStars() |
||
| 129 | |||
| 130 | public function getOpponentDestructionPercentage() |
||
| 134 | } |
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.