AbstractTransactionCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A executeHandlers() 0 14 4
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 Generated\Shared\Transfer\AmazonpayCallTransfer;
11
12
abstract class AbstractTransactionCollection
13
{
14
    /**
15
     * @var \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface[]
16
     */
17
    protected $transactionHandlers;
18
19
    /**
20
     * @param \SprykerEco\Zed\AmazonPay\Business\Payment\Handler\Transaction\AmazonpayTransactionInterface[] $transactionHandlers
21
     */
22
    public function __construct(
23
        array $transactionHandlers
24
    ) {
25
        $this->transactionHandlers = $transactionHandlers;
26
    }
27
28
    /**
29
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonPayCallTransfer
30
     *
31
     * @return \Generated\Shared\Transfer\AmazonpayCallTransfer
32
     */
33
    protected function executeHandlers(AmazonpayCallTransfer $amazonPayCallTransfer)
34
    {
35
        $amazonPayCallTransfer->getAmazonpayPayment()->setResponseHeader(null);
36
37
        foreach ($this->transactionHandlers as $transactionHandler) {
38
            $amazonPayCallTransfer = $transactionHandler->execute($amazonPayCallTransfer);
39
40
            if ($amazonPayCallTransfer->getAmazonpayPayment()->getResponseHeader() &&
41
                !$amazonPayCallTransfer->getAmazonpayPayment()->getResponseHeader()->getIsSuccess()) {
42
                return $amazonPayCallTransfer;
43
            }
44
        }
45
46
        return $amazonPayCallTransfer;
47
    }
48
}
49