Passed
Push — master ( a2100c...af4f13 )
by Andrey
06:37
created

createConcreteIpnRequestHandler()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 1
dl 0
loc 18
rs 8.8571
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\Payment\Handler\Ipn;
9
10
use SprykerEco\Shared\Amazonpay\AmazonpayConstants;
11
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
12
use SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface;
13
use SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface;
14
use SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface;
15
16
class IpnRequestFactory implements IpnRequestFactoryInterface
17
{
18
19
    /**
20
     * @var \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface $omsFacade
21
     */
22
    protected $omsFacade;
23
24
    /**
25
     * @var \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer
26
     */
27
    protected $amazonpayQueryContainer;
28
29
    /**
30
     * @var \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger
31
     */
32
    protected $ipnRequestLogger;
33
34
    /**
35
     * @param \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToOmsInterface $omsFacade
36
     * @param \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer
37
     * @param \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\Logger\IpnRequestLoggerInterface $ipnRequestLogger
38
     */
39
    public function __construct(
40
        AmazonpayToOmsInterface $omsFacade,
41
        AmazonpayQueryContainerInterface $amazonpayQueryContainer,
42
        IpnRequestLoggerInterface $ipnRequestLogger
43
    ) {
44
        $this->omsFacade = $omsFacade;
45
        $this->amazonpayQueryContainer = $amazonpayQueryContainer;
46
        $this->ipnRequestLogger = $ipnRequestLogger;
47
    }
48
49
    /**
50
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentAuthorizeRequestTransfer $ipnRequest
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...uthorizeRequestTransfer 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...
51
     *
52
     * @throws IpnHandlerNotFoundException
53
     *
54
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface
55
     */
56
    public function createConcreteIpnRequestHandler(AbstractTransfer $ipnRequest)
57
    {
58
        switch ($ipnRequest->getMessage()->getNotificationType()) {
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        switch ($ipnRequest->/** @scrutinizer ignore-call */ getMessage()->getNotificationType()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
            case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_AUTHORIZE:
60
                return $this->createIpnPaymentAuthorizeHandler($ipnRequest);
61
62
            case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_CAPTURE:
63
                return $this->createIpnPaymentCaptureHandler($ipnRequest);
64
65
            case AmazonpayConstants::IPN_REQUEST_TYPE_PAYMENT_REFUND:
66
                return $this->createIpnPaymentRefundHandler($ipnRequest);
67
68
            case AmazonpayConstants::IPN_REQUEST_TYPE_ORDER_REFERENCE_NOTIFICATION:
69
                return $this->createIpnOrderReferenceHandler($ipnRequest);
70
        }
71
72
        throw new IpnHandlerNotFoundException('Unknown IPN Notification type: ' .
73
            $ipnRequest->getMessage()->getNotificationType());
74
    }
75
76
    /**
77
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentAuthorizeRequestTransfer $ipnRequest
78
     *
79
     * @throws IpnHandlerNotFoundException
80
     *
81
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface
82
     */
83
    protected function createIpnPaymentAuthorizeHandler(AbstractTransfer $ipnRequest)
84
    {
85
        if ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsSuspended()) {
0 ignored issues
show
Bug introduced by
The method getAuthorizationDetails() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        if ($ipnRequest->/** @scrutinizer ignore-call */ getAuthorizationDetails()->getAuthorizationStatus()->getIsSuspended()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
            return new IpnPaymentAuthorizeSuspendedHandler(
87
                $this->omsFacade,
88
                $this->amazonpayQueryContainer,
89
                $this->ipnRequestLogger
90
            );
91
        } elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsDeclined()) {
92
            return new IpnPaymentAuthorizeDeclineHandler(
93
                $this->omsFacade,
94
                $this->amazonpayQueryContainer,
95
                $this->ipnRequestLogger
96
            );
97
        } elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsOpen()) {
98
            return new IpnPaymentAuthorizeOpenHandler(
99
                $this->omsFacade,
100
                $this->amazonpayQueryContainer,
101
                $this->ipnRequestLogger
102
            );
103
        } elseif ($ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getIsClosed()) {
104
            return new IpnPaymentAuthorizeClosedHandler(
105
                $this->omsFacade,
106
                $this->amazonpayQueryContainer,
107
                $this->ipnRequestLogger
108
            );
109
        }
110
111
        throw new IpnHandlerNotFoundException('No IPN handler for auth payment and status ' .
112
            $ipnRequest->getAuthorizationDetails()->getAuthorizationStatus()->getState());
113
    }
114
115
    /**
116
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentCaptureRequestTransfer $ipnRequest
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...tCaptureRequestTransfer 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...
117
     *
118
     * @throws IpnHandlerNotFoundException
119
     *
120
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface
121
     */
122
    protected function createIpnPaymentCaptureHandler(AbstractTransfer $ipnRequest)
