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 |
||
24 | class StrictClient implements HttpClient, HttpAsyncClient |
||
25 | { |
||
26 | use HttpAsyncClientEmulator; |
||
27 | use VersionBridgeClient; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $configuredSequence = []; |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | * |
||
37 | * @throws UnexpectedRequestException |
||
38 | */ |
||
39 | public function doSendRequest(RequestInterface $request) |
||
65 | |||
66 | /** |
||
67 | * Adds an exception to be thrown or response to be returned for the next request |
||
68 | * expected to be sent in a sequence of requests. |
||
69 | * |
||
70 | * For more complex logic, pass a callable as $result. The method is given |
||
71 | * the request and MUST either return a ResponseInterface or throw an |
||
72 | * exception that implements the PSR-18 / HTTPlug exception interface. |
||
73 | * |
||
74 | * @param ResponseInterface|Exception|ClientExceptionInterface|callable $result |
||
75 | */ |
||
76 | View Code Duplication | public function on(RequestMatcher $requestMatcher, $result) |
|
106 | |||
107 | /** |
||
108 | * Returns true when the configured sequence of requests and responses (or exceptions) |
||
109 | * has been completed, i.e., the queue of configured results has been exhausted. |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function hasCompletedSequence() |
||
117 | } |
||
118 |
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.