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