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 |
||
16 | class JCRequest implements iJCRequest |
||
17 | { |
||
18 | 7 | public static function request($method, $url, $guzzleOptions) |
|
22 | |||
23 | 1 | public static function get($url, $params = null, $headers = [], $options = []) |
|
29 | |||
30 | 2 | View Code Duplication | public static function post($url, $params = null, $headers = [], $options = []) |
37 | |||
38 | 1 | View Code Duplication | public static function put($url, $params = null, $headers = [], $options = []) |
45 | |||
46 | 1 | View Code Duplication | public static function patch($url, $params = null, $headers = [], $options = []) |
53 | |||
54 | 1 | View Code Duplication | public static function delete($url, $params = null, $headers = [], $options = []) |
61 | |||
62 | 2 | public static function head($url, $headers = [], $options = []) |
|
68 | |||
69 | /** |
||
70 | * Manipulate the url & params for GET request |
||
71 | * |
||
72 | * @param string $url |
||
73 | * @param array $params |
||
74 | * @return string |
||
75 | */ |
||
76 | 1 | protected static function manipulateUrl($url, $params = []) |
|
84 | |||
85 | /** |
||
86 | * @param array $guzzleOptions |
||
87 | * @return array |
||
88 | */ |
||
89 | 7 | protected static function manipulateParams($guzzleOptions) |
|
109 | } |
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.