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 |
||
9 | class GuzzleHttpClient implements HttpClient |
||
|
|||
10 | { |
||
11 | /** |
||
12 | * @var Client |
||
13 | */ |
||
14 | protected $client; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $responseHeaders; |
||
20 | |||
21 | /** |
||
22 | * @param Client $client |
||
23 | */ |
||
24 | public function __construct(Client $client) |
||
28 | |||
29 | /** |
||
30 | * @param string $uri |
||
31 | * @param array $params |
||
32 | * @param array $headers |
||
33 | * @return array |
||
34 | */ |
||
35 | public function get($uri, array $params = [], array $headers = []) |
||
47 | |||
48 | /** |
||
49 | * @param string $uri |
||
50 | * @param array $body |
||
51 | * @param array $headers |
||
52 | * @return array |
||
53 | */ |
||
54 | View Code Duplication | public function post($uri, array $body = [], array $headers = []) |
|
67 | |||
68 | /** |
||
69 | * @param string $uri |
||
70 | * @param array $body |
||
71 | * @param array $headers |
||
72 | * @return mixed |
||
73 | */ |
||
74 | View Code Duplication | public function put($uri, array $body = [], array $headers = []) |
|
87 | |||
88 | /** |
||
89 | * @param string $uri |
||
90 | * @param array $body |
||
91 | * @param array $headers |
||
92 | * @return mixed |
||
93 | */ |
||
94 | View Code Duplication | public function delete($uri, array $body = [], array $headers = []) |
|
105 | |||
106 | /** |
||
107 | * @param ResponseInterface $response |
||
108 | * @return array|null |
||
109 | */ |
||
110 | protected function parseResponse(ResponseInterface $response) |
||
118 | |||
119 | /** |
||
120 | * @return array |
||
121 | */ |
||
122 | public function getResponseHeaders() |
||
126 | } |
||
127 |