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 |
||
| 16 | class PlayerProxy extends Proxy implements PlayerInterface { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * {@inheritdoc} |
||
| 20 | */ |
||
| 21 | View Code Duplication | public function load() { |
|
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | 1 | public function getId() { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | 1 | public function getTeam() { |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | 1 | public function getNationality() { |
|
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | 1 | public function getName() { |
|
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | 1 | public function getSport() { |
|
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | 1 | public function getBirthDay() { |
|
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | 1 | public function getDateSigned() { |
|
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | 1 | public function getSigning() { |
|
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | 1 | public function getWage() { |
|
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | 1 | public function getBirthLocation() { |
|
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritdoc} |
||
| 102 | */ |
||
| 103 | 1 | public function getDescription() { |
|
| 106 | |||
| 107 | /** |
||
| 108 | * {@inheritdoc} |
||
| 109 | */ |
||
| 110 | 1 | public function getGender() { |
|
| 113 | |||
| 114 | /** |
||
| 115 | * {@inheritdoc} |
||
| 116 | */ |
||
| 117 | 1 | public function getPosition() { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | 1 | public function getFacebook() { |
|
| 127 | |||
| 128 | /** |
||
| 129 | * {@inheritdoc} |
||
| 130 | */ |
||
| 131 | 1 | public function getWebsite() { |
|
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | 1 | public function getTwitter() { |
|
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | 1 | public function getInstagram() { |
|
| 148 | |||
| 149 | /** |
||
| 150 | * {@inheritdoc} |
||
| 151 | */ |
||
| 152 | 1 | public function getYoutube() { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | 1 | public function getHeight() { |
|
| 162 | |||
| 163 | /** |
||
| 164 | * {@inheritdoc} |
||
| 165 | */ |
||
| 166 | 1 | public function getWeight() { |
|
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | 1 | public function getThumb() { |
|
| 176 | |||
| 177 | /** |
||
| 178 | * {@inheritdoc} |
||
| 179 | */ |
||
| 180 | 1 | public function getCutout() { |
|
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | 1 | public function getLocked() { |
|
| 190 | } |
||
| 191 |
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.