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 |
||
30 | View Code Duplication | class GuzzleTransport implements TransportInterface |
|
|
|||
31 | { |
||
32 | /** |
||
33 | * @var ClientInterface |
||
34 | */ |
||
35 | private $guzzleClient; |
||
36 | |||
37 | /** |
||
38 | * @param ClientInterface $guzzleClient |
||
39 | */ |
||
40 | 3 | public function __construct(ClientInterface $guzzleClient) |
|
44 | |||
45 | /** |
||
46 | * @param string $httpMethod The http method to use. |
||
47 | * |
||
48 | * @return TransportRequestInterface |
||
49 | * @author Mario Mueller |
||
50 | */ |
||
51 | 1 | public function createRequest($httpMethod) |
|
55 | |||
56 | /** |
||
57 | * @param TransportRequestInterface $request The configured request to send. |
||
58 | * |
||
59 | * @throws \Elastification\Client\Exception\ClientException |
||
60 | * @return \Elastification\Client\Transport\TransportResponseInterface |
||
61 | * @author Mario Mueller |
||
62 | */ |
||
63 | 2 | public function send(TransportRequestInterface $request) |
|
71 | } |
||
72 |
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.