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 |
||
16 | class MultiRequest |
||
17 | { |
||
18 | /** |
||
19 | * @var [Response] |
||
20 | */ |
||
21 | protected static $requestPool = array(); |
||
22 | protected static $multiHandler; |
||
23 | protected $defaultOptions = array(); |
||
24 | private static $instance; |
||
25 | protected static $loggerHandler; |
||
26 | /** |
||
27 | * MultiRequest constructor. |
||
28 | */ |
||
29 | 1 | protected function __construct() |
|
32 | |||
33 | /** |
||
34 | * @return MultiRequest |
||
35 | */ |
||
36 | 2 | public static function create() |
|
44 | |||
45 | /** |
||
46 | * @param array $options |
||
47 | * @return $this |
||
48 | */ |
||
49 | 1 | public function setDefaults(array $options = array()){ |
|
57 | |||
58 | /** |
||
59 | * @param $method |
||
60 | * @param $uri |
||
61 | * @param $payload |
||
62 | * @param array $options |
||
63 | * @return $this |
||
64 | */ |
||
65 | 2 | View Code Duplication | public function add($method, $uri, $payload, array $options = array()) |
75 | |||
76 | /** |
||
77 | * @param array $URLOptions |
||
78 | * example: array(array('url'=>'http://localhost:9999/','timeout'=>1, 'method'=>'POST', 'data'=>'aa=bb&c=d')) |
||
79 | * @return $this |
||
80 | */ |
||
81 | 2 | public function addOptions(array $URLOptions) |
|
93 | |||
94 | /** |
||
95 | * @param Request $request |
||
96 | * @return $this |
||
97 | */ |
||
98 | 2 | public function import(Request $request) |
|
107 | |||
108 | /** |
||
109 | * @return array(Response) |
||
110 | */ |
||
111 | 2 | public function sendAll() |
|
134 | |||
135 | } |
||
136 |
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.