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 Guzzle6Adapter implements AdapterInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var Client |
||
24 | */ |
||
25 | protected $client; |
||
26 | |||
27 | protected $logger; |
||
28 | |||
29 | 102 | public function __construct(array $options = []) |
|
43 | |||
44 | 40 | public function setLogger(LoggerInterface $logger) |
|
49 | |||
50 | 40 | public function addHandler($handler) |
|
54 | |||
55 | /** |
||
56 | * @param RequestInterface $request |
||
57 | * @return ResponseInterface |
||
58 | */ |
||
59 | 441 | public function execute(RequestInterface $request) |
|
70 | |||
71 | /** |
||
72 | * @param RequestInterface[] $requests |
||
73 | * @return ResponseInterface[] |
||
74 | */ |
||
75 | 303 | public function executeBatch(array $requests) |
|
95 | |||
96 | /** |
||
97 | * @param $oauthUri |
||
98 | * @param $clientId |
||
99 | * @param $clientSecret |
||
100 | * @param $formParams |
||
101 | * @return ResponseInterface |
||
102 | */ |
||
103 | 42 | public function authenticate($oauthUri, $clientId, $clientSecret, $formParams) |
|
117 | |||
118 | /** |
||
119 | * @param RequestInterface $request |
||
120 | * @return AdapterPromiseInterface |
||
121 | */ |
||
122 | 4 | public function executeAsync(RequestInterface $request) |
|
128 | } |
||
129 |
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.