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 | 6 | public static function request($method, $url, $options) |
|
31 | |||
32 | /** |
||
33 | * @param $url |
||
34 | * @param array $headers |
||
35 | * @param array $params |
||
36 | * @param array $options |
||
37 | * @return JCResponse |
||
38 | */ |
||
39 | 1 | public static function get($url, $params = [], $headers = [], $options = []) |
|
45 | |||
46 | 1 | View Code Duplication | public static function post($url, $params = [], $headers = [], $options = []) |
53 | |||
54 | 1 | View Code Duplication | public static function put($url, $params = [], $headers = [], $options = []) |
61 | |||
62 | 2 | View Code Duplication | public static function patch($url, $params = [], $headers = [], $options = []) |
69 | |||
70 | 1 | public static function delete($url, $params = [], $headers = [], $options = []) |
|
77 | |||
78 | 1 | public static function head($url, $params = [], $headers = [], $options = []) |
|
84 | |||
85 | /** |
||
86 | * @param string $url |
||
87 | * @param array $params |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | protected static function manipulateUrl($url, $params = []) |
|
98 | } |
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.