Total Complexity | 21 |
Total Lines | 308 |
Duplicated Lines | 49.35 % |
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 |
||
33 | class LabelService implements LabelServiceInterface |
||
34 | { |
||
35 | /** |
||
36 | * @var PaazlClientInterface |
||
37 | */ |
||
38 | protected $client; |
||
39 | /** |
||
40 | * @var SecurityServiceInterface |
||
41 | */ |
||
42 | protected $security; |
||
43 | |||
44 | /** |
||
45 | * DocumentService constructor. |
||
46 | * |
||
47 | * @param PaazlClientInterface $client |
||
48 | * @param SecurityServiceInterface $security |
||
49 | */ |
||
50 | public function __construct(PaazlClientInterface $client, SecurityServiceInterface $security) |
||
51 | { |
||
52 | $this->security = $security; |
||
53 | $this->client = $client; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | View Code Duplication | public function generatePdfLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
60 | { |
||
61 | $orders = []; |
||
62 | |||
63 | foreach ($orderReferences as $orderReference) { |
||
64 | $orders[] = new OrderType( |
||
65 | $this->security->getHash($orderReference), |
||
66 | $targetWebShop, |
||
67 | $orderReference, |
||
68 | [], |
||
69 | $batch |
||
70 | ); |
||
71 | } |
||
72 | |||
73 | $request = new GeneratePdfLabelsRequest( |
||
74 | $this->client->getWebShopId(), |
||
75 | $printer, |
||
76 | $orders, |
||
77 | $includeMetaData |
||
78 | ); |
||
79 | |||
80 | return $this->client->generatePdfLabels($request); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function generateExtraPdfLabel($orderReference, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
||
87 | { |
||
88 | $request = new GenerateExtraPdfLabelRequest( |
||
89 | $this->security->getHash($orderReference), |
||
90 | $this->client->getWebShopId(), |
||
91 | $targetWebShop, |
||
92 | $orderReference, |
||
93 | null, |
||
94 | $printer, |
||
95 | $batch, |
||
96 | $includeMetaData |
||
97 | ); |
||
98 | |||
99 | return $this->client->generateExtraPdfLabel($request); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | View Code Duplication | public function generatePdfReturnLabels(array $orderReferences, $shippingOption = null, $printer = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
106 | { |
||
107 | $orders = []; |
||
108 | |||
109 | foreach ($orderReferences as $orderReference) { |
||
110 | $orders[] = new ReturnLabelsOrderType( |
||
111 | $this->security->getHash($orderReference), |
||
112 | $targetWebShop, |
||
113 | $orderReference, |
||
114 | null, |
||
115 | $shippingOption |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | $request = new GeneratePdfReturnLabelsRequest( |
||
120 | $this->client->getWebShopId(), |
||
121 | $orders, |
||
122 | $printer |
||
123 | ); |
||
124 | |||
125 | return $this->client->generatePdfReturnLabels($request); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function generateExtraPdfReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null) |
||
132 | { |
||
133 | $request = new GenerateExtraPdfReturnLabelRequest( |
||
134 | $this->security->getHash($orderReference), |
||
135 | $this->client->getWebShopId(), |
||
136 | $targetWebShop, |
||
137 | $orderReference, |
||
138 | null, |
||
139 | $shippingOption, |
||
140 | $printer |
||
141 | ); |
||
142 | |||
143 | return $this->client->generateExtraPdfReturnLabel($request); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | View Code Duplication | public function generateImageLabels(array $orderReferences, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
150 | { |
||
151 | $orders = []; |
||
152 | |||
153 | foreach ($orderReferences as $orderReference) { |
||
154 | $orders[] = new OrderType( |
||
155 | $this->security->getHash($orderReference), |
||
156 | $targetWebShop, |
||
157 | $orderReference, |
||
158 | [], |
||
159 | $batch |
||
160 | ); |
||
161 | } |
||
162 | |||
163 | $request = new GenerateImageLabelsRequest( |
||
164 | $this->client->getWebShopId(), |
||
165 | $orders, |
||
166 | $includeMetaData |
||
167 | ); |
||
168 | |||
169 | return $this->client->generateImageLabels($request); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | View Code Duplication | public function generateImageReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null) |
|
195 | } |
||
196 | |||
197 | /** |
||
198 | * {@inheritdoc} |
||
199 | */ |
||
200 | public function generateExtraImageReturnLabel($orderReference, $shippingOption, $targetWebShop = null) |
||
201 | { |
||
202 | $request = new GenerateExtraImageReturnLabelRequest( |
||
203 | $this->security->getHash($orderReference), |
||
204 | $this->client->getWebShopId(), |
||
205 | $targetWebShop, |
||
206 | $orderReference, |
||
207 | null, |
||
208 | $shippingOption |
||
209 | ); |
||
210 | |||
211 | return $this->client->generateExtraImageReturnLabel($request); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function generateExtraImageLabel($orderReference, $includeMetaData = null, $batch = null, $targetWebShop = null) |
||
218 | { |
||
219 | $request = new GenerateExtraImageLabelRequest( |
||
220 | $this->security->getHash($orderReference), |
||
221 | $this->client->getWebShopId(), |
||
222 | $targetWebShop, |
||
223 | $orderReference, |
||
224 | null, |
||
225 | $batch, |
||
226 | $includeMetaData |
||
227 | ); |
||
228 | |||
229 | return $this->client->generateExtraImageLabel($request); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * {@inheritdoc} |
||
234 | */ |
||
235 | View Code Duplication | public function generateZplLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null) |
|
1 ignored issue
–
show
|
|||
236 | { |
||
237 | $orders = []; |
||
238 | |||
239 | foreach ($orderReferences as $orderReference) { |
||
240 | $orders[] = new OrderType( |
||
241 | $this->security->getHash($orderReference), |
||
242 | $targetWebShop, |
||
243 | $orderReference, |
||
244 | null, |
||
245 | $batch |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | $request = new GenerateZplLabelsRequest( |
||
250 | $this->client->getWebShopId(), |
||
251 | $printer, |
||
252 | $orders, |
||
253 | $includeMetaData |
||
254 | ); |
||
255 | |||
256 | return $this->client->generateZplLabels($request); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * {@inheritdoc} |
||
261 | */ |
||
262 | public function getExistingPdfLabel($orderReference, $barCode, $printer = null, $includeMetaData = null, $targetWebShop = null) |
||
263 | { |
||
264 | $request = new GetExistingPdfLabelRequest( |
||
265 | $this->security->getHash($orderReference), |
||
266 | $this->client->getWebShopId(), |
||
267 | $targetWebShop, |
||
268 | $orderReference, |
||
269 | $barCode, |
||
270 | $includeMetaData, |
||
271 | $printer |
||
272 | ); |
||
273 | |||
274 | return $this->client->getExistingPdfLabel($request); |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * {@inheritdoc} |
||
279 | */ |
||
280 | View Code Duplication | public function getExistingPdfLabels(array $labelTypes, $printer = null, $includeMetaData = null) |
|
300 | } |
||
301 | |||
302 | /** |
||
303 | * {@inheritdoc} |
||
304 | */ |
||
305 | public function getExistingImageLabel($orderReference, $barCode, $includeMetaData = null, $targetWebShop = null) |
||
306 | { |
||
307 | $request = new GetExistingImageLabelRequest( |
||
308 | $this->security->getHash($orderReference), |
||
309 | $this->client->getWebShopId(), |
||
310 | $targetWebShop, |
||
311 | $orderReference, |
||
312 | $barCode, |
||
313 | $includeMetaData); |
||
314 | |||
315 | return $this->client->getExistingImageLabel($request); |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * {@inheritdoc} |
||
320 | */ |
||
321 | View Code Duplication | public function getExistingImageLabels(array $labelTypes, $includeMetaData = null) |
|
341 | } |
||
342 | } |
||
343 |
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.