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 |
||
| 18 | class Pools extends Api |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * List pools |
||
| 22 | * List configured pools |
||
| 23 | */ |
||
| 24 | public function pools() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Create a pool |
||
| 31 | * Create a new pool |
||
| 32 | * |
||
| 33 | * @param string $name Object name |
||
| 34 | * @param array $origins A list of origins contained in the pool. |
||
| 35 | * Traffic destined to the pool is balanced across all |
||
| 36 | * available origins contained in the pool (as long as the pool |
||
| 37 | * is considered available). |
||
| 38 | * @param string|null $description Object description |
||
| 39 | * @param bool|null $enabled Whether this pool is enabled or not. |
||
| 40 | * @param string|null $monitor ID of the monitor object to use for monitoring the health |
||
| 41 | * status of origins inside this pool. |
||
| 42 | * @param string|null $notification_email ID of the notifier object to use for notifications relating |
||
| 43 | * to the health status of origins inside this pool. |
||
| 44 | */ |
||
| 45 | public function create($name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Pool details |
||
| 61 | * Fetch a single configured pool |
||
| 62 | * |
||
| 63 | * @param string $identifier |
||
| 64 | */ |
||
| 65 | public function details($identifier) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Modify a pool |
||
| 72 | * Modify a configured pool |
||
| 73 | * |
||
| 74 | * @param string $identifier |
||
| 75 | * @param string $name Object name |
||
| 76 | * @param array $origins A list of origins contained in the pool. |
||
| 77 | * Traffic destined to the pool is balanced across all |
||
| 78 | * available origins contained in the pool (as long as the pool |
||
| 79 | * is considered available). |
||
| 80 | * @param string|null $description Object description |
||
| 81 | * @param bool|null $enabled Whether this pool is enabled or not. |
||
| 82 | * @param string|null $monitor ID of the monitor object to use for monitoring the health |
||
| 83 | * status of origins inside this pool. |
||
| 84 | * @param string|null $notification_email ID of the notifier object to use for notifications relating |
||
| 85 | * to the health status of origins inside this pool. |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function update($identifier, $name, $origins, $description = null, $enabled = null, $monitor = null, $notification_email = null) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Delete a pool |
||
| 103 | * Delete a configured pool |
||
| 104 | * |
||
| 105 | * @param string $identifier |
||
| 106 | */ |
||
| 107 | public function delete_pool($identifier) |
||
| 111 | } |
||
| 112 |