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

createCaptureOrderTransaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
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\Payment\Handler\Transaction;
9
10
use SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface;
11
use SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactoryInterface;
12
use SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface;
13
use SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface;
14
15
class TransactionFactory implements TransactionFactoryInterface
16
{
17
18
    /**
19
     * @var \SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactory
20
     */
21
    protected $adapterFactory;
22
23
    /**
24
     * @var \SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface
25
     */
26
    protected $config;
27
28
    /**
29
     * @var \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface
30
     */
31
    protected $amazonpayQueryContainer;
32
33
    /**
34
     * @var \SprykerEco\Zed\Amazonpay\Business\Payment\Method\AmazonpayInterface
1 ignored issue
show
Bug introduced by
The type SprykerEco\Zed\Amazonpay...thod\AmazonpayInterface 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...
35
     */
36
    protected $amazonpayPaymentMethod;
37
38
    /**
39
     * @var \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface
40
     */
41
    protected $transactionLogger;
42
43
    /**
44
     * @param \SprykerEco\Zed\Amazonpay\Business\Api\Adapter\AdapterFactoryInterface $adapterFactory
45
     * @param \SprykerEco\Shared\Amazonpay\AmazonpayConfigInterface $config
46
     * @param \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\Logger\TransactionLoggerInterface $transactionLogger
47
     * @param \SprykerEco\Zed\Amazonpay\Persistence\AmazonpayQueryContainerInterface $amazonpayQueryContainer
48
     */
49
    public function __construct(
50
        AdapterFactoryInterface $adapterFactory,
51
        AmazonpayConfigInterface $config,
52
        TransactionLoggerInterface $transactionLogger,
53
        AmazonpayQueryContainerInterface $amazonpayQueryContainer
54
    ) {
55
        $this->adapterFactory = $adapterFactory;
0 ignored issues
show
Documentation Bug introduced by
$adapterFactory is of type SprykerEco\Zed\Amazonpay...AdapterFactoryInterface, but the property $adapterFactory was declared to be of type SprykerEco\Zed\Amazonpay...\Adapter\AdapterFactory. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
56
        $this->config = $config;
57
        $this->transactionLogger = $transactionLogger;
58
        $this->amazonpayQueryContainer = $amazonpayQueryContainer;
59
    }
60
61
    /**
62
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionInterface
63
     */
64
    public function createConfirmOrderReferenceTransaction()
65
    {
66
        return new ConfirmOrderReferenceTransaction(
67
            $this->adapterFactory->createConfirmOrderReferenceAmazonpayAdapter(),
68
            $this->config,
69
            $this->transactionLogger
70
        );
71
    }
72
73
    /**
74
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionInterface
75
     */
76
    public function createSetOrderReferenceTransaction()
77
    {
78
        return new SetOrderReferenceDetailsTransaction(
79
            $this->adapterFactory->createSetOrderReferenceDetailsAmazonpayAdapter(),
80
            $this->config,
81
            $this->transactionLogger
82
        );
83
    }
84
85
    /**
86
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionInterface
87
     */
88
    public function createGetOrderReferenceDetailsTransaction()
89
    {
90
        return new GetOrderReferenceDetailsTransaction(
91
            $this->adapterFactory->createGetOrderReferenceDetailsAmazonpayAdapter(),
92
            $this->config,
93
            $this->transactionLogger
94
        );
95
    }
96
97
    /**
98
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionInterface
99
     */
100
    public function createCancelPreOrderTransaction()
101
    {
102
        return new CancelPreOrderTransaction(
0 ignored issues
show
Bug Best Practice introduced by
The expression return new SprykerEco\Ze...his->transactionLogger) returns the type SprykerEco\Zed\Amazonpay...ncelPreOrderTransaction which is incompatible with the return type mandated by SprykerEco\Zed\Amazonpay...elPreOrderTransaction() of SprykerEco\Zed\Amazonpay...derTransactionInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
103
            $this->adapterFactory->createCancelPreOrderAdapter(),
104
            $this->config,
105
            $this->transactionLogger
106
        );
107
    }
108
109
    /**
110
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
111
     */
112
    public function createCancelOrderTransaction()
113
    {
114
        return new OrderTransactionCollection(
115
            [
116
                $this->createRefundOrderTransaction(),
117
                $this->createCancelOrderTransactionObject(),
118
            ]
119
        );
120
    }
121
122
    /**
123
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
124
     */
125
    protected function createCancelOrderTransactionObject()
126
    {
127
        return new CancelOrderTransaction(
128
            $this->adapterFactory->createCancelOrderAdapter(),
129
            $this->config,
130
            $this->transactionLogger,
131
            $this->amazonpayQueryContainer
132
        );
133
    }
134
135
    /**
136
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionInterface
137
     */
138
    public function createAuthorizeOrderTransaction()
139
    {
140
        return new AuthorizeOrderTransaction(
141
            $this->adapterFactory->createAuthorizeQuoteAdapter(),
142
            $this->config,
143
            $this->transactionLogger
144
        );
145
    }
146
147
    /**
148
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
149
     */
