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 | class HttpClient extends ClientSocket implements HttpStream |
||
20 | { |
||
21 | use HttpClientTrait; |
||
22 | |||
23 | /** |
||
24 | * Whether to use https instead of http |
||
25 | * |
||
26 | * @var boolean |
||
27 | */ |
||
28 | private $secure; |
||
29 | |||
30 | /** |
||
31 | * Create a new http client |
||
32 | * |
||
33 | * @param Url $url |
||
34 | * The url for http request |
||
35 | * @param string $proto |
||
36 | * The protocol to use (default = HTTP/1.1) |
||
37 | * @param integer $timeout |
||
38 | * Optional timeout for request (default = 10 seconds) |
||
39 | */ |
||
40 | 12 | View Code Duplication | public function __construct(Url $url, $proto = 'HTTP/1.1', $timeout = 10) |
53 | |||
54 | /** |
||
55 | * |
||
56 | * {@inheritdoc} |
||
57 | * @see \Generics\Streams\HttpStream::request() |
||
58 | */ |
||
59 | 12 | public function request(string $requestType) |
|
67 | } |
||
68 |