Total Complexity | 21 |
Total Lines | 402 |
Duplicated Lines | 50.75 % |
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 GenerateServiceType |
||
|
|||
53 | */ |
||
54 | protected $generateServiceType; |
||
55 | /** |
||
56 | * @var GetServiceType |
||
57 | */ |
||
58 | protected $getServiceType; |
||
59 | /** |
||
60 | * @var GeneralServiceType |
||
61 | */ |
||
62 | private $generalServiceType; |
||
63 | |||
64 | /** |
||
65 | * DocumentService constructor. |
||
66 | * |
||
67 | * @param GeneralServiceType $generalServiceType |
||
68 | * @param SecurityServiceInterface $securityService |
||
69 | */ |
||
70 | public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService) |
||
71 | { |
||
72 | $this->securityService = $securityService; |
||
73 | $this->generalServiceType = $generalServiceType; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param array $orderReferences |
||
78 | * @param null $printer |
||
79 | * @param null $includeMetaData |
||
80 | * @param null $batch |
||
81 | * @param null $targetWebShop |
||
82 | * |
||
83 | * @return GeneratePdfLabelsResponse |
||
84 | */ |
||
85 | View Code Duplication | public function generatePdfLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
86 | { |
||
87 | $orders = []; |
||
88 | |||
89 | foreach ($orderReferences as $orderReference) { |
||
90 | $orders[] = new OrderType( |
||
91 | $this->securityService->getHash($orderReference), |
||
92 | $targetWebShop, |
||
93 | $orderReference, |
||
94 | null, |
||
95 | $batch |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | $request = new GeneratePdfLabelsRequest( |
||
100 | $this->generateServiceType->getWebShopId(), |
||
101 | $printer, |
||
102 | $orders, |
||
103 | $includeMetaData |
||
104 | ); |
||
105 | |||
106 | $response = $this->generateServiceType->generatePdfLabels($request); |
||
107 | |||
108 | return $this->processResponse($response, $this->generateServiceType); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @param $orderReference |
||
113 | * @param null $printer |
||
114 | * @param null $includeMetaData |
||
115 | * @param null $batch |
||
116 | * @param null $targetWebShop |
||
117 | * |
||
118 | * @return GenerateExtraPdfLabelResponse |
||
119 | */ |
||
120 | View Code Duplication | public function generateExtraPdfLabel($orderReference, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
121 | { |
||
122 | $request = new GenerateExtraPdfLabelRequest( |
||
123 | $this->securityService->getHash($orderReference), |
||
124 | $this->generateServiceType->getWebShopId(), |
||
125 | $targetWebShop, |
||
126 | $orderReference, |
||
127 | $printer, |
||
128 | $batch, |
||
129 | $includeMetaData |
||
130 | ); |
||
131 | |||
132 | $response = $this->generateServiceType->generateExtraPdfLabel($request); |
||
133 | |||
134 | return $this->processResponse($response, $this->generateServiceType); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param array $orderReferences |
||
139 | * @param $shippingOption |
||
140 | * @param null $printer |
||
141 | * @param null $targetWebShop |
||
142 | * |
||
143 | * @return GeneratePdfReturnLabelsResponse |
||
144 | */ |
||
145 | public function generatePdfReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null) |
||
146 | { |
||
147 | $orders = []; |
||
148 | |||
149 | foreach ($orderReferences as $orderReference) { |
||
150 | $orders[] = new ReturnLabelsOrderType( |
||
151 | $this->securityService->getHash($orderReference), |
||
152 | $targetWebShop, |
||
153 | $orderReference, |
||
154 | null, |
||
155 | $shippingOption |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | $request = new GeneratePdfReturnLabelsRequest( |
||
160 | $printer |
||
161 | ); |
||
162 | $request->setWebshop($this->generateServiceType->getWebShopId()); |
||
163 | $request->setOrder($orders); |
||
164 | |||
165 | $response = $this->generateServiceType->generatePdfReturnLabels($request); |
||
166 | |||
167 | return $this->processResponse($response, $this->generateServiceType); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @param $orderReference |
||
172 | * @param $shippingOption |
||
173 | * @param null $printer |
||
174 | * @param null $targetWebShop |
||
175 | * |
||
176 | * @return GenerateExtraPdfReturnLabelResponse |
||
177 | */ |
||
178 | View Code Duplication | public function generateExtraPdfReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null) |
|
179 | { |
||
180 | $request = new GenerateExtraPdfReturnLabelRequest($printer); |
||
181 | $request->setShippingOption($shippingOption) |
||
182 | ->setWebshop($this->generateServiceType->getWebShopId()) |
||
183 | ->setHash($this->securityService->getHash($orderReference)) |
||
184 | ->setTargetWebshop($targetWebShop) |
||
185 | ->setOrderReference($orderReference) |
||
186 | ->setShippingOption($shippingOption); |
||
187 | |||
188 | $response = $this->generateServiceType->generateExtraPdfReturnLabel($request); |
||
189 | |||
190 | return $this->processResponse($response, $this->generateServiceType); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @param array $orderReferences |
||
195 | * @param null $includeMetaData |
||
196 | * @param null $batch |
||
197 | * @param null $targetWebShop |
||
198 | * |
||
199 | * @return GenerateImageLabelsResponse |
||
200 | */ |
||
201 | View Code Duplication | public function generateImageLabels(array $orderReferences, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
202 | { |
||
203 | $orders = []; |
||
204 | |||
205 | foreach ($orderReferences as $orderReference) { |
||
206 | $orders[] = new OrderType( |
||
207 | $this->securityService->getHash($orderReference), |
||
208 | $targetWebShop, |
||
209 | $orderReference, |
||
210 | null, |
||
211 | $batch |
||
212 | ); |
||
213 | } |
||
214 | |||
215 | $request = new GenerateImageLabelsRequest( |
||
216 | $this->generateServiceType->getWebShopId(), |
||
217 | $orders, |
||
218 | $includeMetaData |
||
219 | ); |
||
220 | |||
221 | $response = $this->generateServiceType->generateImageLabels($request); |
||
222 | |||
223 | return $this->processResponse($response, $this->generateServiceType); |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * @param array $orderReferences |
||
228 | * @param $shippingOption |
||
229 | * @param null $printer |
||
230 | * @param null $targetWebShop |
||
231 | * |
||
232 | * @return GenerateImageReturnLabelsResponse |
||
233 | */ |
||
234 | public function generateImageReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null) |
||
235 | { |
||
236 | $orders = []; |
||
237 | |||
238 | foreach ($orderReferences as $orderReference) { |
||
239 | $orders[] = new ReturnLabelsOrderType( |
||
240 | $this->securityService->getHash($orderReference), |
||
241 | $targetWebShop, |
||
242 | $orderReference, |
||
243 | null, |
||
244 | $shippingOption |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | $request = new GeneratePdfReturnLabelsRequest( |
||
249 | $printer |
||
250 | ); |
||
251 | $request->setWebshop($this->generateServiceType->getWebShopId()); |
||
252 | $request->setOrder($orders); |
||
253 | |||
254 | $response = $this->generateServiceType->generateImageReturnLabels($request); |
||
255 | |||
256 | return $this->processResponse($response, $this->generateServiceType); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @param $orderReference |
||
261 | * @param $shippingOption |
||
262 | * @param null $printer |
||
263 | * @param null $targetWebShop |
||
264 | * |
||
265 | * @return GenerateExtraImageReturnLabelResponse |
||
266 | */ |
||
267 | View Code Duplication | public function generateExtraImageReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null) |
|
268 | { |
||
269 | $request = new GenerateExtraPdfReturnLabelRequest($printer); |
||
270 | $request->setShippingOption($shippingOption) |
||
271 | ->setWebshop($this->generateServiceType->getWebShopId()) |
||
272 | ->setHash($this->securityService->getHash($orderReference)) |
||
273 | ->setTargetWebshop($targetWebShop) |
||
274 | ->setOrderReference($orderReference) |
||
275 | ->setShippingOption($shippingOption); |
||
276 | |||
277 | $response = $this->generateServiceType->generateExtraImageReturnLabel($request); |
||
278 | |||
279 | return $this->processResponse($response, $this->generateServiceType); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * @param $orderReference |
||
284 | * @param null $includeMetaData |
||
285 | * @param null $batch |
||
286 | * @param null $targetWebShop |
||
287 | * |
||
288 | * @return GenerateExtraImageLabelResponse |
||
289 | */ |
||
290 | View Code Duplication | public function generateExtraImageLabel($orderReference, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
291 | { |
||
292 | $request = new GenerateExtraImageLabelRequest( |
||
293 | $this->securityService->getHash($orderReference), |
||
294 | $this->generateServiceType->getWebShopId(), |
||
295 | $targetWebShop, |
||
296 | $orderReference, |
||
297 | $batch, |
||
298 | $includeMetaData |
||
299 | ); |
||
300 | |||
301 | $response = $this->generateServiceType->generateExtraImageLabel($request); |
||
302 | |||
303 | return $this->processResponse($response, $this->generateServiceType); |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * @param array $orderReferences |
||
308 | * @param null $printer |
||
309 | * @param null $includeMetaData |
||
310 | * @param null $batch |
||
311 | * @param null $targetWebShop |
||
312 | * |
||
313 | * @return GenerateZplLabelsResponse |
||
314 | */ |
||
315 | View Code Duplication | public function generateZplLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
339 | } |
||
340 | |||
341 | /** |
||
342 | * @param $orderReference |
||
343 | * @param $barCode |
||
344 | * @param null $printer |
||
345 | * @param null $includeMetaData |
||
346 | * @param null $targetWebShop |
||
347 | * |
||
348 | * @return GetExistingPdfLabelResponse |
||
349 | */ |
||
350 | View Code Duplication | public function getExistingPdfLabel($orderReference, $barCode, $printer = null, $includeMetaData = null, $targetWebShop = null) |
|
351 | { |
||
352 | $request = new GetExistingPdfLabelRequest($printer); |
||
353 | $request->setHash($this->securityService->getHash($orderReference)) |
||
354 | ->setWebshop($this->getServiceType->getWebShopId()) |
||
355 | ->setOrderReference($orderReference) |
||
356 | ->setBarcode($barCode) |
||
357 | ->setIncludeMetaData($includeMetaData) |
||
358 | ->setTargetWebshop($targetWebShop); |
||
359 | |||
360 | $response = $this->getServiceType->getExistingPdfLabel($request); |
||
361 | |||
362 | return $this->processResponse($response, $this->getServiceType); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * @param array $barCodes [$orderReference => $barcode] |
||
367 | * @param null $printer |
||
368 | * @param null $includeMetaData |
||
369 | * |
||
370 | * @return GetExistingPdfLabelsResponse |
||
371 | */ |
||
372 | View Code Duplication | public function getExistingPdfLabels(array $barCodes, $printer = null, $includeMetaData = null) |
|
393 | } |
||
394 | |||
395 | /** |
||
396 | * @param $orderReference |
||
397 | * @param $barCode |
||
398 | * @param null $includeMetaData |
||
399 | * @param null $targetWebShop |
||
400 | * |
||
401 | * @return GetExistingImageLabelResponse |
||
402 | */ |
||
403 | View Code Duplication | public function getExistingImageLabel($orderReference, $barCode, $includeMetaData = null, $targetWebShop = null) |
|
404 | { |
||
405 | $request = new GetExistingPdfLabelRequest(); |
||
406 | $request->setHash($this->securityService->getHash($orderReference)) |
||
407 | ->setWebshop($this->getServiceType->getWebShopId()) |
||
408 | ->setOrderReference($orderReference) |
||
409 | ->setBarcode($barCode) |
||
410 | ->setIncludeMetaData($includeMetaData) |
||
411 | ->setTargetWebshop($targetWebShop); |
||
412 | |||
413 | $response = $this->getServiceType->getExistingImageLabel($request); |
||
414 | |||
415 | return $this->processResponse($response, $this->getServiceType); |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * @param array $barCodes [$orderReference => $barcode] |
||
420 | * @param null $includeMetaData |
||
421 | * |
||
422 | * @return GetExistingImageLabelsResponse |
||
423 | */ |
||
424 | View Code Duplication | public function getExistingImageLabels(array $barCodes, $includeMetaData = null) |
|
445 | } |
||
446 | } |
||
447 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths