Total Complexity | 21 |
Total Lines | 394 |
Duplicated Lines | 43.91 % |
Changes | 0 |
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 |
||
43 | class LabelService |
||
44 | { |
||
45 | use Processor; |
||
46 | |||
47 | /** |
||
48 | * @var SecurityServiceInterface |
||
49 | */ |
||
50 | protected $securityService; |
||
51 | /** |
||
52 | * @var GeneralServiceType |
||
53 | */ |
||
54 | private $generalServiceType; |
||
55 | |||
56 | /** |
||
57 | * DocumentService constructor. |
||
58 | * |
||
59 | * @param GeneralServiceType $generalServiceType |
||
60 | * @param SecurityServiceInterface $securityService |
||
61 | */ |
||
62 | public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService) |
||
63 | { |
||
64 | $this->securityService = $securityService; |
||
65 | $this->generalServiceType = $generalServiceType; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param array $orderReferences |
||
70 | * @param null $printer |
||
71 | * @param null $includeMetaData |
||
72 | * @param null $batch |
||
73 | * @param null $targetWebShop |
||
74 | * |
||
75 | * @return GeneratePdfLabelsResponse |
||
76 | */ |
||
77 | View Code Duplication | public function generatePdfLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
78 | { |
||
79 | $orders = []; |
||
80 | |||
81 | foreach ($orderReferences as $orderReference) { |
||
82 | $orders[] = new OrderType( |
||
83 | $this->securityService->getHash($orderReference), |
||
84 | $targetWebShop, |
||
85 | $orderReference, |
||
86 | null, |
||
87 | $batch |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | $request = new GeneratePdfLabelsRequest( |
||
92 | $this->generalServiceType->getWebShopId(), |
||
93 | $printer, |
||
94 | $orders, |
||
95 | $includeMetaData |
||
96 | ); |
||
97 | |||
98 | $response = $this->generalServiceType->generatePdfLabels($request); |
||
99 | |||
100 | return $this->processResponse($response, $this->generalServiceType); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param $orderReference |
||
105 | * @param null $printer |
||
106 | * @param null $includeMetaData |
||
107 | * @param null $batch |
||
108 | * @param null $targetWebShop |
||
109 | * |
||
110 | * @return GenerateExtraPdfLabelResponse |
||
111 | */ |
||
112 | public function generateExtraPdfLabel($orderReference, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
||
113 | { |
||
114 | $request = new GenerateExtraPdfLabelRequest( |
||
115 | $this->securityService->getHash($orderReference), |
||
116 | $this->generalServiceType->getWebShopId(), |
||
117 | $targetWebShop, |
||
118 | $orderReference, |
||
119 | $printer, |
||
120 | $batch, |
||
121 | $includeMetaData |
||
122 | ); |
||
123 | |||
124 | $response = $this->generalServiceType->generateExtraPdfLabel($request); |
||
125 | |||
126 | return $this->processResponse($response, $this->generalServiceType); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param array $orderReferences |
||
131 | * @param $shippingOption |
||
132 | * @param null $printer |
||
133 | * @param null $targetWebShop |
||
134 | * |
||
135 | * @return GeneratePdfReturnLabelsResponse |
||
136 | */ |
||
137 | public function generatePdfReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null) |
||
138 | { |
||
139 | $orders = []; |
||
140 | |||
141 | foreach ($orderReferences as $orderReference) { |
||
142 | $orders[] = new ReturnLabelsOrderType( |
||
143 | $this->securityService->getHash($orderReference), |
||
144 | $targetWebShop, |
||
145 | $orderReference, |
||
146 | null, |
||
147 | $shippingOption |
||
148 | ); |
||
149 | } |
||
150 | |||
151 | $request = new GeneratePdfReturnLabelsRequest( |
||
152 | $printer |
||
153 | ); |
||
154 | $request->setWebshop($this->generalServiceType->getWebShopId()); |
||
155 | $request->setOrder($orders); |
||
156 | |||
157 | $response = $this->generalServiceType->generatePdfReturnLabels($request); |
||
158 | |||
159 | return $this->processResponse($response, $this->generalServiceType); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @param $orderReference |
||
164 | * @param $shippingOption |
||
165 | * @param null $printer |
||
166 | * @param null $targetWebShop |
||
167 | * |
||
168 | * @return GenerateExtraPdfReturnLabelResponse |
||
169 | */ |
||
170 | View Code Duplication | public function generateExtraPdfReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null) |
|
171 | { |
||
172 | $request = new GenerateExtraPdfReturnLabelRequest($printer); |
||
173 | $request->setShippingOption($shippingOption) |
||
174 | ->setWebshop($this->generalServiceType->getWebShopId()) |
||
175 | ->setHash($this->securityService->getHash($orderReference)) |
||
176 | ->setTargetWebshop($targetWebShop) |
||
177 | ->setOrderReference($orderReference) |
||
178 | ->setShippingOption($shippingOption); |
||
179 | |||
180 | $response = $this->generalServiceType->generateExtraPdfReturnLabel($request); |
||
181 | |||
182 | return $this->processResponse($response, $this->generalServiceType); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param array $orderReferences |
||
187 | * @param null $includeMetaData |
||
188 | * @param null $batch |
||
189 | * @param null $targetWebShop |
||
190 | * |
||
191 | * @return GenerateImageLabelsResponse |
||
192 | */ |
||
193 | View Code Duplication | public function generateImageLabels(array $orderReferences, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
194 | { |
||
195 | $orders = []; |
||
196 | |||
197 | foreach ($orderReferences as $orderReference) { |
||
198 | $orders[] = new OrderType( |
||
199 | $this->securityService->getHash($orderReference), |
||
200 | $targetWebShop, |
||
201 | $orderReference, |
||
202 | null, |
||
203 | $batch |
||
204 | ); |
||
205 | } |
||
206 | |||
207 | $request = new GenerateImageLabelsRequest( |
||
208 | $this->generalServiceType->getWebShopId(), |
||
209 | $orders, |
||
210 | $includeMetaData |
||
211 | ); |
||
212 | |||
213 | $response = $this->generalServiceType->generateImageLabels($request); |
||
214 | |||
215 | return $this->processResponse($response, $this->generalServiceType); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @param array $orderReferences |
||
220 | * @param $shippingOption |
||
221 | * @param null $printer |
||
222 | * @param null $targetWebShop |
||
223 | * |
||
224 | * @return GenerateImageReturnLabelsResponse |
||
225 | */ |
||
226 | public function generateImageReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null) |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param $orderReference |
||
253 | * @param $shippingOption |
||
254 | * @param null $printer |
||
255 | * @param null $targetWebShop |
||
256 | * |
||
257 | * @return GenerateExtraImageReturnLabelResponse |
||
258 | */ |
||
259 | View Code Duplication | public function generateExtraImageReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null) |
|
260 | { |
||
261 | $request = new GenerateExtraPdfReturnLabelRequest($printer); |
||
262 | $request->setShippingOption($shippingOption) |
||
263 | ->setWebshop($this->generalServiceType->getWebShopId()) |
||
264 | ->setHash($this->securityService->getHash($orderReference)) |
||
265 | ->setTargetWebshop($targetWebShop) |
||
266 | ->setOrderReference($orderReference) |
||
267 | ->setShippingOption($shippingOption); |
||
268 | |||
269 | $response = $this->generalServiceType->generateExtraImageReturnLabel($request); |
||
270 | |||
271 | return $this->processResponse($response, $this->generalServiceType); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @param $orderReference |
||
276 | * @param null $includeMetaData |
||
277 | * @param null $batch |
||
278 | * @param null $targetWebShop |
||
279 | * |
||
280 | * @return GenerateExtraImageLabelResponse |
||
281 | */ |
||
282 | public function generateExtraImageLabel($orderReference, $includeMetaData = null, $batch = null, $targetWebShop = null) |
||
283 | { |
||
284 | $request = new GenerateExtraImageLabelRequest( |
||
285 | $this->securityService->getHash($orderReference), |
||
286 | $this->generalServiceType->getWebShopId(), |
||
287 | $targetWebShop, |
||
288 | $orderReference, |
||
289 | $batch, |
||
290 | $includeMetaData |
||
291 | ); |
||
292 | |||
293 | $response = $this->generalServiceType->generateExtraImageLabel($request); |
||
294 | |||
295 | return $this->processResponse($response, $this->generalServiceType); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @param array $orderReferences |
||
300 | * @param null $printer |
||
301 | * @param null $includeMetaData |
||
302 | * @param null $batch |
||
303 | * @param null $targetWebShop |
||
304 | * |
||
305 | * @return GenerateZplLabelsResponse |
||
306 | */ |
||
307 | View Code Duplication | public function generateZplLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
308 | { |
||
309 | $orders = []; |
||
310 | |||
311 | foreach ($orderReferences as $orderReference) { |
||
312 | $orders[] = new OrderType( |
||
313 | $this->securityService->getHash($orderReference), |
||
314 | $targetWebShop, |
||
315 | $orderReference, |
||
316 | null, |
||
317 | $batch |
||
318 | ); |
||
319 | } |
||
320 | |||
321 | $request = new GenerateZplLabelsRequest( |
||
322 | $this->generalServiceType->getWebShopId(), |
||
323 | $printer, |
||
324 | $orders, |
||
325 | $includeMetaData |
||
326 | ); |
||
327 | |||
328 | $response = $this->generalServiceType->generateZplLabels($request); |
||
329 | |||
330 | return $this->processResponse($response, $this->generalServiceType); |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * @param $orderReference |
||
335 | * @param $barCode |
||
336 | * @param null $printer |
||
337 | * @param null $includeMetaData |
||
338 | * @param null $targetWebShop |
||
339 | * |
||
340 | * @return GetExistingPdfLabelResponse |
||
341 | */ |
||
342 | View Code Duplication | public function getExistingPdfLabel($orderReference, $barCode, $printer = null, $includeMetaData = null, $targetWebShop = null) |
|
343 | { |
||
344 | $request = new GetExistingPdfLabelRequest($printer); |
||
345 | $request->setHash($this->securityService->getHash($orderReference)) |
||
346 | ->setWebshop($this->generalServiceType->getWebShopId()) |
||
347 | ->setOrderReference($orderReference) |
||
348 | ->setBarcode($barCode) |
||
349 | ->setIncludeMetaData($includeMetaData) |
||
350 | ->setTargetWebshop($targetWebShop); |
||
351 | |||
352 | $response = $this->generalServiceType->getExistingPdfLabel($request); |
||
353 | |||
354 | return $this->processResponse($response, $this->generalServiceType); |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * @param array $barCodes [$orderReference => $barcode] |
||
359 | * @param null $printer |
||
360 | * @param null $includeMetaData |
||
361 | * |
||
362 | * @return GetExistingPdfLabelsResponse |
||
363 | */ |
||
364 | View Code Duplication | public function getExistingPdfLabels(array $barCodes, $printer = null, $includeMetaData = null) |
|
385 | } |
||
386 | |||
387 | /** |
||
388 | * @param $orderReference |
||
389 | * @param $barCode |
||
390 | * @param null $includeMetaData |
||
391 | * @param null $targetWebShop |
||
392 | * |
||
393 | * @return GetExistingImageLabelResponse |
||
394 | */ |
||
395 | View Code Duplication | public function getExistingImageLabel($orderReference, $barCode, $includeMetaData = null, $targetWebShop = null) |
|
396 | { |
||
397 | $request = new GetExistingPdfLabelRequest(); |
||
398 | $request->setHash($this->securityService->getHash($orderReference)) |
||
399 | ->setWebshop($this->generalServiceType->getWebShopId()) |
||
400 | ->setOrderReference($orderReference) |
||
401 | ->setBarcode($barCode) |
||
402 | ->setIncludeMetaData($includeMetaData) |
||
403 | ->setTargetWebshop($targetWebShop); |
||
404 | |||
405 | $response = $this->generalServiceType->getExistingImageLabel($request); |
||
406 | |||
407 | return $this->processResponse($response, $this->generalServiceType); |
||
408 | } |
||
409 | |||
410 | /** |
||
411 | * @param array $barCodes [$orderReference => $barcode] |
||
412 | * @param null $includeMetaData |
||
413 | * |
||
414 | * @return GetExistingImageLabelsResponse |
||
415 | */ |
||
416 | View Code Duplication | public function getExistingImageLabels(array $barCodes, $includeMetaData = null) |
|
437 | } |
||
438 | } |
||
439 |
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.