Total Complexity | 61 |
Total Lines | 579 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like ComputopFactory often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ComputopFactory, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
72 | class ComputopFactory extends AbstractFactory |
||
73 | { |
||
74 | /** |
||
75 | * @return \SprykerEco\Yves\Computop\ComputopConfigInterface |
||
76 | */ |
||
77 | public function getComputopConfig() |
||
78 | { |
||
79 | return $this->getConfig(); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPaymentHandlerInterface |
||
84 | */ |
||
85 | public function createComputopPaymentHandler() |
||
86 | { |
||
87 | return new ComputopPaymentHandler($this->getConfig()); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
92 | */ |
||
93 | public function createCreditCardForm() |
||
94 | { |
||
95 | return new CreditCardSubForm(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
100 | */ |
||
101 | public function createPayNowForm() |
||
102 | { |
||
103 | return new PayNowSubForm(); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
108 | */ |
||
109 | public function createPayPalForm() |
||
110 | { |
||
111 | return new PayPalSubForm(); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
116 | */ |
||
117 | public function createSofortForm() |
||
118 | { |
||
119 | return new SofortSubForm(); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
124 | */ |
||
125 | public function createDirectDebitForm() |
||
126 | { |
||
127 | return new DirectDebitSubForm(); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
132 | */ |
||
133 | public function createPaydirektForm() |
||
134 | { |
||
135 | return new PaydirektSubForm(); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
140 | */ |
||
141 | public function createIdealForm() |
||
142 | { |
||
143 | return new IdealSubForm(); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
||
148 | */ |
||
149 | public function createEasyCreditForm() |
||
150 | { |
||
151 | return new EasyCreditSubForm(); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
156 | */ |
||
157 | public function createCreditCardFormDataProvider() |
||
158 | { |
||
159 | return new CreditCardFormDataProvider($this->getQuoteClient(), $this->createOrderCreditCardMapper()); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
164 | */ |
||
165 | public function createPayNowFormDataProvider() |
||
166 | { |
||
167 | return new PayNowFormDataProvider($this->getQuoteClient(), $this->createOrderPayNowMapper()); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
172 | */ |
||
173 | public function createPayPalFormDataProvider() |
||
174 | { |
||
175 | return new PayPalFormDataProvider($this->getQuoteClient(), $this->createOrderPayPalMapper()); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
180 | */ |
||
181 | public function createPayPalExpressFormDataProvider() |
||
182 | { |
||
183 | return new PayPalExpressFormDataProvider($this->getQuoteClient(), $this->createOrderPayPalExpressMapper()); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
188 | */ |
||
189 | public function createSofortFormDataProvider() |
||
190 | { |
||
191 | return new SofortFormDataProvider($this->getQuoteClient(), $this->createOrderSofortMapper()); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
196 | */ |
||
197 | public function createDirectDebitFormDataProvider() |
||
198 | { |
||
199 | return new DirectDebitFormDataProvider($this->getQuoteClient(), $this->createOrderDirectDebitMapper()); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
204 | */ |
||
205 | public function createPaydirektFormDataProvider() |
||
206 | { |
||
207 | return new PaydirektFormDataProvider($this->getQuoteClient(), $this->createOrderPaydirektMapper()); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
212 | */ |
||
213 | public function createIdealFormDataProvider() |
||
214 | { |
||
215 | return new IdealFormDataProvider($this->getQuoteClient(), $this->createOrderIdealMapper()); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
||
220 | */ |
||
221 | public function createEasyCreditFormDataProvider() |
||
222 | { |
||
223 | return new EasyCreditFormDataProvider($this->getQuoteClient(), $this->createOrderEasyCreditMapper()); |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * @return \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface |
||
228 | */ |
||
229 | public function getComputopApiService() |
||
230 | { |
||
231 | return $this->getProvidedDependency(ComputopDependencyProvider::SERVICE_COMPUTOP_API); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * @return \Symfony\Component\HttpKernel\HttpKernelInterface |
||
236 | */ |
||
237 | public function getApplication() |
||
238 | { |
||
239 | return $this->getProvidedDependency(ComputopDependencyProvider::PLUGIN_APPLICATION); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @return \SprykerEco\Yves\Computop\Dependency\Client\ComputopToQuoteClientInterface |
||
244 | */ |
||
245 | public function getQuoteClient() |
||
246 | { |
||
247 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_QUOTE); |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * @return \Spryker\Client\Shipment\ShipmentClientInterface |
||
252 | */ |
||
253 | public function getShipmentClient(): ShipmentClientInterface |
||
254 | { |
||
255 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_SHIPMENT); |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
260 | */ |
||
261 | public function createCreditCardPaymentHandler() |
||
262 | { |
||
263 | return new ComputopCreditCardPaymentHandler($this->createInitCreditCardConverter(), $this->getComputopClient()); |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
268 | */ |
||
269 | public function createPayNowPaymentHandler() |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
276 | */ |
||
277 | public function createPayPalPaymentHandler() |
||
278 | { |
||
279 | return new ComputopPayPalPaymentHandler($this->createInitPayPalConverter(), $this->getComputopClient()); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * @return \SprykerEco\Yves\Computop\Handler\ExpressCheckout\ComputopPayPalExpressInitHandlerInterface |
||
284 | */ |
||
285 | public function createPayPalExpressInitHandler() |
||
286 | { |
||
287 | return new ComputopPayPalExpressInitHandler( |
||
288 | $this->createInitPayPalExpressConverter(), |
||
289 | $this->getQuoteClient(), |
||
290 | $this->getComputopClient(), |
||
291 | $this->getShipmentClient(), |
||
292 | $this->createPayPalExpressToQuoteMapper() |
||
293 | ); |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * @return \SprykerEco\Yves\Computop\Handler\ExpressCheckout\ComputopPayPalExpressPrepareHandlerInterface |
||
298 | */ |
||
299 | public function createPayPalExpressPrepareHandler(): ComputopPayPalExpressPrepareHandlerInterface |
||
300 | { |
||
301 | return new ComputopPayPalExpressPrepareHandler( |
||
302 | $this->getQuoteClient(), |
||
303 | $this->createPayPalExpressFormDataProvider(), |
||
304 | $this->getComputopApiClient(), |
||
305 | $this->getComputopApiService(), |
||
306 | $this->getComputopConfig() |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @return \SprykerEco\Yves\Computop\Handler\ExpressCheckout\ComputopPayPalExpressCompleteHandlerInterface |
||
312 | */ |
||
313 | public function createPayPalExpressCompleteHandler(): ComputopPayPalExpressCompleteHandlerInterface |
||
314 | { |
||
315 | return new ComputopPayPalExpressCompleteHandler( |
||
316 | $this->getComputopApiClient(), |
||
317 | $this->getComputopClient() |
||
318 | ); |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
323 | */ |
||
324 | public function createDirectDebitPaymentHandler() |
||
325 | { |
||
326 | return new ComputopDirectDebitPaymentHandler($this->createInitDirectDebitConverter(), $this->getComputopClient()); |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
331 | */ |
||
332 | public function createEasyCreditPaymentHandler() |
||
338 | ); |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
343 | */ |
||
344 | public function createPaydirektPaymentHandler() |
||
345 | { |
||
346 | return new ComputopPaydirektPaymentHandler($this->createInitPaydirektConverter(), $this->getComputopClient()); |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
351 | */ |
||
352 | public function createSofortPaymentHandler() |
||
353 | { |
||
354 | return new ComputopSofortPaymentHandler($this->createInitSofortConverter(), $this->getComputopClient()); |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * @return \SprykerEco\Yves\Computop\Handler\ComputopPrePostPaymentHandlerInterface |
||
359 | */ |
||
360 | public function createIdealPaymentHandler() |
||
361 | { |
||
362 | return new ComputopIdealPaymentHandler($this->createInitIdealConverter(), $this->getComputopClient()); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
367 | */ |
||
368 | protected function createInitCreditCardConverter() |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
375 | */ |
||
376 | protected function createInitPayNowConverter() |
||
377 | { |
||
378 | return new InitPayNowConverter($this->getComputopApiService(), $this->getConfig()); |
||
379 | } |
||
380 | |||
381 | /** |
||
382 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
383 | */ |
||
384 | protected function createInitPayPalConverter() |
||
385 | { |
||
386 | return new InitPayPalConverter($this->getComputopApiService(), $this->getConfig()); |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
391 | */ |
||
392 | protected function createInitPayPalExpressConverter() |
||
393 | { |
||
394 | return new InitPayPalExpressConverter($this->getComputopApiService(), $this->getConfig()); |
||
395 | } |
||
396 | |||
397 | /** |
||
398 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
399 | */ |
||
400 | protected function createInitDirectDebitConverter() |
||
401 | { |
||
402 | return new InitDirectDebitConverter($this->getComputopApiService(), $this->getConfig()); |
||
403 | } |
||
404 | |||
405 | /** |
||
406 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
407 | */ |
||
408 | protected function createInitEasyCreditConverter() |
||
409 | { |
||
410 | return new InitEasyCreditConverter($this->getComputopApiService(), $this->getConfig()); |
||
411 | } |
||
412 | |||
413 | /** |
||
414 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
415 | */ |
||
416 | protected function createInitPaydirektConverter() |
||
417 | { |
||
418 | return new InitPaydirektConverter($this->getComputopApiService(), $this->getConfig()); |
||
419 | } |
||
420 | |||
421 | /** |
||
422 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
423 | */ |
||
424 | protected function createInitSofortConverter() |
||
425 | { |
||
426 | return new InitSofortConverter($this->getComputopApiService(), $this->getConfig()); |
||
427 | } |
||
428 | |||
429 | /** |
||
430 | * @return \SprykerEco\Yves\Computop\Converter\ConverterInterface |
||
431 | */ |
||
432 | protected function createInitIdealConverter() |
||
433 | { |
||
434 | return new InitIdealConverter($this->getComputopApiService(), $this->getConfig()); |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * @return \SprykerEco\Client\Computop\ComputopClientInterface |
||
439 | */ |
||
440 | protected function getComputopClient() |
||
441 | { |
||
442 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_COMPUTOP); |
||
443 | } |
||
444 | |||
445 | /** |
||
446 | * @return \SprykerEco\Yves\Computop\Dependency\ComputopToStoreInterface |
||
447 | */ |
||
448 | protected function getStore() |
||
449 | { |
||
450 | return $this->getProvidedDependency(ComputopDependencyProvider::STORE); |
||
451 | } |
||
452 | |||
453 | /** |
||
454 | * @return \SprykerEco\Yves\Computop\Dependency\Client\ComputopToCalculationClientInterface |
||
455 | */ |
||
456 | protected function getCalculationClient() |
||
457 | { |
||
458 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_CALCULATION); |
||
459 | } |
||
460 | |||
461 | /** |
||
462 | * @return \SprykerEco\Yves\Computop\Dependency\Client\ComputopToComputopApiClientInterface |
||
463 | */ |
||
464 | protected function getComputopApiClient(): ComputopToComputopApiClientInterface |
||
465 | { |
||
466 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_COMPUTOP_API); |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
471 | */ |
||
472 | protected function createOrderCreditCardMapper() |
||
473 | { |
||
474 | return new CreditCardMapper( |
||
475 | $this->getComputopApiService(), |
||
476 | $this->getRouter(), |
||
477 | $this->getStore(), |
||
478 | $this->getConfig(), |
||
479 | $this->getRequestStack()->getCurrentRequest(), |
||
|
|||
480 | $this->getUtilEncodingService(), |
||
481 | $this->getCountryClient() |
||
482 | ); |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
487 | */ |
||
488 | protected function createOrderPayNowMapper() |
||
489 | { |
||
490 | return new PayNowMapper( |
||
491 | $this->getComputopApiService(), |
||
492 | $this->getRouter(), |
||
493 | $this->getStore(), |
||
494 | $this->getConfig(), |
||
495 | $this->getRequestStack()->getCurrentRequest(), |
||
496 | $this->getUtilEncodingService(), |
||
497 | $this->getCountryClient() |
||
498 | ); |
||
499 | } |
||
500 | |||
501 | /** |
||
502 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
503 | */ |
||
504 | protected function createOrderPayPalMapper() |
||
505 | { |
||
506 | return new PayPalMapper( |
||
507 | $this->getComputopApiService(), |
||
508 | $this->getRouter(), |
||
509 | $this->getStore(), |
||
510 | $this->getConfig(), |
||
511 | $this->getRequestStack()->getCurrentRequest(), |
||
512 | $this->getUtilEncodingService(), |
||
513 | $this->getCountryClient() |
||
514 | ); |
||
515 | } |
||
516 | |||
517 | /** |
||
518 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
519 | */ |
||
520 | protected function createOrderPayPalExpressMapper() |
||
521 | { |
||
522 | return new PayPalExpressMapper( |
||
523 | $this->getComputopApiService(), |
||
524 | $this->getRouter(), |
||
525 | $this->getStore(), |
||
526 | $this->getConfig(), |
||
527 | $this->getRequestStack()->getCurrentRequest(), |
||
528 | $this->getUtilEncodingService(), |
||
529 | $this->getCountryClient() |
||
530 | ); |
||
531 | } |
||
532 | |||
533 | /** |
||
534 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
535 | */ |
||
536 | protected function createOrderDirectDebitMapper() |
||
537 | { |
||
538 | return new DirectDebitMapper( |
||
539 | $this->getComputopApiService(), |
||
540 | $this->getRouter(), |
||
541 | $this->getStore(), |
||
542 | $this->getConfig(), |
||
543 | $this->getRequestStack()->getCurrentRequest(), |
||
544 | $this->getUtilEncodingService(), |
||
545 | $this->getCountryClient() |
||
546 | ); |
||
547 | } |
||
548 | |||
549 | /** |
||
550 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
551 | */ |
||
552 | protected function createOrderSofortMapper() |
||
553 | { |
||
554 | return new SofortMapper( |
||
555 | $this->getComputopApiService(), |
||
556 | $this->getRouter(), |
||
557 | $this->getStore(), |
||
558 | $this->getConfig(), |
||
559 | $this->getRequestStack()->getCurrentRequest(), |
||
560 | $this->getUtilEncodingService(), |
||
561 | $this->getCountryClient() |
||
562 | ); |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
567 | */ |
||
568 | protected function createOrderPaydirektMapper() |
||
569 | { |
||
570 | return new PaydirektMapper( |
||
571 | $this->getComputopApiService(), |
||
572 | $this->getRouter(), |
||
573 | $this->getStore(), |
||
574 | $this->getConfig(), |
||
575 | $this->getRequestStack()->getCurrentRequest(), |
||
576 | $this->getUtilEncodingService(), |
||
577 | $this->getCountryClient() |
||
578 | ); |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
583 | */ |
||
584 | protected function createOrderIdealMapper() |
||
585 | { |
||
586 | return new IdealMapper( |
||
587 | $this->getComputopApiService(), |
||
588 | $this->getRouter(), |
||
589 | $this->getStore(), |
||
590 | $this->getConfig(), |
||
591 | $this->getRequestStack()->getCurrentRequest(), |
||
592 | $this->getUtilEncodingService(), |
||
593 | $this->getCountryClient() |
||
594 | ); |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * @return \SprykerEco\Yves\Computop\Mapper\Init\MapperInterface |
||
599 | */ |
||
600 | protected function createOrderEasyCreditMapper() |
||
610 | ); |
||
611 | } |
||
612 | |||
613 | /** |
||
614 | * @return \Spryker\Yves\Router\Router\RouterInterface |
||
615 | */ |
||
616 | public function getRouter(): RouterInterface |
||
617 | { |
||
618 | return $this->getProvidedDependency(ComputopDependencyProvider::SERVICE_ROUTER); |
||
619 | } |
||
620 | |||
621 | /** |
||
622 | * @return \Symfony\Component\HttpFoundation\RequestStack |
||
623 | */ |
||
624 | public function getRequestStack(): RequestStack |
||
627 | } |
||
628 | |||
629 | /** |
||
630 | * @return \SprykerEco\Yves\Computop\Dependency\Service\ComputopToUtilEncodingServiceInterface |
||
631 | */ |
||
632 | public function getUtilEncodingService(): ComputopToUtilEncodingServiceInterface |
||
633 | { |
||
634 | return $this->getProvidedDependency(ComputopDependencyProvider::SERVICE_UTIL_ENCODING); |
||
635 | } |
||
636 | |||
637 | /** |
||
638 | * @return \SprykerEco\Yves\Computop\Dependency\Client\ComputopToCountryClientInterface |
||
639 | */ |
||
640 | public function getCountryClient(): ComputopToCountryClientInterface |
||
641 | { |
||
642 | return $this->getProvidedDependency(ComputopDependencyProvider::CLIENT_COUNTRY); |
||
643 | } |
||
644 | |||
645 | /** |
||
646 | * @return \SprykerEco\Yves\Computop\Mapper\Init\PrePlace\PayPalExpressToQuoteMapper |
||
647 | */ |
||
648 | protected function createPayPalExpressToQuoteMapper(): PayPalExpressToQuoteMapper |
||
649 | { |
||
650 | return new PayPalExpressToQuoteMapper(); |
||
651 | } |
||
652 | } |
||
653 |