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 |
||
| 17 | class League extends Entity implements LeagueInterface { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * {@inheritdoc} |
||
| 21 | */ |
||
| 22 | protected static $propertyMapDefinition; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The primary identifier. |
||
| 26 | * |
||
| 27 | * @var mixed |
||
| 28 | */ |
||
| 29 | protected $id; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The name. |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $name; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The sport |
||
| 40 | * |
||
| 41 | * @var \TheSportsDb\Entity\SportInterface |
||
| 42 | */ |
||
| 43 | protected $sport; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The alternate name. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $alternateName; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The year the league was formed. |
||
| 54 | * |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | protected $formedYear; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The date of the first event. |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $dateFirstEvent; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The gender. |
||
| 68 | * |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | protected $gender; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The country. |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | protected $country; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The website URL. |
||
| 82 | * |
||
| 83 | * @var string |
||
| 84 | */ |
||
| 85 | protected $website; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The facebook URL. |
||
| 89 | * |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $facebook; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The twitter URL. |
||
| 96 | * |
||
| 97 | * @var string |
||
| 98 | */ |
||
| 99 | protected $twitter; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The youtube URL. |
||
| 103 | * |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | protected $youtube; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The RSS URL. |
||
| 110 | * |
||
| 111 | * @var string |
||
| 112 | */ |
||
| 113 | protected $rss; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * The description. |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | protected $description; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The banner URL. |
||
| 124 | * |
||
| 125 | * @var string |
||
| 126 | */ |
||
| 127 | protected $banner; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The badge URL. |
||
| 131 | * |
||
| 132 | * @var string |
||
| 133 | */ |
||
| 134 | protected $badge; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * The logo URL. |
||
| 138 | * |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $logo; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * The poster URL. |
||
| 145 | * |
||
| 146 | * @var string |
||
| 147 | */ |
||
| 148 | protected $poster; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * The trophy URL. |
||
| 152 | * |
||
| 153 | * @var string |
||
| 154 | */ |
||
| 155 | protected $trophy; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * The event naming pattern. |
||
| 159 | * |
||
| 160 | * @var string |
||
| 161 | */ |
||
| 162 | protected $naming; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Whether or not the league is locked. |
||
| 166 | * |
||
| 167 | * @var string |
||
| 168 | */ |
||
| 169 | protected $locked; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * The seasons. |
||
| 173 | * |
||
| 174 | * @var \TheSportsDb\Entity\SeasonInterface[] |
||
| 175 | */ |
||
| 176 | protected $seasons = array(); |
||
| 177 | |||
| 178 | /** |
||
| 179 | * {@inheritdoc} |
||
| 180 | */ |
||
| 181 | 1 | public function getId() { |
|
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritdoc} |
||
| 187 | */ |
||
| 188 | 1 | public function getName() { |
|
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | 1 | public function getSport() { |
|
| 198 | |||
| 199 | /** |
||
| 200 | * {@inheritdoc} |
||
| 201 | */ |
||
| 202 | 1 | public function getAlternateName() { |
|
| 205 | |||
| 206 | /** |
||
| 207 | * {@inheritdoc} |
||
| 208 | */ |
||
| 209 | 1 | public function getFormedYear() { |
|
| 212 | |||
| 213 | /** |
||
| 214 | * {@inheritdoc} |
||
| 215 | */ |
||
| 216 | 1 | public function getDateFirstEvent() { |
|
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | 1 | public function getGender() { |
|
| 226 | |||
| 227 | /** |
||
| 228 | * {@inheritdoc} |
||
| 229 | */ |
||
| 230 | 1 | public function getCountry() { |
|
| 233 | |||
| 234 | /** |
||
| 235 | * {@inheritdoc} |
||
| 236 | */ |
||
| 237 | 1 | public function getWebsite() { |
|
| 240 | |||
| 241 | /** |
||
| 242 | * {@inheritdoc} |
||
| 243 | */ |
||
| 244 | 1 | public function getFacebook() { |
|
| 247 | |||
| 248 | /** |
||
| 249 | * {@inheritdoc} |
||
| 250 | */ |
||
| 251 | 1 | public function getTwitter() { |
|
| 254 | |||
| 255 | /** |
||
| 256 | * {@inheritdoc} |
||
| 257 | */ |
||
| 258 | 1 | public function getYoutube() { |
|
| 261 | |||
| 262 | /** |
||
| 263 | * {@inheritdoc} |
||
| 264 | */ |
||
| 265 | 1 | public function getRss() { |
|
| 268 | |||
| 269 | /** |
||
| 270 | * {@inheritdoc} |
||
| 271 | */ |
||
| 272 | 1 | public function getDescription() { |
|
| 275 | |||
| 276 | /** |
||
| 277 | * {@inheritdoc} |
||
| 278 | */ |
||
| 279 | 1 | public function getBanner() { |
|
| 282 | |||
| 283 | /** |
||
| 284 | * {@inheritdoc} |
||
| 285 | */ |
||
| 286 | 1 | public function getBadge() { |
|
| 289 | |||
| 290 | /** |
||
| 291 | * {@inheritdoc} |
||
| 292 | */ |
||
| 293 | 1 | public function getLogo() { |
|
| 296 | |||
| 297 | /** |
||
| 298 | * {@inheritdoc} |
||
| 299 | */ |
||
| 300 | 1 | public function getPoster() { |
|
| 303 | |||
| 304 | /** |
||
| 305 | * {@inheritdoc} |
||
| 306 | */ |
||
| 307 | 1 | public function getTrophy() { |
|
| 310 | |||
| 311 | /** |
||
| 312 | * {@inheritdoc} |
||
| 313 | */ |
||
| 314 | 1 | public function getNaming() { |
|
| 317 | |||
| 318 | /** |
||
| 319 | * {@inheritdoc} |
||
| 320 | */ |
||
| 321 | 1 | public function getLocked() { |
|
| 324 | |||
| 325 | /** |
||
| 326 | * {@inheritdoc} |
||
| 327 | */ |
||
| 328 | 1 | public function getSeasons() { |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Transforms the sport property to a sport entity. |
||
| 334 | * |
||
| 335 | * @param mixed $value |
||
| 336 | * The source value of the sport property. |
||
| 337 | * @param \stdClass $context |
||
| 338 | * The source object representing this league. |
||
| 339 | * @param EntityManagerInterface $entityManager |
||
| 340 | * The entity manager. |
||
| 341 | * |
||
| 342 | * @return \TheSportsDb\Entity\SportInterface |
||
| 343 | * The sport entity. |
||
| 344 | */ |
||
| 345 | public static function transformSport($value, $context, EntityManagerInterface $entityManager) { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Transforms the seasons property to season entities. |
||
| 351 | * |
||
| 352 | * @param array $values |
||
| 353 | * The source value of the seasons property. |
||
| 354 | * @param \stdClass $context |
||
| 355 | * The source object representing this league. |
||
| 356 | * @param EntityManagerInterface $entityManager |
||
| 357 | * The entity manager. |
||
| 358 | * |
||
| 359 | * @return \TheSportsDb\Entity\SeasonInterface[] |
||
| 360 | * The season entities. |
||
| 361 | */ |
||
| 362 | public static function transformSeasons($values, $context, EntityManagerInterface $entityManager) { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * {@inheritdoc} |
||
| 373 | */ |
||
| 374 | 1 | View Code Duplication | protected static function initPropertyMapDefinition() { |
| 486 | |||
| 487 | } |
||
| 488 |