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 |
||
12 | class CopyRequest extends BaseRequest |
||
13 | { |
||
14 | /** @var string */ |
||
15 | private $destination; |
||
16 | |||
17 | /** @var resource<stream<plainfile>> */ |
||
18 | private $fp; |
||
19 | |||
20 | private $success = false; |
||
21 | |||
22 | protected static $defaultCurlOptions = array( |
||
23 | CURLOPT_HTTPGET => true, |
||
24 | CURLOPT_FOLLOWLOCATION => true, |
||
25 | CURLOPT_MAXREDIRS => 20, |
||
26 | CURLOPT_ENCODING => '', |
||
27 | ); |
||
28 | |||
29 | /** |
||
30 | * @param string $url |
||
31 | * @param string $destination |
||
32 | * @param bool $useRedirector |
||
33 | * @param IO\IOInterface $io |
||
34 | * @param Config $config |
||
35 | */ |
||
36 | 6 | View Code Duplication | public function __construct($url, $destination, $useRedirector, IO\IOInterface $io, Config $config) |
48 | |||
49 | 5 | public function __destruct() |
|
61 | |||
62 | 1 | public function makeSuccess() |
|
66 | |||
67 | /** |
||
68 | * @return array |
||
69 | */ |
||
70 | 2 | public function getCurlOptions() |
|
76 | |||
77 | /** |
||
78 | * @param string |
||
79 | */ |
||
80 | 6 | public function setDestination($destination) |
|
98 | |||
99 | 5 | private function createDir($fileName) |
|
110 | } |
||
111 |
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.