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 |
||
| 26 | class RaLocation |
||
|
|
|||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var RaLocationId |
||
| 30 | */ |
||
| 31 | private $raLocationId; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var RaLocationName |
||
| 35 | */ |
||
| 36 | private $raLocationName; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var Location |
||
| 40 | */ |
||
| 41 | private $location; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var ContactInformation |
||
| 45 | */ |
||
| 46 | private $contactInformation; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param RaLocationId $raLocationId |
||
| 50 | * @param RaLocationName $raLocationName |
||
| 51 | * @param Location $location |
||
| 52 | * @param ContactInformation $contactInformation |
||
| 53 | * @return RaLocation |
||
| 54 | */ |
||
| 55 | public static function create( |
||
| 63 | |||
| 64 | View Code Duplication | private function __construct( |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @param RaLocationName $raLocationName |
||
| 78 | */ |
||
| 79 | public function rename(RaLocationName $raLocationName) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param Location $location |
||
| 86 | */ |
||
| 87 | public function relocate(Location $location) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param ContactInformation $contactInformation |
||
| 94 | */ |
||
| 95 | public function changeContactInformation(ContactInformation $contactInformation) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param RaLocationId $raLocationId |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | public function hasRaLocationId(RaLocationId $raLocationId) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return RaLocationId |
||
| 111 | */ |
||
| 112 | public function getRaLocationId() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return RaLocationName |
||
| 119 | */ |
||
| 120 | public function getRaLocationName() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return Location |
||
| 127 | */ |
||
| 128 | public function getLocation() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return ContactInformation |
||
| 135 | */ |
||
| 136 | public function getContactInformation() |
||
| 140 | } |
||
| 141 |