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 |
||
| 13 | class Application extends Api |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $appKey; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $clientId; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Supported batch endpoints |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $supportedBatchEndpoints = array( |
||
| 31 | "activities", |
||
| 32 | "activities/summaries", |
||
| 33 | "heart_rates", |
||
| 34 | "bmis", |
||
| 35 | "body_fats", |
||
| 36 | "heights", |
||
| 37 | "weights", |
||
| 38 | "blood_glucoses", |
||
| 39 | "blood_oxygens", |
||
| 40 | "sleeps", |
||
| 41 | "blood_pressures", |
||
| 42 | "genetic_traits", |
||
| 43 | "locations", |
||
| 44 | "food/meals", |
||
| 45 | ); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Constructor |
||
| 49 | * |
||
| 50 | * @param string $appKey HumanAPI app key |
||
| 51 | * @param string $clientId HumanAPI client ID |
||
| 52 | */ |
||
| 53 | public function __construct($appKey, $clientId) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Batch get endpoint data |
||
| 65 | * |
||
| 66 | * @param string $endpoint |
||
| 67 | * @param array $params |
||
| 68 | * @return Collection |
||
| 69 | * @throws UnsupportedBatchEndpointException |
||
| 70 | */ |
||
| 71 | public function batch($endpoint, array $params = array()) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get users |
||
| 96 | * |
||
| 97 | * @return Collection |
||
| 98 | */ |
||
| 99 | View Code Duplication | public function getUsers() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Get user by human ID |
||
| 119 | * |
||
| 120 | * @param string $humanId Human ID |
||
| 121 | * @return Model |
||
| 122 | */ |
||
| 123 | View Code Duplication | public function getUserById($humanId) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Delete a user by human ID |
||
| 143 | * |
||
| 144 | * @param string $humanId Human ID |
||
| 145 | * @return bool |
||
| 146 | * @throws \Exception |
||
| 147 | */ |
||
| 148 | public function deleteUserById($humanId) |
||
| 177 | } |
||
| 178 |