Passed
Push — feature/ECO-808-scrutinizer ( 956529...82fb0b )
by Andrey
05:28 queued 01:30
created

updateAfterCapture()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
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\Converter;
9
10
use Generated\Shared\Transfer\AmazonpayPaymentTransfer;
11
use Generated\Shared\Transfer\AmazonpayResponseHeaderTransfer;
12
use Generated\Shared\Transfer\AmazonpayStatusTransfer;
13
use Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay 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...
14
use SprykerEco\Shared\Amazonpay\AmazonpayConstants;
15
16
class AmazonpayTransferToEntityConverter implements AmazonpayTransferToEntityConverterInterface
17
{
18
19
    /**
20
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
21
     *
22
     * @return \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay
23
     */
24
    public function mapTransferToEntity(AmazonpayPaymentTransfer $amazonpayPaymentTransfer)
25
    {
26
        $responseHeader = new AmazonpayResponseHeaderTransfer();
27
        $responseHeader->setIsSuccess(true);
28
29
        $paymentEntity = new SpyPaymentAmazonpay();
30
        $paymentEntity->fromArray($amazonpayPaymentTransfer->toArray());
31
32
        return $paymentEntity;
33
    }
34
35
    /**
36
     * @param \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay $entity
37
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
38
     *
39
     * @return void
40
     */
41
    public function updateAfterAuthorization(SpyPaymentAmazonpay $entity, AmazonpayPaymentTransfer $amazonpayPaymentTransfer)
42
    {
43
        $entity->fromArray($amazonpayPaymentTransfer->getAuthorizationDetails()->toArray());
44
        $entity->setStatus(
45
            $this->getPaymentStatusFromTransfer(
46
                $amazonpayPaymentTransfer->getAuthorizationDetails()->getAuthorizationStatus()
47
            )
48
        );
49
    }
50
51
    /**
52
     * @param \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay $entity
53
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
54
     *
55
     * @return void
56
     */
57
    public function updateAfterRefund(SpyPaymentAmazonpay $entity, AmazonpayPaymentTransfer $amazonpayPaymentTransfer)
58
    {
59
        $entity->fromArray($amazonpayPaymentTransfer->getRefundDetails()->toArray());
60
        $entity->setStatus($this->getRefundStatusFromTransfer(
61
            $amazonpayPaymentTransfer->getRefundDetails()->getRefundStatus()
62
        ));
63
    }
64
65
    /**
66
     * @param \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay $entity
67
     * @param \Generated\Shared\Transfer\AmazonpayPaymentTransfer $amazonpayPaymentTransfer
68
     *
69
     * @return void
70
     */
71
    public function updateAfterCapture(SpyPaymentAmazonpay $entity, AmazonpayPaymentTransfer $amazonpayPaymentTransfer)
72
    {
73
        $entity->fromArray($amazonpayPaymentTransfer->getCaptureDetails()->toArray());
74
        $entity->setStatus($this->getCaptureStatusFromTransfer(
75
            $amazonpayPaymentTransfer->getCaptureDetails()->getCaptureStatus()
76
        ));
77
    }
78
79
    /**
80
     * @param \Generated\Shared\Transfer\AmazonpayStatusTransfer $amazonpayStatusTransfer
81
     *
82
     * @return string
83
     */
84 View Code Duplication
    protected function getPaymentStatusFromTransfer(AmazonpayStatusTransfer $amazonpayStatusTransfer)
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...
85
    {
86
        if ($amazonpayStatusTransfer->getIsPending()) {
87
            return AmazonpayConstants::OMS_STATUS_AUTH_PENDING;
88
        }
89
90
        if ($amazonpayStatusTransfer->getIsDeclined()) {
91
            return AmazonpayConstants::OMS_STATUS_AUTH_DECLINED;
92
        }
93
94
        if ($amazonpayStatusTransfer->getIsSuspended()) {
95
            return AmazonpayConstants::OMS_STATUS_AUTH_SUSPENDED;
96
        }
97
98
        if ($amazonpayStatusTransfer->getIsTransactionTimedOut()) {
99
            return AmazonpayConstants::OMS_STATUS_AUTH_TRANSACTION_TIMED_OUT;
100
        }
101
102
        if ($amazonpayStatusTransfer->getIsOpen()) {
103
            return AmazonpayConstants::OMS_STATUS_AUTH_OPEN;
104
        }
105
106
        return AmazonpayConstants::OMS_STATUS_CLOSED;
107
    }
108
109
    /**
110
     * @param \Generated\Shared\Transfer\AmazonpayStatusTransfer $amazonpayStatusTransfer
111
     *
112
     * @return string
113
     */
114
    protected function getCaptureStatusFromTransfer(AmazonpayStatusTransfer $amazonpayStatusTransfer)
115
    {
116
        if ($amazonpayStatusTransfer->getIsPending()) {
117
            return AmazonpayConstants::OMS_STATUS_CAPTURE_PENDING;
118
        }
119
120
        if ($amazonpayStatusTransfer->getIsDeclined()) {
121
            return AmazonpayConstants::OMS_STATUS_CAPTURE_DECLINED;
122
        }
123
124
        if ($amazonpayStatusTransfer->getIsCompleted()) {
125
            return AmazonpayConstants::OMS_STATUS_CAPTURE_COMPLETED;
126
        }
127
128
        if ($amazonpayStatusTransfer->getIsClosed()) {
129
            return AmazonpayConstants::OMS_STATUS_CAPTURE_CLOSED;
130
        }
131
132
        return AmazonpayConstants::OMS_STATUS_CAPTURE_CLOSED;
133
    }
134
135
    /**
136
     * @param \Generated\Shared\Transfer\AmazonpayStatusTransfer $amazonpayStatusTransfer
137
     *
138
     * @return string
139
     */
140 View Code Duplication
    protected function getRefundStatusFromTransfer(AmazonpayStatusTransfer $amazonpayStatusTransfer)
1 ignored issue
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...
141
    {
142
        if ($amazonpayStatusTransfer->getIsPending()) {
143
            return AmazonpayConstants::OMS_STATUS_REFUND_PENDING;
144
        }
145
146
        if ($amazonpayStatusTransfer->getIsDeclined()) {
147
            return AmazonpayConstants::OMS_STATUS_REFUND_DECLINED;
148
        }
149
150
        if ($amazonpayStatusTransfer->getIsCompleted()) {
151
            return AmazonpayConstants::OMS_STATUS_CAPTURE_COMPLETED;
152
        }
153
154
        return $amazonpayStatusTransfer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $amazonpayStatusTransfer returns the type Generated\Shared\Transfer\AmazonpayStatusTransfer which is incompatible with the documented return type string.
Loading history...
155
    }
156
157
}
158