123
    {
124
        if ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsDeclined()) {
0 ignored issues
show
Bug introduced by
The method getCaptureDetails() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        if ($ipnRequest->/** @scrutinizer ignore-call */ getCaptureDetails()->getCaptureStatus()->getIsDeclined()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
            return new IpnPaymentCaptureDeclineHandler(
126
                $this->omsFacade,
127
                $this->amazonpayQueryContainer,
128
                $this->ipnRequestLogger
129
            );
130
        } elseif ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsCompleted()) {
131
            return new IpnPaymentCaptureCompletedHandler(
132
                $this->omsFacade,
133
                $this->amazonpayQueryContainer,
134
                $this->ipnRequestLogger
135
            );
136
        } elseif ($ipnRequest->getCaptureDetails()->getCaptureStatus()->getIsClosed()) {
137
            return new IpnEmptyHandler();
138
        }
139
140
        throw new IpnHandlerNotFoundException('No IPN handler for capture and status ' .
141
            $ipnRequest->getCaptureDetails()->getCaptureStatus()->getState());
142
    }
143
144
    /**
145
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnPaymentRefundRequestTransfer $ipnRequest
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...ntRefundRequestTransfer 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...
146
     *
147
     * @throws IpnHandlerNotFoundException
148
     *
149
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface
150
     */
151
    protected function createIpnPaymentRefundHandler(AbstractTransfer $ipnRequest)
152
    {
153
        if ($ipnRequest->getRefundDetails()->getRefundStatus()->getIsDeclined()) {
0 ignored issues
show
Bug introduced by
The method getRefundDetails() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

153
        if ($ipnRequest->/** @scrutinizer ignore-call */ getRefundDetails()->getRefundStatus()->getIsDeclined()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
            return new IpnPaymentRefundDeclineHandler(
155
                $this->omsFacade,
156
                $this->amazonpayQueryContainer,
157
                $this->ipnRequestLogger
158
            );
159
        } elseif ($ipnRequest->getRefundDetails()->getRefundStatus()->getIsCompleted()) {
160
            return new IpnPaymentRefundCompletedHandler(
161
                $this->omsFacade,
162
                $this->amazonpayQueryContainer,
163
                $this->ipnRequestLogger
164
            );
165
        }
166
167
        throw new IpnHandlerNotFoundException('No IPN handler for payment refund and status ' .
168
            $ipnRequest->getRefundDetails()->getRefundStatus()->getState());
169
    }
170
171
    /**
172
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer | \Generated\Shared\Transfer\AmazonpayIpnOrderReferenceNotificationTransfer $ipnRequest
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...nceNotificationTransfer 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...
173
     *
174
     * @throws IpnHandlerNotFoundException
175
     *
176
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Ipn\IpnRequestHandlerInterface
177
     */
178
    protected function createIpnOrderReferenceHandler(AbstractTransfer $ipnRequest)
179
    {
180
        if ($ipnRequest->getOrderReferenceStatus()->getIsOpen()) {
0 ignored issues
show
Bug introduced by
The method getOrderReferenceStatus() does not exist on Spryker\Shared\Kernel\Transfer\AbstractTransfer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

180
        if ($ipnRequest->/** @scrutinizer ignore-call */ getOrderReferenceStatus()->getIsOpen()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
            return new IpnOrderReferenceOpenHandler(
182
                $this->omsFacade,
183
                $this->amazonpayQueryContainer,
184
                $this->ipnRequestLogger
185
            );
186
        }
187
188
        if ($ipnRequest->getOrderReferenceStatus()->getIsClosed()) {
189
            if ($ipnRequest->getOrderReferenceStatus()->getIsClosedByAmazon()) {
190
                return new IpnOrderReferenceClosedHandler(
191
                    $this->omsFacade,
192
                    $this->amazonpayQueryContainer,
193
                    $this->ipnRequestLogger
194
                );
195
            } else {
196
                return new IpnEmptyHandler(
197
                    $this->omsFacade,
0 ignored issues
show
Unused Code introduced by
The call to SprykerEco\Zed\Amazonpay...yHandler::__construct() has too many arguments starting with $this->omsFacade. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

197
                return /** @scrutinizer ignore-call */ new IpnEmptyHandler(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
198
                    $this->amazonpayQueryContainer,
199
                    $this->ipnRequestLogger
200
                );
201
            }
202
        }
203
204
        if ($ipnRequest->getOrderReferenceStatus()->getIsSuspended()) {
205
            return new IpnOrderReferenceSuspendedHandler(
206
                $this->omsFacade,
207
                $this->amazonpayQueryContainer,
208
                $this->ipnRequestLogger
209
            );
210
        }
211
212
        throw new IpnHandlerNotFoundException('No IPN handler for order reference and status ' .
213
            $ipnRequest->getOrderReferenceStatus()->getState());
214
    }
215
216
}
217