Passed
Pull Request — dev (#9)
by Andrey
07:38 queued 03:31
created

extractBillingAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AmazonPay\Business\Api\Converter;
9
10
use Generated\Shared\Transfer\AddressTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer 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\AmazonpayResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...azonpayResponseTransfer 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
13
class GetOrderReferenceDetailsConverter extends AbstractResponseParserConverter
14
{
15
    const ORDER_REFERENCE_DETAILS = 'OrderReferenceDetails';
16
    const ORDER_REFERENCE_STATUS = 'OrderReferenceStatus';
17
    const FIELD_STATE = 'State';
18
    const RELEASE_ENVIRONMENT = 'ReleaseEnvironment';
19
    const SANDBOX = 'Sandbox';
20
    const BILLING_ADDRESS = 'BillingAddress';
21
    const PHYSICAL_ADDRESS = 'PhysicalAddress';
22
23
    /**
24
     * @return string
25
     */
26
    protected function getResponseType()
27
    {
28
        return 'GetOrderReferenceDetailsResult';
29
    }
30
31
    /**
32
     * @param array $response
33
     *
34
     * @return array
35
     */
36
    protected function extractOrderReferenceStatus(array $response)
37
    {
38
        return $this->extractResult($response)[static::ORDER_REFERENCE_DETAILS][static::ORDER_REFERENCE_STATUS][static::FIELD_STATE];
39
    }
40
41
    /**
42
     * @param array $response
43
     *
44
     * @return int
45
     */
46
    protected function extractIsSandbox(array $response)
47
    {
48
        return ($this->extractResult($response)[static::ORDER_REFERENCE_DETAILS][static::RELEASE_ENVIRONMENT] === static::SANDBOX) ? 1 : 0;
49
    }
50
51
    /**
52
     * @param array $response
53
     *
54
     * @return \Generated\Shared\Transfer\AddressTransfer
55
     */
56
    protected function extractBillingAddress(array $response)
57
    {
58
        $address = new AddressTransfer();
59
60
        if (!$this->isSuccess($response)) {
61
            return $address;
62
        }
63
64
        $result = $this->extractResult($response);
65
66
        $aResponseAddress =
67
            $result[static::ORDER_REFERENCE_DETAILS][static::BILLING_ADDRESS][static::PHYSICAL_ADDRESS];
68
69
        return $this->convertAddressToTransfer($aResponseAddress);
70
    }
71
72
    /**
73
     * @param \Generated\Shared\Transfer\AmazonpayResponseTransfer $responseTransfer
74
     * @param array $response
75
     *
76
     * @return \Generated\Shared\Transfer\AmazonpayResponseTransfer
77
     */
78
    protected function setBody(AmazonpayResponseTransfer $responseTransfer, array $response)
79
    {
80
        $responseTransfer->setOrderReferenceStatus(
81
            $this->convertStatusToTransfer(
82
                $this->extractResult($response)[static::ORDER_REFERENCE_DETAILS][static::ORDER_REFERENCE_STATUS]
83
            )
84
        );
85
        $responseTransfer->setIsSandbox($this->extractIsSandbox($response));
86
        $responseTransfer->setShippingAddress($this->extractShippingAddress($response));
87
        $responseTransfer->setBillingAddress($this->extractBillingAddress($response));
88
89
        return parent::setBody($responseTransfer, $response);
90
    }
91
}
92