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 |
||
| 22 | class Guzzle6Adapter implements AdapterOptionInterface, CorrelationIdAware, TokenProviderAware |
||
| 23 | { |
||
| 24 | const DEFAULT_CONCURRENCY = 25; |
||
| 25 | /** |
||
| 26 | * @var Client |
||
| 27 | */ |
||
| 28 | protected $client; |
||
| 29 | |||
| 30 | protected $logger; |
||
| 31 | |||
| 32 | private $concurrency; |
||
| 33 | |||
| 34 | 112 | public function __construct(array $options = []) |
|
| 49 | |||
| 50 | 44 | public function setLogger(LoggerInterface $logger, $logLevel = LogLevel::INFO, $formatter = null) |
|
| 58 | |||
| 59 | public function setCorrelationIdProvider(CorrelationIdProvider $provider) |
||
| 68 | |||
| 69 | public function setOAuthTokenProvider(TokenProvider $tokenProvider) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Middleware that logs requests, responses, and errors using a message |
||
| 81 | * formatter. |
||
| 82 | * |
||
| 83 | * @param LoggerInterface $logger Logs messages. |
||
| 84 | * @param MessageFormatter $formatter Formatter used to create message strings. |
||
| 85 | * @param string $logLevel Level at which to log requests. |
||
| 86 | * |
||
| 87 | * @return callable Returns a function that accepts the next handler. |
||
| 88 | */ |
||
| 89 | private static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO) |
||
| 123 | |||
| 124 | 74 | public function addHandler($handler) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @param RequestInterface $request |
||
| 131 | * @param array $clientOptions |
||
| 132 | * @return ResponseInterface |
||
| 133 | * @throws ApiException |
||
| 134 | * @throws \Commercetools\Core\Error\ApiException |
||
| 135 | * @throws \Commercetools\Core\Error\BadGatewayException |
||
| 136 | * @throws \Commercetools\Core\Error\ConcurrentModificationException |
||
| 137 | * @throws \Commercetools\Core\Error\ErrorResponseException |
||
| 138 | * @throws \Commercetools\Core\Error\GatewayTimeoutException |
||
| 139 | * @throws \Commercetools\Core\Error\InternalServerErrorException |
||
| 140 | * @throws \Commercetools\Core\Error\InvalidTokenException |
||
| 141 | * @throws \Commercetools\Core\Error\NotFoundException |
||
| 142 | * @throws \Commercetools\Core\Error\ServiceUnavailableException |
||
| 143 | */ |
||
| 144 | 547 | public function execute(RequestInterface $request, array $clientOptions = []) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * @param RequestInterface[] $requests |
||
| 158 | * @param array $clientOptions |
||
| 159 | * @return ResponseInterface[] |
||
| 160 | */ |
||
| 161 | 421 | public function executeBatch(array $requests, array $clientOptions = []) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * @param $oauthUri |
||
| 188 | * @param $clientId |
||
| 189 | * @param $clientSecret |
||
| 190 | * @param $formParams |
||
| 191 | * @return ResponseInterface |
||
| 192 | */ |
||
| 193 | 45 | public function authenticate($oauthUri, $clientId, $clientSecret, $formParams) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @param RequestInterface $request |
||
| 210 | * @param array $clientOptions |
||
| 211 | * @return AdapterPromiseInterface |
||
| 212 | */ |
||
| 213 | 4 | public function executeAsync(RequestInterface $request, array $clientOptions = []) |
|
| 219 | |||
| 220 | 75 | public static function getAdapterInfo() |
|
| 224 | } |
||
| 225 |