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, $options) |
|
34 | |||
35 | /** |
||
36 | * @param $url |
||
37 | * @param array $headers |
||
38 | * @param array $params |
||
39 | * @param array $options |
||
40 | * @return JCResponse |
||
41 | */ |
||
42 | 1 | public static function get($url, $params = null, $headers = [], $options = []) |
|
48 | |||
49 | 2 | View Code Duplication | public static function post($url, $params = null, $headers = [], $options = []) |
56 | |||
57 | 1 | View Code Duplication | public static function put($url, $params = null, $headers = [], $options = []) |
64 | |||
65 | 1 | View Code Duplication | public static function patch($url, $params = null, $headers = [], $options = []) |
72 | |||
73 | 1 | View Code Duplication | public static function delete($url, $params = null, $headers = [], $options = []) |
80 | |||
81 | 1 | public static function head($url, $params = null, $headers = [], $options = []) |
|
87 | |||
88 | /** |
||
89 | * @param string $url |
||
90 | * @param array $params |
||
91 | * @return string |
||
92 | */ |
||
93 | 1 | protected static function manipulateUrl($url, $params = []) |
|
101 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.