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 |
||
| 5 | class SandCage { |
||
| 6 | // Your SandCage API Key |
||
| 7 | // This can be retrieved from https://www.sandcage.com/panel/api_key |
||
| 8 | protected $sandcage_api_key = '[YOUR SANDCAGE API KEY]'; |
||
| 9 | |||
| 10 | // SandCage API version |
||
| 11 | protected $sandcage_api_version = '0.2'; |
||
| 12 | |||
| 13 | // SandCage API endpoint base |
||
| 14 | protected $sandcage_api_endpoint_base; |
||
| 15 | |||
| 16 | protected $user_agent; |
||
| 17 | protected $follow_location = false; |
||
| 18 | protected $timeout = 30; |
||
| 19 | protected $post_fields; |
||
| 20 | protected $status; |
||
| 21 | protected $response; |
||
| 22 | |||
| 23 | public function __construct($sandcage_api_key = null) { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The "schedule-tasks" service |
||
| 35 | * @param array $payload values to send |
||
| 36 | * @param string $callback_endpoint to send the callback to |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function scheduleFiles($payload, $callback_endpoint = '') { |
|
| 49 | |||
| 50 | /** |
||
| 51 | * The "destroy-files" service |
||
| 52 | * @param array $payload values to send |
||
| 53 | * @param string $callback_endpoint to send the callback to |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function destroyFiles($payload, $callback_endpoint = '') { |
|
| 66 | |||
| 67 | /** |
||
| 68 | * The "list-files" service |
||
| 69 | * @param array $payload values to send |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function listFiles($payload) { |
|
| 78 | |||
| 79 | /** |
||
| 80 | * The "get-info" service |
||
| 81 | * @param array $payload values to send |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function getInfo($payload) { |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Send a requst using cURL |
||
| 93 | * @param string $service_endpoint to request |
||
| 94 | */ |
||
| 95 | public function call($service_endpoint) { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Return the HTTP status of the call |
||
| 136 | * @return array or FALSE on failure |
||
| 137 | */ |
||
| 138 | public function getHttpStatus() { |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Return the HTTP status of the call |
||
| 146 | * @return array or FALSE on failure |
||
| 147 | */ |
||
| 148 | public function getResponse() { |
||
| 153 | } |
||
| 154 |