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($locationId) |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Gets an stdClass containing location-information |
||
| 22 | * |
||
| 23 | * @return stdClass, location |
||
|
|
|||
| 24 | */ |
||
| 25 | protected function getLocation() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Sets the location by providing it's exact name |
||
| 47 | * |
||
| 48 | * @param string, location name |
||
| 49 | * @return bool, success or fail |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function setLocationByName($name) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Sets the location by providing it's country code |
||
| 67 | * |
||
| 68 | * @param string |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function setLocationByCode($cc) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Gets the location ID |
||
| 87 | * |
||
| 88 | * @return int |
||
| 89 | */ |
||
| 90 | public function getLocationId() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Gets the location name |
||
| 97 | * |
||
| 98 | * @return string, name |
||
| 99 | */ |
||
| 100 | public function getLocationName() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Check whether the given location is a country or a region |
||
| 107 | * |
||
| 108 | * @return bool |
||
| 109 | */ |
||
| 110 | public function isCountry() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Gets the country code for the given location |
||
| 117 | * |
||
| 118 | * @return string, country code |
||
| 119 | */ |
||
| 120 | public function getCountryCode() |
||
| 131 | } |
||
| 132 | |||
| 133 | ?> |
||
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.