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_Location |
||
| 4 | { |
||
| 5 | protected $api; |
||
| 6 | protected $locationId; |
||
| 7 | protected $location = NULL; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Constructor of CoC_Location |
||
| 11 | * |
||
| 12 | * @param $locationId |
||
| 13 | */ |
||
| 14 | public function __construct($location) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Gets an stdClass containing location-information |
||
| 30 | * |
||
| 31 | * @return stdClass, location |
||
|
|
|||
| 32 | */ |
||
| 33 | protected function getLocation() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Sets the location by providing it's exact name |
||
| 55 | * |
||
| 56 | * @param string, location name |
||
| 57 | * @return bool, success or fail |
||
| 58 | */ |
||
| 59 | View Code Duplication | public function setLocationByName($name) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Sets the location by providing it's country code |
||
| 75 | * |
||
| 76 | * @param string |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function setLocationByCode($cc) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Gets the location ID |
||
| 95 | * |
||
| 96 | * @return int |
||
| 97 | */ |
||
| 98 | public function getLocationId() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Gets the location name |
||
| 105 | * |
||
| 106 | * @return string, name |
||
| 107 | */ |
||
| 108 | public function getLocationName() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Check whether the given location is a country or a region |
||
| 115 | * |
||
| 116 | * @return bool |
||
| 117 | */ |
||
| 118 | public function isCountry() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Gets the country code for the given location |
||
| 125 | * |
||
| 126 | * @return string, country code |
||
| 127 | */ |
||
| 128 | public function getCountryCode() |
||
| 139 | } |
||
| 140 | |||
| 141 | ?> |
||
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.