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 |
||
24 | class Guzzle5Adapter implements AdapterOptionInterface, CorrelationIdAware, TokenProviderAware |
||
25 | { |
||
26 | const DEFAULT_CONCURRENCY = 25; |
||
27 | |||
28 | /** |
||
29 | * @var Client |
||
30 | */ |
||
31 | protected $client; |
||
32 | |||
33 | /** |
||
34 | * @var LoggerInterface |
||
35 | */ |
||
36 | protected $logger; |
||
37 | |||
38 | private $concurrency; |
||
39 | |||
40 | /** |
||
41 | * @param array $options |
||
42 | */ |
||
43 | public function __construct(array $options = []) |
||
71 | |||
72 | public function setLogger(LoggerInterface $logger, $logLevel = LogLevel::INFO, $formatter = null) |
||
79 | |||
80 | public function addHandler($handler) |
||
84 | |||
85 | public function setCorrelationIdProvider(CorrelationIdProvider $provider) |
||
89 | |||
90 | public function setOAuthTokenProvider(TokenProvider $tokenProvider) |
||
94 | |||
95 | /** |
||
96 | * @internal |
||
97 | * @return \GuzzleHttp\Event\Emitter|\GuzzleHttp\Event\EmitterInterface |
||
98 | */ |
||
99 | public function getEmitter() |
||
103 | |||
104 | /** |
||
105 | * @param RequestInterface $request |
||
106 | * @param array $clientOptions |
||
107 | * @return ResponseInterface |
||
108 | * @throws \Commercetools\Core\Error\ApiException |
||
109 | * @throws \Commercetools\Core\Error\BadGatewayException |
||
110 | * @throws \Commercetools\Core\Error\ConcurrentModificationException |
||
111 | * @throws \Commercetools\Core\Error\ErrorResponseException |
||
112 | * @throws \Commercetools\Core\Error\GatewayTimeoutException |
||
113 | * @throws \Commercetools\Core\Error\InternalServerErrorException |
||
114 | * @throws \Commercetools\Core\Error\InvalidTokenException |
||
115 | * @throws \Commercetools\Core\Error\NotFoundException |
||
116 | * @throws \Commercetools\Core\Error\ServiceUnavailableException |
||
117 | */ |
||
118 | public function execute(RequestInterface $request, array $clientOptions = []) |
||
139 | |||
140 | protected function packResponse(\GuzzleHttp\Message\ResponseInterface $response = null) |
||
151 | |||
152 | /** |
||
153 | * @param RequestInterface[] $requests |
||
154 | * @param array $clientOptions |
||
155 | * @return \Psr\Http\Message\ResponseInterface[] |
||
156 | * @throws \Commercetools\Core\Error\ApiException |
||
157 | * @throws \Commercetools\Core\Error\BadGatewayException |
||
158 | * @throws \Commercetools\Core\Error\ConcurrentModificationException |
||
159 | * @throws \Commercetools\Core\Error\ErrorResponseException |
||
160 | * @throws \Commercetools\Core\Error\GatewayTimeoutException |
||
161 | * @throws \Commercetools\Core\Error\InternalServerErrorException |
||
162 | * @throws \Commercetools\Core\Error\InvalidTokenException |
||
163 | * @throws \Commercetools\Core\Error\NotFoundException |
||
164 | * @throws \Commercetools\Core\Error\ServiceUnavailableException |
||
165 | */ |
||
166 | public function executeBatch(array $requests, array $clientOptions = []) |
||
188 | |||
189 | /** |
||
190 | * @param array $requests |
||
191 | * @param array $clientOptions |
||
192 | * @return array |
||
193 | */ |
||
194 | protected function getBatchHttpRequests(array $requests, array $clientOptions = []) |
||
217 | |||
218 | /** |
||
219 | * @param $oauthUri |
||
220 | * @param $clientId |
||
221 | * @param $clientSecret |
||
222 | * @param $formParams |
||
223 | * @return ResponseInterface |
||
224 | */ |
||
225 | public function authenticate($oauthUri, $clientId, $clientSecret, $formParams) |
||
247 | |||
248 | /** |
||
249 | * @param RequestInterface $request |
||
250 | * @param array $clientOptions |
||
251 | * @return AdapterPromiseInterface |
||
252 | */ |
||
253 | public function executeAsync(RequestInterface $request, array $clientOptions = []) |
||
281 | |||
282 | public static function getAdapterInfo() |
||
286 | } |
||
287 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.