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 | 16 | 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 | * @return self |
||
67 | */ |
||
68 | 16 | public function setEndpoint($uri) { |
|
73 | |||
74 | /** |
||
75 | * Get the Random.org endpoint. |
||
76 | * |
||
77 | * @return UriInterface |
||
78 | */ |
||
79 | 13 | public function getEndpoint() { |
|
82 | |||
83 | /** |
||
84 | * @param \Http\Message\UriFactory $uriFactory |
||
85 | * |
||
86 | * @return self |
||
87 | */ |
||
88 | 16 | public function setUriFactory(UriFactory $uriFactory) { |
|
93 | |||
94 | /** |
||
95 | * Returns the UriFactory. |
||
96 | * |
||
97 | * @return \Http\Message\UriFactory |
||
98 | */ |
||
99 | 16 | public function getUriFactory() { |
|
102 | |||
103 | /** |
||
104 | * Validate the response. |
||
105 | * |
||
106 | * @param \Psr\Http\Message\ResponseInterface $response |
||
107 | * |
||
108 | * @return \Exception|ResponseInterface |
||
109 | */ |
||
110 | 13 | public function validateResponse(ResponseInterface $response) { |
|
134 | |||
135 | /** |
||
136 | * Request. |
||
137 | * |
||
138 | * @param MethodPluginInterface $methodPlugin |
||
139 | * |
||
140 | * @return null|ResponseInterface |
||
141 | */ |
||
142 | 13 | public function request(MethodPluginInterface $methodPlugin) { |
|
151 | |||
152 | } |
||
153 |