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 |
||
| 15 | class Version |
||
| 16 | { |
||
| 17 | protected $expansionVersion = null; |
||
| 18 | |||
| 19 | protected $expansionBranch = null; |
||
| 20 | |||
| 21 | protected $expansionSha = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get current expansion version. |
||
| 25 | * |
||
| 26 | * @return null|string |
||
| 27 | */ |
||
| 28 | public function getExpansionVersion() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get a shorten version of the expansion version. |
||
| 51 | * |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | public function getShortExpansionVersion() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get current branch. |
||
| 61 | * |
||
| 62 | * @return null|string |
||
| 63 | */ |
||
| 64 | View Code Duplication | protected function getBranch() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Get current commit sha. |
||
| 78 | * |
||
| 79 | * @return null|string |
||
| 80 | */ |
||
| 81 | View Code Duplication | protected function getSha() |
|
| 92 | } |
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.