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