Passed
Pull Request — dev (#4)
by Mykyta
11:52 queued 07:39
created

ApiResponseToRegistrationRequestTransfer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 16.88 %

Importance

Changes 0
Metric Value
wmc 5
dl 13
loc 77
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 11 1
A mapCreditCardInfo() 0 14 1
A mapError() 12 12 2
A hydrateErrorToRegistrationRequest() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
namespace SprykerEco\Client\Heidelpay\Mapper;
8
9
use Generated\Shared\Transfer\HeidelpayCreditCardInfoTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...yCreditCardInfoTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...strationRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\HeidelpayResponseErrorTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ayResponseErrorTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Heidelpay\PhpApi\Response;
13
14
class ApiResponseToRegistrationRequestTransfer implements ApiResponseToRegistrationResponseTransferInterface
15
{
16
    /**
17
     * @param \Heidelpay\PhpApi\Response $apiResponseObject
18
     * @param \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer $registrationRequestTransfer
19
     *
20
     * @return void
21
     */
22
    public function map(Response $apiResponseObject, HeidelpayRegistrationRequestTransfer $registrationRequestTransfer)
23
    {
24
        $this->mapCreditCardInfo($apiResponseObject, $registrationRequestTransfer);
25
        $this->mapError($apiResponseObject, $registrationRequestTransfer);
26
27
        $registrationRequestTransfer
28
            ->setRegistrationHash(
29
                $apiResponseObject->getIdentification()->getUniqueId()
30
            )
31
            ->setQuoteHash(
32
                $apiResponseObject->getIdentification()->getTransactionId()
33
            );
34
    }
35
36
    /**
37
     * @param \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer $registrationRequestTransfer
38
     * @param \Generated\Shared\Transfer\HeidelpayResponseErrorTransfer $errorTransfer
39
     *
40
     * @return void
41
     */
42
    public function hydrateErrorToRegistrationRequest(
43
        HeidelpayRegistrationRequestTransfer $registrationRequestTransfer,
44
        HeidelpayResponseErrorTransfer $errorTransfer
45
    ) {
46
        $registrationRequestTransfer
47
            ->setIsError(true)
48
            ->setError($errorTransfer);
49
    }
50
51
    /**
52
     * @param \Heidelpay\PhpApi\Response $apiResponse
53
     * @param \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer $responseTransfer
54
     *
55
     * @return void
56
     */
57 View Code Duplication
    protected function mapError(Response $apiResponse, HeidelpayRegistrationRequestTransfer $responseTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        if (!$apiResponse->isError()) {
60
            return;
61
        }
62
63
        $errorResponse = $apiResponse->getError();
64
        $errorTransfer = (new HeidelpayResponseErrorTransfer())
65
            ->setCode($errorResponse['code'])
66
            ->setInternalMessage($errorResponse['message']);
67
68
        $this->hydrateErrorToRegistrationRequest($responseTransfer, $errorTransfer);
69
    }
70
71
    /**
72
     * @param \Heidelpay\PhpApi\Response $apiResponseObject
73
     * @param \Generated\Shared\Transfer\HeidelpayRegistrationRequestTransfer $registrationRequestTransfer
74
     *
75
     * @return void
76
     */
77
    protected function mapCreditCardInfo(Response $apiResponseObject, HeidelpayRegistrationRequestTransfer $registrationRequestTransfer)
78
    {
79
        $creditCardInfoTransfer = new HeidelpayCreditCardInfoTransfer();
80
        $accountInfo = $apiResponseObject->getAccount();
81
82
        $creditCardInfoTransfer
83
            ->setAccountBrand($accountInfo->getBrand())
84
            ->setAccountExpiryMonth($accountInfo->getExpiryMonth())
85
            ->setAccountExpiryYear($accountInfo->getExpiryYear())
86
            ->setAccountHolder($accountInfo->getHolder())
87
            ->setAccountNumber($accountInfo->getNumber())
88
            ->setAccountVerification($accountInfo->getVerification());
89
90
        $registrationRequestTransfer->setCreditCardInfo($creditCardInfoTransfer);
91
    }
92
}
93