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 |
||
11 | final class CurlWebLoader implements LoaderInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $prefix; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $curlOptions; |
||
22 | |||
23 | /** |
||
24 | * @var DecoderManager |
||
25 | */ |
||
26 | private $decoderManager; |
||
27 | |||
28 | /** |
||
29 | * @param string $prefix |
||
30 | * @param array $curlOptions |
||
31 | * @param DecoderInterface|DecoderManager $decoderManager |
||
32 | 66 | */ |
|
33 | View Code Duplication | public function __construct($prefix, array $curlOptions = null, $decoderManager = null) |
|
44 | 14 | ||
45 | 14 | /** |
|
46 | 14 | * {@inheritdoc} |
|
47 | 14 | */ |
|
48 | 14 | public function load($path) |
|
63 | |||
64 | 14 | /** |
|
65 | 14 | * @param resource $ch |
|
66 | * |
||
67 | 14 | * @return array |
|
68 | */ |
||
69 | private function getResponseBodyAndStatusCode($ch) |
||
79 | 33 | ||
80 | /** |
||
81 | * @return array |
||
82 | */ |
||
83 | private function getDefaultCurlOptions() |
||
91 | |||
92 | 64 | /** |
|
93 | 64 | * @param array|null $curlOptions |
|
94 | */ |
||
95 | private function setCurlOptions($curlOptions) |
||
104 | |||
105 | /** |
||
106 | * Parse http headers returned by $http_response_header |
||
107 | * @link https://stackoverflow.com/questions/10589889/returning-header-as-array-using-curl |
||
108 | * |
||
109 | * @param array $headers |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | public static function parseResponseHeader($header_text) |
||
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.