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 |
||
| 20 | class GuzzleAdapter implements AdapterInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Guzzle client |
||
| 24 | * |
||
| 25 | * @var Client |
||
| 26 | */ |
||
| 27 | private $client; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * curl options |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $options; |
||
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * GuzzleAdapter constructor. |
||
| 39 | * |
||
| 40 | * @link https://gist.github.com/jseidl/3218673 |
||
| 41 | * |
||
| 42 | * @param Client $client guzzle client |
||
| 43 | * @param array $curlOptions List of curl options to be recognized for a request. |
||
| 44 | */ |
||
| 45 | public function __construct(Client $client, array $curlOptions) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @inheritDoc |
||
| 53 | * |
||
| 54 | * @param RequestInterface $request request |
||
| 55 | * |
||
| 56 | * @return ResponseInterface |
||
| 57 | */ |
||
| 58 | public function send(RequestInterface $request) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param string $method |
||
| 65 | * @param string $uri |
||
| 66 | * @param array $options |
||
| 67 | * |
||
| 68 | * @return mixed|ResponseInterface |
||
|
|
|||
| 69 | */ |
||
| 70 | public function request($method, $uri = '', array $options = []) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | private function applyOptions($options) |
||
| 91 | |||
| 92 | |||
| 93 | } |
||
| 94 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.