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 |
||
| 19 | final class PluginClient implements HttpClient, HttpAsyncClient |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var \Http\Client\Common\PluginClient |
||
| 23 | */ |
||
| 24 | private $pluginClient; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param HttpClient|HttpAsyncClient $client |
||
| 28 | * @param Plugin[] $plugins |
||
| 29 | * @param array $options { |
||
| 30 | * |
||
| 31 | * @var int $max_restarts Number of times plugins may initiate a restart of the plugin chain. Defaults to 10. |
||
| 32 | * } |
||
| 33 | * |
||
| 34 | * @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient |
||
| 35 | */ |
||
| 36 | 8 | public function __construct($client, array $plugins = [], array $options = []) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | 4 | View Code Duplication | public function sendRequest(RequestInterface $request) |
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | 1 | View Code Duplication | public function sendAsyncRequest(RequestInterface $request) |
| 64 | } |
||
| 65 |
If you suppress an error, we recommend checking for the error condition explicitly: