Total Complexity | 53 |
Total Lines | 512 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
Complex classes like ComputopBusinessFactory 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 ComputopBusinessFactory, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
88 | class ComputopBusinessFactory extends AbstractBusinessFactory |
||
89 | { |
||
90 | /** |
||
91 | * @return \SprykerEco\Zed\Computop\Business\Order\OrderManagerInterface |
||
92 | */ |
||
93 | public function createOrderSaver(): OrderManagerInterface |
||
94 | { |
||
95 | $orderSaver = new OrderManager($this->getConfig()); |
||
96 | |||
97 | $orderSaver->registerMapper($this->createOrderFactory()->createInitCreditCardMapper()); |
||
98 | $orderSaver->registerMapper($this->createOrderFactory()->createInitPayNowMapper()); |
||
99 | $orderSaver->registerMapper($this->createOrderFactory()->createInitPayPalMapper()); |
||
100 | $orderSaver->registerMapper($this->createOrderFactory()->createInitDirectDebitMapper()); |
||
101 | $orderSaver->registerMapper($this->createOrderFactory()->createInitSofortMapper()); |
||
102 | $orderSaver->registerMapper($this->createOrderFactory()->createInitPaydirektMapper()); |
||
103 | $orderSaver->registerMapper($this->createOrderFactory()->createInitIdealMapper()); |
||
104 | $orderSaver->registerMapper($this->createOrderFactory()->createInitEasyCreditMapper()); |
||
105 | |||
106 | return $orderSaver; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return \SprykerEco\Zed\Computop\Business\Hook\ComputopPostSaveHookInterface |
||
111 | */ |
||
112 | public function createPostSaveHook(): ComputopPostSaveHookInterface |
||
113 | { |
||
114 | $postSaveHook = new ComputopPostSaveHook($this->getConfig()); |
||
115 | $postSaveHook->registerMapper($this->createPostSaveSofortMapper()); |
||
116 | $postSaveHook->registerMapper($this->createPostSavePaydirektMapper()); |
||
117 | $postSaveHook->registerMapper($this->createPostSaveIdealMapper()); |
||
118 | $postSaveHook->registerMapper($this->createPostSaveCreditCart()); |
||
119 | $postSaveHook->registerMapper($this->createPostSavePayNowMapper()); |
||
120 | $postSaveHook->registerMapper($this->createPostSavePayPal()); |
||
121 | $postSaveHook->registerMapper($this->createPostSaveDirectDebit()); |
||
122 | $postSaveHook->registerMapper($this->createPostSaveEasyCredit()); |
||
123 | |||
124 | return $postSaveHook; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
129 | */ |
||
130 | public function createSofortResponseSaver(): InitResponseSaverInterface |
||
131 | { |
||
132 | return new SofortResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
137 | */ |
||
138 | public function createIdealResponseSaver(): InitResponseSaverInterface |
||
139 | { |
||
140 | return new IdealResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
145 | */ |
||
146 | public function createPaydirektResponseSaver(): InitResponseSaverInterface |
||
147 | { |
||
148 | return new PaydirektResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
153 | */ |
||
154 | public function createCreditCardResponseSaver(): InitResponseSaverInterface |
||
155 | { |
||
156 | return new CreditCardResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
161 | */ |
||
162 | public function createPayNowResponseSaver(): InitResponseSaverInterface |
||
163 | { |
||
164 | return new PayNowResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
169 | */ |
||
170 | public function createPayPalResponseSaver(): InitResponseSaverInterface |
||
171 | { |
||
172 | return new PayPalResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
177 | */ |
||
178 | public function createDirectDebitResponseSaver(): InitResponseSaverInterface |
||
179 | { |
||
180 | return new DirectDebitResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\Init\InitResponseSaverInterface |
||
185 | */ |
||
186 | public function createEasyCreditResponseSaver(): InitResponseSaverInterface |
||
187 | { |
||
188 | return new EasyCreditResponseSaver($this->getQueryContainer(), $this->getOmsFacade(), $this->getConfig()); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Logger\ComputopResponseLoggerInterface |
||
193 | */ |
||
194 | public function createComputopResponseLogger(): ComputopResponseLoggerInterface |
||
195 | { |
||
196 | return new ComputopResponseLogger(); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return \SprykerEco\Zed\Computop\Dependency\ComputopToStoreInterface |
||
201 | */ |
||
202 | public function getStore(): ComputopToStoreInterface |
||
203 | { |
||
204 | return $this->getProvidedDependency(ComputopDependencyProvider::STORE); |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\CommandHandlerInterface |
||
209 | */ |
||
210 | public function createAuthorizeCommandHandler(): CommandHandlerInterface |
||
211 | { |
||
212 | return new AuthorizeCommandHandler( |
||
213 | $this->createAuthorizeHandler(), |
||
214 | $this->createAuthorizeManager() |
||
215 | ); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\CommandHandlerInterface |
||
220 | */ |
||
221 | public function createCancelCommandHandler(): CommandHandlerInterface |
||
222 | { |
||
223 | return new CancelCommandHandler( |
||
224 | $this->createInquireHandler(), |
||
225 | $this->createReverseHandler(), |
||
226 | $this->createCancelManager(), |
||
227 | $this->getFlashMessengerFacade() |
||
228 | ); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\CommandHandlerInterface |
||
233 | */ |
||
234 | public function createCaptureCommandHandler(): CommandHandlerInterface |
||
235 | { |
||
236 | return new CaptureCommandHandler( |
||
237 | $this->createCaptureHandler(), |
||
238 | $this->createCaptureManager() |
||
239 | ); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\CommandHandlerInterface |
||
244 | */ |
||
245 | public function createRefundCommandHandler(): CommandHandlerInterface |
||
246 | { |
||
247 | return new RefundCommandHandler( |
||
248 | $this->createRefundHandler(), |
||
249 | $this->createRefundManager() |
||
250 | ); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\CommandHandlerInterface |
||
255 | */ |
||
256 | public function createEasyCreditAuthorizeCommandHandler(): CommandHandlerInterface |
||
257 | { |
||
258 | return new AuthorizeCommandHandler( |
||
259 | $this->createEasyCreditAuthorizeHandler(), |
||
260 | $this->createAuthorizeManager() |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PrePlace\PrePlaceHandlerInterface |
||
266 | */ |
||
267 | public function createEasyCreditStatusHandler(): PrePlaceHandlerInterface |
||
268 | { |
||
269 | return new EasyCreditStatusHandler( |
||
270 | $this->getComputopApiFacade(), |
||
271 | $this->getMoneyFacade(), |
||
272 | $this->createComputopResponseLogger() |
||
273 | ); |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * @return \SprykerEco\Zed\Computop\Business\RiskCheck\Handler\HandlerInterface |
||
278 | */ |
||
279 | public function createCrifHandler(): HandlerInterface |
||
280 | { |
||
281 | return new CrifHandler( |
||
282 | $this->getComputopApiFacade(), |
||
283 | $this->createCrifSaver(), |
||
284 | $this->getConfig() |
||
285 | ); |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @return \SprykerEco\Zed\Computop\Business\Logger\LoggerInterface |
||
290 | */ |
||
291 | public function createComputopLogger(): LoggerInterface |
||
292 | { |
||
293 | return new ComputopLogger(); |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
298 | */ |
||
299 | public function createEasyCreditAuthorizeHandler(): PostPlaceHandlerInterface |
||
300 | { |
||
301 | return new EasyCreditAuthorizeHandler( |
||
302 | $this->getComputopApiFacade(), |
||
303 | $this->createAuthorizeSaver() |
||
304 | ); |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @return \SprykerEco\Zed\Computop\Business\Payment\Reader\ComputopPaymentReaderInterface |
||
309 | */ |
||
310 | public function createPaymentReader(): ComputopPaymentReaderInterface |
||
311 | { |
||
312 | return new ComputopPaymentReader($this->getQueryContainer()); |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
317 | */ |
||
318 | public function createAuthorizeHandler(): PostPlaceHandlerInterface |
||
319 | { |
||
320 | return new AuthorizeHandler( |
||
321 | $this->getComputopApiFacade(), |
||
322 | $this->createAuthorizeSaver() |
||
323 | ); |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
328 | */ |
||
329 | public function createReverseHandler(): PostPlaceHandlerInterface |
||
330 | { |
||
331 | return new ReverseHandler( |
||
332 | $this->getComputopApiFacade(), |
||
333 | $this->createReverseSaver() |
||
334 | ); |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
339 | */ |
||
340 | public function createInquireHandler(): PostPlaceHandlerInterface |
||
345 | ); |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
350 | */ |
||
351 | public function createCaptureHandler(): PostPlaceHandlerInterface |
||
356 | ); |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\PostPlace\HandlerInterface |
||
361 | */ |
||
362 | public function createRefundHandler(): PostPlaceHandlerInterface |
||
363 | { |
||
364 | return new RefundHandler( |
||
365 | $this->getComputopApiFacade(), |
||
366 | $this->createRefundSaver() |
||
367 | ); |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @return \SprykerEco\Zed\Computop\Business\RiskCheck\Saver\RiskCheckSaverInterface |
||
372 | */ |
||
373 | public function createCrifSaver(): RiskCheckSaverInterface |
||
374 | { |
||
375 | return new CrifSaver( |
||
376 | $this->getQueryContainer(), |
||
377 | $this->createComputopLogger(), |
||
378 | $this->getConfig() |
||
379 | ); |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\SaverInterface |
||
384 | */ |
||
385 | public function createAuthorizeSaver(): SaverInterface |
||
386 | { |
||
387 | return new AuthorizeSaver( |
||
388 | $this->getQueryContainer(), |
||
389 | $this->createComputopResponseLogger(), |
||
390 | $this->getConfig() |
||
391 | ); |
||
392 | } |
||
393 | |||
394 | /** |
||
395 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\SaverInterface |
||
396 | */ |
||
397 | public function createReverseSaver(): SaverInterface |
||
398 | { |
||
399 | return new ReverseSaver( |
||
400 | $this->getQueryContainer(), |
||
401 | $this->createComputopResponseLogger(), |
||
402 | $this->getConfig() |
||
403 | ); |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\SaverInterface |
||
408 | */ |
||
409 | public function createInquireSaver(): SaverInterface |
||
410 | { |
||
411 | return new InquireSaver( |
||
412 | $this->getQueryContainer(), |
||
413 | $this->createComputopResponseLogger(), |
||
414 | $this->getConfig() |
||
415 | ); |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\SaverInterface |
||
420 | */ |
||
421 | public function createCaptureSaver(): SaverInterface |
||
422 | { |
||
423 | return new CaptureSaver( |
||
424 | $this->getQueryContainer(), |
||
425 | $this->createComputopResponseLogger(), |
||
426 | $this->getConfig() |
||
427 | ); |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * @return \SprykerEco\Zed\Computop\Business\Payment\Handler\Saver\SaverInterface |
||
432 | */ |
||
433 | public function createRefundSaver(): SaverInterface |
||
434 | { |
||
435 | return new RefundSaver( |
||
436 | $this->getQueryContainer(), |
||
437 | $this->createComputopResponseLogger(), |
||
438 | $this->getConfig() |
||
439 | ); |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\Manager\ManagerInterface |
||
444 | */ |
||
445 | public function createAuthorizeManager(): ManagerInterface |
||
446 | { |
||
447 | return new AuthorizeManager($this->getQueryContainer(), $this->getConfig()); |
||
448 | } |
||
449 | |||
450 | /** |
||
451 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\Manager\CancelManagerInterface |
||
452 | */ |
||
453 | public function createCancelManager(): CancelManagerInterface |
||
454 | { |
||
455 | return new CancelManager($this->getQueryContainer(), $this->getConfig()); |
||
456 | } |
||
457 | |||
458 | /** |
||
459 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\Manager\ManagerInterface |
||
460 | */ |
||
461 | public function createCaptureManager(): ManagerInterface |
||
462 | { |
||
463 | return new CaptureManager($this->getQueryContainer(), $this->getConfig()); |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * @return \SprykerEco\Zed\Computop\Business\Oms\Command\Manager\ManagerInterface |
||
468 | */ |
||
469 | public function createRefundManager(): ManagerInterface |
||
470 | { |
||
471 | return new RefundManager($this->getQueryContainer(), $this->getConfig()); |
||
472 | } |
||
473 | |||
474 | /** |
||
475 | * @return \SprykerEco\Zed\Computop\Business\Order\ComputopBusinessOrderFactoryInterface |
||
476 | */ |
||
477 | public function createOrderFactory(): ComputopBusinessOrderFactoryInterface |
||
478 | { |
||
479 | return new ComputopBusinessOrderFactory(); |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
484 | */ |
||
485 | public function createPostSaveSofortMapper(): InitMapperInterface |
||
486 | { |
||
487 | return new InitSofortMapper($this->getConfig(), $this->getComputopApiService()); |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
492 | */ |
||
493 | public function createPostSaveCreditCart(): InitMapperInterface |
||
494 | { |
||
495 | return new InitCreditCardMapper($this->getConfig(), $this->getComputopApiService()); |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
500 | */ |
||
501 | public function createPostSavePayNowMapper(): InitMapperInterface |
||
502 | { |
||
503 | return new InitPayNowMapper($this->getConfig(), $this->getComputopApiService()); |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
508 | */ |
||
509 | public function createPostSavePayPal(): InitMapperInterface |
||
510 | { |
||
511 | return new InitPayPalMapper($this->getConfig(), $this->getComputopApiService()); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
516 | */ |
||
517 | public function createPostSaveDirectDebit(): InitMapperInterface |
||
518 | { |
||
519 | return new InitDirectDebitMapper($this->getConfig(), $this->getComputopApiService()); |
||
520 | } |
||
521 | |||
522 | /** |
||
523 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
524 | */ |
||
525 | public function createPostSaveEasyCredit(): InitMapperInterface |
||
526 | { |
||
527 | return new InitEasyCreditMapper($this->getConfig(), $this->getComputopApiService()); |
||
528 | } |
||
529 | |||
530 | /** |
||
531 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
532 | */ |
||
533 | public function createPostSavePaydirektMapper(): InitMapperInterface |
||
534 | { |
||
535 | return new InitPaydirektMapper($this->getConfig(), $this->getComputopApiService()); |
||
536 | } |
||
537 | |||
538 | /** |
||
539 | * @return \SprykerEco\Zed\Computop\Business\Hook\Mapper\Init\InitMapperInterface |
||
540 | */ |
||
541 | public function createPostSaveIdealMapper(): InitMapperInterface |
||
542 | { |
||
543 | return new InitIdealMapper($this->getConfig(), $this->getComputopApiService()); |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * @return \SprykerEco\Zed\Computop\Business\Payment\PaymentMethodFilterInterface |
||
548 | */ |
||
549 | public function createPaymentMethodFilter(): PaymentMethodFilterInterface |
||
550 | { |
||
551 | return new PaymentMethodFilter($this->getConfig()); |
||
552 | } |
||
553 | |||
554 | /** |
||
555 | * @return \SprykerEco\Zed\Computop\Business\Processor\NotificationProcessorInterface |
||
556 | */ |
||
557 | public function createNotificationProcessor(): NotificationProcessorInterface |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * @return \SprykerEco\Service\ComputopApi\ComputopApiServiceInterface |
||
564 | */ |
||
565 | public function getComputopApiService(): ComputopApiServiceInterface |
||
566 | { |
||
567 | return $this->getProvidedDependency(ComputopDependencyProvider::SERVICE_COMPUTOP_API); |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * @return \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToOmsFacadeInterface |
||
572 | */ |
||
573 | public function getOmsFacade(): ComputopToOmsFacadeInterface |
||
576 | } |
||
577 | |||
578 | /** |
||
579 | * @return \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToMessengerFacadeInterface |
||
580 | */ |
||
581 | public function getFlashMessengerFacade(): ComputopToMessengerFacadeInterface |
||
582 | { |
||
583 | return $this->getProvidedDependency(ComputopDependencyProvider::FACADE_FLASH_MESSENGER); |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * @return \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToMoneyFacadeInterface |
||
588 | */ |
||
589 | public function getMoneyFacade(): ComputopToMoneyFacadeInterface |
||
590 | { |
||
591 | return $this->getProvidedDependency(ComputopDependencyProvider::FACADE_MONEY); |
||
592 | } |
||
593 | |||
594 | /** |
||
595 | * @return \SprykerEco\Zed\Computop\Dependency\Facade\ComputopToComputopApiFacadeInterface |
||
596 | */ |
||
597 | public function getComputopApiFacade(): ComputopToComputopApiFacadeInterface |
||
598 | { |
||
599 | return $this->getProvidedDependency(ComputopDependencyProvider::FACADE_COMPUTOP_API); |
||
600 | } |
||
601 | } |
||
602 |