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 |
||
14 | class XmlHandler implements Handler, Collection |
||
15 | { |
||
16 | use XmlConverter; |
||
17 | |||
18 | private $response; |
||
19 | |||
20 | private $validText = []; |
||
21 | |||
22 | private $buildXml; |
||
23 | |||
24 | /* |
||
25 | |-------------------------------------------------------------------------- |
||
26 | | Namespaces XML API BPM |
||
27 | |-------------------------------------------------------------------------- |
||
28 | | Namespaces in BPM API to parse the XML response |
||
29 | | |
||
30 | */ |
||
31 | private $namespaces = [ |
||
32 | 'NamespaceAtom' => 'http://www.w3.org/2005/Atom', |
||
33 | 'NamespaceMetadata' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata', |
||
34 | 'NamespaceDataServices' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', |
||
35 | ]; |
||
36 | |||
37 | /* |
||
38 | |-------------------------------------------------------------------------- |
||
39 | | List Namespaces for post request in BPM |
||
40 | |-------------------------------------------------------------------------- |
||
41 | | Namespaces To specify a file in XML |
||
42 | | |
||
43 | */ |
||
44 | private $listNamespaces = [ |
||
45 | ['xml:base' => 'http://softex-iis:7503/0/ServiceModel/EntityDataService.svc/'], |
||
46 | ['xmlns' => 'http://www.w3.org/2005/Atom'], |
||
47 | ['xmlns:d' => 'http://schemas.microsoft.com/ado/2007/08/dataservices'], |
||
48 | ['xmlns:m' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'], |
||
49 | ['xmlns:georss' => 'http://www.georss.org/georss'], |
||
50 | ['xmlns:gml' => 'http://www.opengis.net/gml'], |
||
51 | ]; |
||
52 | |||
53 | /* |
||
54 | |-------------------------------------------------------------------------- |
||
55 | | Prefix XML document |
||
56 | |-------------------------------------------------------------------------- |
||
57 | | The prefix for insertion into Namespace XML document to be sent to API BPM |
||
58 | | |
||
59 | */ |
||
60 | private $prefixNamespace = 'd'; |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | 2 | public function getAccept() |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 2 | public function getContentType() |
|
77 | |||
78 | /** |
||
79 | * @param $response |
||
80 | * @return XmlHandler|array|mixed |
||
81 | */ |
||
82 | 6 | public function parse($response) |
|
103 | |||
104 | /** |
||
105 | * @param $response |
||
106 | * @return bool |
||
107 | */ |
||
108 | 8 | public function checkIntegrity($response) |
|
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | 1 | public function getData() |
|
124 | |||
125 | /** |
||
126 | * @return array|null |
||
127 | */ |
||
128 | public function getError() |
||
136 | |||
137 | /** |
||
138 | * @return array|null |
||
139 | */ |
||
140 | 2 | public function toArray() |
|
144 | |||
145 | /** |
||
146 | * @return \Illuminate\Support\Collection |
||
147 | */ |
||
148 | 1 | public function toArrayCollect() |
|
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | 1 | public function toJson() |
|
160 | |||
161 | /** |
||
162 | * Return All Collection Bpm |
||
163 | * if not specified all parameters in url |
||
164 | * return list all collection from bpm |
||
165 | * @throws \Exception |
||
166 | */ |
||
167 | 1 | private function workspace() |
|
174 | |||
175 | /** |
||
176 | * Extraction array in response XML , more element one |
||
177 | * @return XmlHandler |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | 3 | View Code Duplication | private function arrayMany() |
188 | /** |
||
189 | * Get one Element |
||
190 | * @return mixed |
||
191 | */ |
||
192 | 1 | View Code Duplication | private function arrayOne() |
199 | |||
200 | |||
201 | /** |
||
202 | * Xml text for request in Bpm Online |
||
203 | * @param $data array |
||
204 | * @return string |
||
205 | */ |
||
206 | 1 | public function create(array $data) |
|
244 | } |
||
245 |
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.