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 Guzzle5Adapter implements AdapterInterface, CorrelationIdAware |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var Client |
||
| 26 | */ |
||
| 27 | protected $client; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var LoggerInterface |
||
| 31 | */ |
||
| 32 | protected $logger; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param array $options |
||
| 36 | */ |
||
| 37 | public function __construct(array $options = []) |
||
| 59 | |||
| 60 | public function setLogger(LoggerInterface $logger, $logLevel = LogLevel::INFO, $formatter = null) |
||
| 67 | |||
| 68 | public function addHandler($handler) |
||
| 72 | |||
| 73 | public function setCorrelationIdProvider(CorrelationIdProvider $provider) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @internal |
||
| 80 | * @return \GuzzleHttp\Event\Emitter|\GuzzleHttp\Event\EmitterInterface |
||
| 81 | */ |
||
| 82 | public function getEmitter() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param RequestInterface $request |
||
| 89 | * @return ResponseInterface |
||
| 90 | * @throws \Commercetools\Core\Error\ApiException |
||
| 91 | * @throws \Commercetools\Core\Error\BadGatewayException |
||
| 92 | * @throws \Commercetools\Core\Error\ConcurrentModificationException |
||
| 93 | * @throws \Commercetools\Core\Error\ErrorResponseException |
||
| 94 | * @throws \Commercetools\Core\Error\GatewayTimeoutException |
||
| 95 | * @throws \Commercetools\Core\Error\InternalServerErrorException |
||
| 96 | * @throws \Commercetools\Core\Error\InvalidTokenException |
||
| 97 | * @throws \Commercetools\Core\Error\NotFoundException |
||
| 98 | * @throws \Commercetools\Core\Error\ServiceUnavailableException |
||
| 99 | */ |
||
| 100 | public function execute(RequestInterface $request) |
||
| 118 | |||
| 119 | protected function packResponse(\GuzzleHttp\Message\ResponseInterface $response = null) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param RequestInterface[] $requests |
||
| 133 | * @return \Psr\Http\Message\ResponseInterface[] |
||
| 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 | public function executeBatch(array $requests) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return array |
||
| 168 | */ |
||
| 169 | protected function getBatchHttpRequests(array $requests) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param $oauthUri |
||
| 190 | * @param $clientId |
||
| 191 | * @param $clientSecret |
||
| 192 | * @param $formParams |
||
| 193 | * @return ResponseInterface |
||
| 194 | */ |
||
| 195 | public function authenticate($oauthUri, $clientId, $clientSecret, $formParams) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param RequestInterface $request |
||
| 220 | * @return AdapterPromiseInterface |
||
| 221 | */ |
||
| 222 | public function executeAsync(RequestInterface $request) |
||
| 247 | |||
| 248 | public static function getAdapterInfo() |
||
| 252 | } |
||
| 253 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.