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 SandCage { |
||
| 4 | // Your SandCage API Key |
||
| 5 | // This can be retrieved from https://www.sandcage.com/panel/api_key |
||
| 6 | protected $sandcage_api_key = '[YOUR SANDCAGE API KEY]'; |
||
| 7 | |||
| 8 | // SandCage API version |
||
| 9 | protected $sandcage_api_version = '0.2'; |
||
| 10 | |||
| 11 | // SandCage API endpoint base |
||
| 12 | protected $sandcage_api_endpoint_base; |
||
| 13 | |||
| 14 | protected $user_agent; |
||
| 15 | protected $follow_location = true; |
||
| 16 | protected $timeout = 30; |
||
| 17 | protected $post; |
||
| 18 | protected $post_fields; |
||
| 19 | protected $status; |
||
| 20 | protected $response; |
||
| 21 | |||
| 22 | public function __construct($sandcage_api_key=null) { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The "schedule-tasks" service |
||
| 34 | * @param array $payload values to send |
||
| 35 | * @param string $callback_endpoint to send the callback to |
||
| 36 | */ |
||
| 37 | 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='') { |
|
| 67 | |||
| 68 | /** |
||
| 69 | * The "list-files" service |
||
| 70 | * @param array $payload values to send |
||
| 71 | */ |
||
| 72 | View Code Duplication | public function listFiles($payload) { |
|
| 80 | |||
| 81 | /** |
||
| 82 | * The "get-info" service |
||
| 83 | * @param array $payload values to send |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function getInfo($payload) { |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Send a requst using cURL |
||
| 96 | * @param string $service_endpoint to request |
||
| 97 | */ |
||
| 98 | public function call($service_endpoint) { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Return the HTTP status of the call |
||
| 137 | * @return array or FALSE on failure |
||
| 138 | */ |
||
| 139 | public function getHttpStatus() { |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Return the HTTP status of the call |
||
| 147 | * @return array or FALSE on failure |
||
| 148 | */ |
||
| 149 | public function getResponse() { |
||
| 154 | } |
||
| 155 | |||
| 156 | ?> |
||
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.