| Total Complexity | 41 | 
| Total Lines | 426 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
Complex classes like CrefoPayApiBusinessFactory 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 CrefoPayApiBusinessFactory, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 51 | class CrefoPayApiBusinessFactory extends AbstractBusinessFactory | ||
| 52 | { | ||
| 53 | /** | ||
| 54 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 55 | */ | ||
| 56 | public function createCreateTransactionClient(): CrefoPayApiClientInterface | ||
| 57 |     { | ||
| 58 | return new CrefoPayApiClient( | ||
| 59 | $this->getCrefoPayApiHttpClient(), | ||
| 60 | $this->createCreateTransactionRequest(), | ||
| 61 | $this->createCreateTransactionResponseConverter(), | ||
| 62 | $this->createCrefoPayApiLogger() | ||
| 63 | ); | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 68 | */ | ||
| 69 | public function createReserveClient(): CrefoPayApiClientInterface | ||
| 70 |     { | ||
| 71 | return new CrefoPayApiClient( | ||
| 72 | $this->getCrefoPayApiHttpClient(), | ||
| 73 | $this->createReserveRequest(), | ||
| 74 | $this->createReserveResponseConverter(), | ||
| 75 | $this->createCrefoPayApiLogger() | ||
| 76 | ); | ||
| 77 | } | ||
| 78 | |||
| 79 | /** | ||
| 80 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 81 | */ | ||
| 82 | public function createCaptureClient(): CrefoPayApiClientInterface | ||
| 83 |     { | ||
| 84 | return new CrefoPayApiClient( | ||
| 85 | $this->getCrefoPayApiHttpClient(), | ||
| 86 | $this->createCaptureRequest(), | ||
| 87 | $this->createCaptureResponseConverter(), | ||
| 88 | $this->createCrefoPayApiLogger() | ||
| 89 | ); | ||
| 90 | } | ||
| 91 | |||
| 92 | /** | ||
| 93 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 94 | */ | ||
| 95 | public function createCancelClient(): CrefoPayApiClientInterface | ||
| 96 |     { | ||
| 97 | return new CrefoPayApiClient( | ||
| 98 | $this->getCrefoPayApiHttpClient(), | ||
| 99 | $this->createCancelRequest(), | ||
| 100 | $this->createCancelResponseConverter(), | ||
| 101 | $this->createCrefoPayApiLogger() | ||
| 102 | ); | ||
| 103 | } | ||
| 104 | |||
| 105 | /** | ||
| 106 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 107 | */ | ||
| 108 | public function createRefundClient(): CrefoPayApiClientInterface | ||
| 115 | ); | ||
| 116 | } | ||
| 117 | |||
| 118 | /** | ||
| 119 | * @return \SprykerEco\Zed\CrefoPayApi\Business\ApiClient\CrefoPayApiClientInterface | ||
| 120 | */ | ||
| 121 | public function createFinishClient(): CrefoPayApiClientInterface | ||
| 122 |     { | ||
| 123 | return new CrefoPayApiClient( | ||
| 124 | $this->getCrefoPayApiHttpClient(), | ||
| 125 | $this->createFinishRequest(), | ||
| 126 | $this->createFinishResponseConverter(), | ||
| 127 | $this->createCrefoPayApiLogger() | ||
| 128 | ); | ||
| 129 | } | ||
| 130 | |||
| 131 | /** | ||
| 132 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 133 | */ | ||
| 134 | public function createCreateTransactionRequest(): CrefoPayApiRequestInterface | ||
| 135 |     { | ||
| 136 | return new CreateTransactionRequest( | ||
| 137 | $this->createCreateTransactionRequestBuilder(), | ||
| 138 | $this->getConfig() | ||
| 139 | ); | ||
| 140 | } | ||
| 141 | |||
| 142 | /** | ||
| 143 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 144 | */ | ||
| 145 | public function createReserveRequest(): CrefoPayApiRequestInterface | ||
| 150 | ); | ||
| 151 | } | ||
| 152 | |||
| 153 | /** | ||
| 154 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 155 | */ | ||
| 156 | public function createCaptureRequest(): CrefoPayApiRequestInterface | ||
| 157 |     { | ||
| 158 | return new CaptureRequest( | ||
| 159 | $this->createCaptureRequestBuilder(), | ||
| 160 | $this->getConfig() | ||
| 161 | ); | ||
| 162 | } | ||
| 163 | |||
| 164 | /** | ||
| 165 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 166 | */ | ||
| 167 | public function createCancelRequest(): CrefoPayApiRequestInterface | ||
| 168 |     { | ||
| 169 | return new CancelRequest( | ||
| 170 | $this->createCancelRequestBuilder(), | ||
| 171 | $this->getConfig() | ||
| 172 | ); | ||
| 173 | } | ||
| 174 | |||
| 175 | /** | ||
| 176 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 177 | */ | ||
| 178 | public function createRefundRequest(): CrefoPayApiRequestInterface | ||
| 179 |     { | ||
| 180 | return new RefundRequest( | ||
| 181 | $this->createRefundRequestBuilder(), | ||
| 182 | $this->getConfig() | ||
| 183 | ); | ||
| 184 | } | ||
| 185 | |||
| 186 | /** | ||
| 187 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface | ||
| 188 | */ | ||
| 189 | public function createFinishRequest(): CrefoPayApiRequestInterface | ||
| 194 | ); | ||
| 195 | } | ||
| 196 | |||
| 197 | /** | ||
| 198 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 199 | */ | ||
| 200 | public function createCreateTransactionRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 201 |     { | ||
| 202 | return new CrefoPayApiRequestBuilder( | ||
| 203 | $this->createCreateTransactionRequestConverter(), | ||
| 204 | $this->getUtilEncodingService(), | ||
| 205 | $this->getCrefoPayApiService() | ||
| 206 | ); | ||
| 207 | } | ||
| 208 | |||
| 209 | /** | ||
| 210 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 211 | */ | ||
| 212 | public function createReserveRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 218 | ); | ||
| 219 | } | ||
| 220 | |||
| 221 | /** | ||
| 222 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 223 | */ | ||
| 224 | public function createCaptureRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 225 |     { | ||
| 226 | return new CrefoPayApiRequestBuilder( | ||
| 227 | $this->createCaptureRequestConverter(), | ||
| 228 | $this->getUtilEncodingService(), | ||
| 229 | $this->getCrefoPayApiService() | ||
| 230 | ); | ||
| 231 | } | ||
| 232 | |||
| 233 | /** | ||
| 234 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 235 | */ | ||
| 236 | public function createCancelRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 237 |     { | ||
| 238 | return new CrefoPayApiRequestBuilder( | ||
| 239 | $this->createCancelRequestConverter(), | ||
| 240 | $this->getUtilEncodingService(), | ||
| 241 | $this->getCrefoPayApiService() | ||
| 242 | ); | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 247 | */ | ||
| 248 | public function createRefundRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 249 |     { | ||
| 250 | return new CrefoPayApiRequestBuilder( | ||
| 251 | $this->createRefundRequestConverter(), | ||
| 252 | $this->getUtilEncodingService(), | ||
| 253 | $this->getCrefoPayApiService() | ||
| 254 | ); | ||
| 255 | } | ||
| 256 | |||
| 257 | /** | ||
| 258 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Builder\CrefoPayApiRequestBuilderInterface | ||
| 259 | */ | ||
| 260 | public function createFinishRequestBuilder(): CrefoPayApiRequestBuilderInterface | ||
| 266 | ); | ||
| 267 | } | ||
| 268 | |||
| 269 | /** | ||
| 270 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 271 | */ | ||
| 272 | public function createCreateTransactionRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 273 |     { | ||
| 274 | return new CreateTransactionRequestConverter(); | ||
| 275 | } | ||
| 276 | |||
| 277 | /** | ||
| 278 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 279 | */ | ||
| 280 | public function createReserveRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 281 |     { | ||
| 282 | return new ReserveRequestConverter(); | ||
| 283 | } | ||
| 284 | |||
| 285 | /** | ||
| 286 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 287 | */ | ||
| 288 | public function createCaptureRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 289 |     { | ||
| 290 | return new CaptureRequestConverter(); | ||
| 291 | } | ||
| 292 | |||
| 293 | /** | ||
| 294 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 295 | */ | ||
| 296 | public function createCancelRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 297 |     { | ||
| 298 | return new CancelRequestConverter(); | ||
| 299 | } | ||
| 300 | |||
| 301 | /** | ||
| 302 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 303 | */ | ||
| 304 | public function createRefundRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 305 |     { | ||
| 306 | return new RefundRequestConverter(); | ||
| 307 | } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Request\Converter\CrefoPayApiRequestConverterInterface | ||
| 311 | */ | ||
| 312 | public function createFinishRequestConverter(): CrefoPayApiRequestConverterInterface | ||
| 313 |     { | ||
| 314 | return new FinishRequestConverter(); | ||
| 315 | } | ||
| 316 | |||
| 317 | /** | ||
| 318 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 319 | */ | ||
| 320 | public function createCreateTransactionResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 321 |     { | ||
| 322 | return new CrefoPayApiResponseConverter( | ||
| 323 | $this->getUtilEncodingService(), | ||
| 324 | $this->createCreateTransactionResponseMapper(), | ||
| 325 | $this->createCrefoPayApiResponseValidator() | ||
| 326 | ); | ||
| 327 | } | ||
| 328 | |||
| 329 | /** | ||
| 330 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 331 | */ | ||
| 332 | public function createReserveResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 333 |     { | ||
| 334 | return new CrefoPayApiResponseConverter( | ||
| 335 | $this->getUtilEncodingService(), | ||
| 336 | $this->createReserveResponseMapper(), | ||
| 337 | $this->createCrefoPayApiResponseValidator() | ||
| 338 | ); | ||
| 339 | } | ||
| 340 | |||
| 341 | /** | ||
| 342 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 343 | */ | ||
| 344 | public function createCaptureResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 345 |     { | ||
| 346 | return new CrefoPayApiResponseConverter( | ||
| 347 | $this->getUtilEncodingService(), | ||
| 348 | $this->createCaptureResponseMapper(), | ||
| 349 | $this->createCrefoPayApiResponseValidator() | ||
| 350 | ); | ||
| 351 | } | ||
| 352 | |||
| 353 | /** | ||
| 354 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 355 | */ | ||
| 356 | public function createCancelResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 362 | ); | ||
| 363 | } | ||
| 364 | |||
| 365 | /** | ||
| 366 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 367 | */ | ||
| 368 | public function createRefundResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 369 |     { | ||
| 370 | return new CrefoPayApiResponseConverter( | ||
| 371 | $this->getUtilEncodingService(), | ||
| 372 | $this->createRefundResponseMapper(), | ||
| 373 | $this->createCrefoPayApiResponseValidator() | ||
| 374 | ); | ||
| 375 | } | ||
| 376 | |||
| 377 | /** | ||
| 378 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Converter\CrefoPayApiResponseConverterInterface | ||
| 379 | */ | ||
| 380 | public function createFinishResponseConverter(): CrefoPayApiResponseConverterInterface | ||
| 386 | ); | ||
| 387 | } | ||
| 388 | |||
| 389 | /** | ||
| 390 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 391 | */ | ||
| 392 | public function createCreateTransactionResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 393 |     { | ||
| 394 | return new CreateTransactionResponseMapper(); | ||
| 395 | } | ||
| 396 | |||
| 397 | /** | ||
| 398 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 399 | */ | ||
| 400 | public function createReserveResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 401 |     { | ||
| 402 | return new ReserveResponseMapper(); | ||
| 403 | } | ||
| 404 | |||
| 405 | /** | ||
| 406 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 407 | */ | ||
| 408 | public function createCaptureResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 409 |     { | ||
| 410 | return new CaptureResponseMapper(); | ||
| 411 | } | ||
| 412 | |||
| 413 | /** | ||
| 414 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 415 | */ | ||
| 416 | public function createCancelResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 417 |     { | ||
| 418 | return new CancelResponseMapper(); | ||
| 419 | } | ||
| 420 | |||
| 421 | /** | ||
| 422 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 423 | */ | ||
| 424 | public function createRefundResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 425 |     { | ||
| 426 | return new RefundResponseMapper(); | ||
| 427 | } | ||
| 428 | |||
| 429 | /** | ||
| 430 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Mapper\CrefoPayApiResponseMapperInterface | ||
| 431 | */ | ||
| 432 | public function createFinishResponseMapper(): CrefoPayApiResponseMapperInterface | ||
| 433 |     { | ||
| 434 | return new FinishResponseMapper(); | ||
| 435 | } | ||
| 436 | |||
| 437 | /** | ||
| 438 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Response\Validator\CrefoPayApiResponseValidatorInterface | ||
| 439 | */ | ||
| 440 | public function createCrefoPayApiResponseValidator(): CrefoPayApiResponseValidatorInterface | ||
| 444 | ); | ||
| 445 | } | ||
| 446 | |||
| 447 | /** | ||
| 448 | * @return \SprykerEco\Zed\CrefoPayApi\Business\Logger\CrefoPayApiLoggerInterface | ||
| 449 | */ | ||
| 450 | public function createCrefoPayApiLogger(): CrefoPayApiLoggerInterface | ||
| 451 |     { | ||
| 452 | return new CrefoPayApiLogger($this->getEntityManager()); | ||
| 453 | } | ||
| 454 | |||
| 455 | /** | ||
| 456 | * @return \SprykerEco\Zed\CrefoPayApi\Dependency\Service\CrefoPayApiToUtilEncodingServiceInterface | ||
| 457 | */ | ||
| 458 | public function getUtilEncodingService(): CrefoPayApiToUtilEncodingServiceInterface | ||
| 459 |     { | ||
| 460 | return $this->getProvidedDependency(CrefoPayApiDependencyProvider::SERVICE_UTIL_ENCODING); | ||
| 461 | } | ||
| 462 | |||
| 463 | /** | ||
| 464 | * @return \SprykerEco\Service\CrefoPayApi\CrefoPayApiServiceInterface | ||
| 465 | */ | ||
| 466 | public function getCrefoPayApiService(): CrefoPayApiServiceInterface | ||
| 467 |     { | ||
| 468 | return $this->getProvidedDependency(CrefoPayApiDependencyProvider::SERVICE_CREFO_PAY_API); | ||
| 469 | } | ||
| 470 | |||
| 471 | /** | ||
| 472 | * @return \SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\CrefoPayApiGuzzleHttpClientAdapterInterface | ||
| 473 | */ | ||
| 474 | public function getCrefoPayApiHttpClient(): CrefoPayApiGuzzleHttpClientAdapterInterface | ||
| 477 | } | ||
| 478 | } | ||
| 479 |