150
    public function createReauthorizeExpiredOrderTransaction()
151
    {
152
        return new OrderTransactionCollection(
153
            [
154
                $this->createReauthorizeOrderTransactionObject(),
155
                $this->createUpdateOrderAuthorizationStatusTransaction(),
156
            ]
157
        );
158
    }
159
160
    /**
161
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
162
     */
163
    protected function createReauthorizeOrderTransactionObject()
164
    {
165
        return new ReauthorizeOrderTransaction(
166
            $this->adapterFactory->createAuthorizeCaptureNowOrderAdapter(),
167
            $this->config,
168
            $this->transactionLogger,
169
            $this->amazonpayQueryContainer
170
        );
171
    }
172
173
    /**
174
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
175
     */
176
    public function createReauthorizeSuspendedOrderTransaction()
177
    {
178
        return new ReauthorizeOrderTransaction(
179
            $this->adapterFactory->createAuthorizeOrderAdapter(),
180
            $this->config,
181
            $this->transactionLogger,
182
            $this->amazonpayQueryContainer
183
        );
184
    }
185
186
    /**
187
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
188
     */
189
    protected function createCaptureOrderTransaction()
190
    {
191
        return new CaptureOrderTransaction(
192
            $this->adapterFactory->createCaptureOrderAdapter(),
193
            $this->config,
194
            $this->transactionLogger,
195
            $this->amazonpayQueryContainer
196
        );
197
    }
198
199
    /**
200
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
201
     */
202
    public function createCaptureAuthorizedTransaction()
203
    {
204
        return new OrderTransactionCollection(
205
            [
206
                $this->createUpdateOrderAuthorizationStatusTransaction(),
207
                $this->createCaptureOrderTransaction(),
208
            ]
209
        );
210
    }
211
212
    /**
213
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
214
     */
215
    public function createCloseOrderTransaction()
216
    {
217
        return new CloseOrderTransaction(
218
            $this->adapterFactory->createCloseOrderAdapter(),
219
            $this->config,
220
            $this->transactionLogger,
221
            $this->amazonpayQueryContainer
222
        );
223
    }
224
225
    /**
226
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
227
     */
228
    public function createRefundOrderTransaction()
229
    {
230
        return new RefundOrderTransaction(
231
            $this->adapterFactory->createRefundOrderAdapter(),
232
            $this->config,
233
            $this->transactionLogger,
234
            $this->amazonpayQueryContainer,
235
            $this->amazonpayPaymentMethod
0 ignored issues
show
Unused Code introduced by
The call to SprykerEco\Zed\Amazonpay...nsaction::__construct() has too many arguments starting with $this->amazonpayPaymentMethod. ( Ignorable by Annotation )

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

235
        return /** @scrutinizer ignore-call */ new RefundOrderTransaction(

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...
236
        );
237
    }
238
239
    /**
240
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
241
     */
242
    public function createUpdateOrderRefundStatusTransaction()
243
    {
244
        return new UpdateOrderRefundStatusTransaction(
245
            $this->adapterFactory->createGetOrderRefundDetailsAdapter(),
246
            $this->config,
247
            $this->transactionLogger,
248
            $this->amazonpayQueryContainer
249
        );
250
    }
251
252
    /**
253
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
254
     */
255
    public function createUpdateOrderAuthorizationStatusTransaction()
256
    {
257
        return new UpdateOrderAuthorizationStatusTransaction(
258
            $this->adapterFactory->createGetOrderAuthorizationDetailsAdapter(),
259
            $this->config,
260
            $this->transactionLogger,
261
            $this->amazonpayQueryContainer
262
        );
263
    }
264
265
    /**
266
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\OrderTransactionInterface
267
     */
268
    public function createUpdateOrderCaptureStatusTransaction()
269
    {
270
        return new UpdateOrderCaptureStatusTransaction(
271
            $this->adapterFactory->createGetOrderCaptureDetailsAdapter(),
272
            $this->config,
273
            $this->transactionLogger,
274
            $this->amazonpayQueryContainer
275
        );
276
    }
277
278
    /**
279
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\HandleDeclinedOrderTransaction
280
     */
281
    public function createHandleDeclinedOrderTransaction()
282
    {
283
        return new HandleDeclinedOrderTransaction(
284
            $this->createGetOrderReferenceDetailsTransaction(),
285
            $this->createCancelPreOrderTransaction()
286
        );
287
    }
288
289
    /**
290
     * @return \SprykerEco\Zed\Amazonpay\Business\Payment\Handler\Transaction\QuoteTransactionCollection
291
     */
292
    public function createConfirmPurchaseTransaction()
293
    {
294
        return new QuoteTransactionCollection(
295
            [
296
                $this->createSetOrderReferenceTransaction(),
297
                $this->createConfirmOrderReferenceTransaction(),
298
                $this->createGetOrderReferenceDetailsTransaction(),
299
                $this->createAuthorizeOrderTransaction(),
300
                $this->createHandleDeclinedOrderTransaction(),
301
            ]
302
        );
303
    }
304
305
}
306