RiskCheckResponseConverter::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
cc 3
eloc 11
c 5
b 0
f 2
nc 3
nop 1
dl 0
loc 18
rs 9.9
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\ArvatoRss\Business\Api\Converter;
9
10
use Generated\Shared\Transfer\ArvatoRssAddressValidationResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...idationResponseTransfer 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\ArvatoRssRiskCheckResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...skCheckResponseTransfer 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 stdClass;
13
14
class RiskCheckResponseConverter implements RiskCheckResponseConverterInterface
15
{
16
    /**
17
     * @param \stdClass $response
18
     *
19
     * @return \Generated\Shared\Transfer\ArvatoRssRiskCheckResponseTransfer
20
     */
21
    public function convert(stdClass $response)
22
    {
23
        $responseTransfer = new ArvatoRssRiskCheckResponseTransfer();
24
25
        $responseTransfer->setResult($response->Decision->Result);
26
        $responseTransfer->setResultCode($response->Decision->ResultCode);
27
        $responseTransfer->setActionCode($response->Decision->ActionCode);
28
        $responseTransfer->setResultText($response->Decision->ResultText);
29
        $responseTransfer->setCommunicationToken($response->Decision->CommunicationToken);
30
31
        if (isset($response->Details)) {
32
            $this->processBillingAddressResponse($responseTransfer, $response->Details->BillingCustomerResult);
33
            if (isset($response->Details->DeliveryCustomerResult)) {
34
                $this->processDeliveryAddressResponse($responseTransfer, $response->Details->DeliveryCustomerResult);
35
            }
36
        }
37
38
        return $responseTransfer;
39
    }
40
41
    /**
42
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckResponseTransfer $responseTransfer
43
     * @param \stdClass $response
44
     *
45
     * @return void
46
     */
47
    protected function processBillingAddressResponse(
48
        ArvatoRssRiskCheckResponseTransfer $responseTransfer,
49
        stdClass $response
50
    ) {
51
        if (isset($response->ServiceResults->AddressValidationResponse)) {
52
            $responseTransfer->setBillingAddressValidation(
53
                $this->convertAddressValidationResponse(
54
                    $response->ServiceResults->AddressValidationResponse
55
                )
56
            );
57
        }
58
    }
59
60
    /**
61
     * @param \Generated\Shared\Transfer\ArvatoRssRiskCheckResponseTransfer $responseTransfer
62
     * @param \stdClass $response
63
     *
64
     * @return void
65
     */
66
    protected function processDeliveryAddressResponse(
67
        ArvatoRssRiskCheckResponseTransfer $responseTransfer,
68
        stdClass $response
69
    ) {
70
        if (isset($response->ServiceResults->AddressValidationResponse)) {
71
            $responseTransfer->setDeliveryAddressValidation(
72
                $this->convertAddressValidationResponse(
73
                    $response->ServiceResults->AddressValidationResponse
74
                )
75
            );
76
        }
77
    }
78
79
    /**
80
     * @param \stdClass $response
81
     *
82
     * @return \Generated\Shared\Transfer\ArvatoRssAddressValidationResponseTransfer
83
     */
84
    protected function convertAddressValidationResponse(stdClass $response)
85
    {
86
        $addressValidationResponse = new ArvatoRssAddressValidationResponseTransfer();
87
88
        $addressValidationResponse->setReturnCode($response->ReturnCode);
89
        $addressValidationResponse->setStreet($response->Street);
90
        $addressValidationResponse->setStreetNumber($response->StreetNumber);
91
        $addressValidationResponse->setZipCode($response->ZipCode);
92
        $addressValidationResponse->setCity($response->City);
93
        $addressValidationResponse->setCountry($response->Country);
94
95
        if (isset($response->StreetNumberAdditional)) {
96
            $addressValidationResponse->setStreetNumberAdditional($response->StreetNumberAdditional);
97
        }
98
99
        return $addressValidationResponse;
100
    }
101
}
102