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