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 |
||
| 25 | class Client extends HttpMethodsClient { |
||
|
|
|||
| 26 | |||
| 27 | /** |
||
| 28 | * The default Random.org endpoint. |
||
| 29 | * |
||
| 30 | * @var UriInterface |
||
| 31 | */ |
||
| 32 | protected $endpoint; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The URI Factory. |
||
| 36 | * |
||
| 37 | * @var UriFactory |
||
| 38 | */ |
||
| 39 | protected $uriFactory; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The HTTP plugins array. |
||
| 43 | * |
||
| 44 | * @var Plugin[] |
||
| 45 | */ |
||
| 46 | protected $plugins; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Client constructor. |
||
| 50 | * |
||
| 51 | * @param \Http\Client\HttpClient|NULL $httpClient |
||
| 52 | * @param \Http\Message\UriFactory|NULL $uriFactory |
||
| 53 | */ |
||
| 54 | 15 | public function __construct(HttpClient $httpClient = NULL, UriFactory $uriFactory = NULL) { |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Get the HTTP plugins array. |
||
| 64 | * |
||
| 65 | * @return Plugin[] |
||
| 66 | */ |
||
| 67 | 15 | public function getPlugins() { |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Set the HTTP plugins. |
||
| 73 | * |
||
| 74 | * @param Plugin[] $plugins |
||
| 75 | * An array of HTTP plugin. |
||
| 76 | * |
||
| 77 | * @return $this |
||
| 78 | */ |
||
| 79 | 15 | public function setPlugins(array $plugins = array()) { |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Set the Random.org endpoint. |
||
| 91 | * |
||
| 92 | * @param string $uri |
||
| 93 | */ |
||
| 94 | 15 | public function setEndpoint($uri) { |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Get the Random.org endpoint. |
||
| 100 | * |
||
| 101 | * @return UriInterface |
||
| 102 | */ |
||
| 103 | 12 | public function getEndpoint() { |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Request. |
||
| 109 | * |
||
| 110 | * @param MethodPluginInterface $methodPlugin |
||
| 111 | * |
||
| 112 | * @return null|ResponseInterface |
||
| 113 | */ |
||
| 114 | 12 | public function request(MethodPluginInterface $methodPlugin) { |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Validate the response. |
||
| 126 | * |
||
| 127 | * @param \Psr\Http\Message\ResponseInterface $response |
||
| 128 | * |
||
| 129 | * @return \Exception|ResponseInterface |
||
| 130 | */ |
||
| 131 | 12 | public function validateResponse(ResponseInterface $response) { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * Get the logger. |
||
| 158 | * |
||
| 159 | * @return \Psr\Log\LoggerInterface |
||
| 160 | */ |
||
| 161 | public function getLogger() { |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Set the logger. |
||
| 167 | * |
||
| 168 | * @param \Psr\Log\LoggerInterface $logger |
||
| 169 | */ |
||
| 170 | public function setLogger(LoggerInterface $logger) { |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Returns the UriFactory. |
||
| 176 | * |
||
| 177 | * @return \Http\Message\UriFactory |
||
| 178 | */ |
||
| 179 | 15 | public function getUriFactory() { |
|
| 182 | |||
| 183 | /** |
||
| 184 | * @param \Http\Message\UriFactory $uriFactory |
||
| 185 | */ |
||
| 186 | 15 | public function setUriFactory(UriFactory $uriFactory) { |
|
| 189 | |||
| 190 | } |
||
| 191 |