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 |
||
23 | class Client extends HttpMethodsClient { |
||
|
|||
24 | |||
25 | /** |
||
26 | * The default Random.org endpoint. |
||
27 | * |
||
28 | * @var UriInterface |
||
29 | */ |
||
30 | protected $endpoint; |
||
31 | |||
32 | /** |
||
33 | * The URI Factory. |
||
34 | * |
||
35 | * @var UriFactory |
||
36 | */ |
||
37 | protected $uriFactory; |
||
38 | |||
39 | /** |
||
40 | * The HTTP plugins array. |
||
41 | * |
||
42 | * @var Plugin[] |
||
43 | */ |
||
44 | protected $plugins; |
||
45 | |||
46 | /** |
||
47 | * Client constructor. |
||
48 | * |
||
49 | * @param \Http\Client\HttpClient|NULL $httpClient |
||
50 | * @param \Http\Message\UriFactory|NULL $uriFactory |
||
51 | * @param Plugin[] $plugins |
||
52 | */ |
||
53 | 15 | public function __construct(HttpClient $httpClient = NULL, UriFactory $uriFactory = NULL, array $plugins = array()) { |
|
60 | |||
61 | /** |
||
62 | * Set the Random.org endpoint. |
||
63 | * |
||
64 | * @param string $uri |
||
65 | */ |
||
66 | 15 | public function setEndpoint($uri) { |
|
69 | |||
70 | /** |
||
71 | * Get the Random.org endpoint. |
||
72 | * |
||
73 | * @return UriInterface |
||
74 | */ |
||
75 | 12 | public function getEndpoint() { |
|
78 | |||
79 | /** |
||
80 | * Request. |
||
81 | * |
||
82 | * @param MethodPluginInterface $methodPlugin |
||
83 | * |
||
84 | * @return null|ResponseInterface |
||
85 | */ |
||
86 | 12 | public function request(MethodPluginInterface $methodPlugin) { |
|
95 | |||
96 | /** |
||
97 | * Validate the response. |
||
98 | * |
||
99 | * @param \Psr\Http\Message\ResponseInterface $response |
||
100 | * |
||
101 | * @return \Exception|ResponseInterface |
||
102 | */ |
||
103 | 12 | public function validateResponse(ResponseInterface $response) { |
|
127 | |||
128 | /** |
||
129 | * Returns the UriFactory. |
||
130 | * |
||
131 | * @return \Http\Message\UriFactory |
||
132 | */ |
||
133 | 15 | public function getUriFactory() { |
|
136 | |||
137 | /** |
||
138 | * @param \Http\Message\UriFactory $uriFactory |
||
139 | */ |
||
140 | 15 | public function setUriFactory(UriFactory $uriFactory) { |
|
143 | |||
144 | } |
||
145 |