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 Monitors extends Api |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * List monitors |
||
| 22 | * List configured monitors for a user |
||
| 23 | * |
||
| 24 | * @param string $organization_identifier |
||
| 25 | */ |
||
| 26 | public function monitors($organization_identifier) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Create a monitor |
||
| 33 | * Create a configured monitor |
||
| 34 | * |
||
| 35 | * @param string $organization_identifier |
||
| 36 | * @param string $expected_body A case-insensitive substring to match in the body of the probe |
||
| 37 | * response to declare an origin as up |
||
| 38 | * @param string $expected_codes The expected HTTP response code or code range for the probe |
||
| 39 | * @param string|null $method The HTTP method to use for the health check. |
||
| 40 | * @param int|null $timeout The timeout (in seconds) before marking the health check as failed |
||
| 41 | * @param string|null $path The endpoint path to health check against. |
||
| 42 | * @param int|null $interval The interval between each health check. Shorter intervals may improve failover |
||
| 43 | * time, but will increase load on the origins as we check from multiple locations. |
||
| 44 | * @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin |
||
| 45 | * as unhealthy. Retries are attempted immediately. |
||
| 46 | * @param array|null $header The HTTP request headers to send in the health check. It is recommended you set |
||
| 47 | * a Host header by default. The User-Agent header cannot be overridden. |
||
| 48 | * @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are |
||
| 49 | * 'HTTP' and 'HTTPS'. |
||
| 50 | * @param string|null $description Object description |
||
| 51 | */ |
||
| 52 | View Code Duplication | public function create($organization_identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Monitor details |
||
| 72 | * List a single configured CTM monitor for a user |
||
| 73 | * |
||
| 74 | * @param string $organization_identifier |
||
| 75 | * @param string $identifier |
||
| 76 | */ |
||
| 77 | public function details($organization_identifier, $identifier) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Modify a monitor |
||
| 84 | * Modify a configured monitor |
||
| 85 | * |
||
| 86 | * @param string $organization_identifier |
||
| 87 | * @param string $identifier |
||
| 88 | * @param string $expected_body A case-insensitive substring to match in the body of the probe |
||
| 89 | * response to declare an origin as up |
||
| 90 | * @param string $expected_codes The expected HTTP response code or code range for the probe |
||
| 91 | * @param string|null $method The HTTP method to use for the health check. |
||
| 92 | * @param int|null $timeout The timeout (in seconds) before marking the health check as failed |
||
| 93 | * @param string|null $path The endpoint path to health check against. |
||
| 94 | * @param int|null $interval The interval between each health check. Shorter intervals may improve failover |
||
| 95 | * time, but will increase load on the origins as we check from multiple locations. |
||
| 96 | * @param int|null $retries The number of retries to attempt in case of a timeout before marking the origin |
||
| 97 | * as unhealthy. Retries are attempted immediately. |
||
| 98 | * @param array|null $header The HTTP request headers to send in the health check. It is recommended you set |
||
| 99 | * a Host header by default. The User-Agent header cannot be overridden. |
||
| 100 | * @param int|null $type The protocol to use for the healthcheck. Currently supported protocols are |
||
| 101 | * 'HTTP' and 'HTTPS'. |
||
| 102 | * @param string|null $description Object description |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function update($organization_identifier, $identifier, $expected_body, $expected_codes, $method = null, $timeout = null, $path = null, $interval = null, $retries = null, $header = null, $type = null, $description = null) |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Delete a monitor |
||
| 124 | * Delete a configured monitor |
||
| 125 | * |
||
| 126 | * @param string $organization_identifier |
||
| 127 | * @param string $identifier |
||
| 128 | */ |
||
| 129 | public function delete_monitor($organization_identifier, $identifier) |
||
| 133 | } |
||
| 134 |