OrderExpander::loadPaymentDataByOrder()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 23
rs 9.8666
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\FirstData\Business\Expander;
9
10
use Generated\Shared\Transfer\FirstDataTransactionDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...TransactionDataTransfer 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\FirstDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\FirstDataTransfer 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
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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...
13
use Generated\Shared\Transfer\PaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentTransfer 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\FirstData\FirstDataConfig;
15
use SprykerEco\Zed\FirstData\Persistence\FirstDataRepositoryInterface;
16
17
class OrderExpander implements OrderExpanderInterface
18
{
19
    /**
20
     * @var \SprykerEco\Zed\FirstData\Persistence\FirstDataRepositoryInterface
21
     */
22
    protected $firstDataRepository;
23
24
    /**
25
     * @param \SprykerEco\Zed\FirstData\Persistence\FirstDataRepositoryInterface $firstDataRepository
26
     */
27
    public function __construct(FirstDataRepositoryInterface $firstDataRepository)
28
    {
29
        $this->firstDataRepository = $firstDataRepository;
30
    }
31
32
    /**
33
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
34
     *
35
     * @return \Generated\Shared\Transfer\OrderTransfer
36
     */
37
    public function loadPaymentDataByOrder(OrderTransfer $orderTransfer): OrderTransfer
38
    {
39
        $paymentTransfer = $this->getFirstDataPaymentFromOrder($orderTransfer);
40
41
        if ($paymentTransfer === null) {
42
            return $orderTransfer;
43
        }
44
45
        $paymentFirstDataTransfer = $this->firstDataRepository
46
            ->findPaymentFirstDataByIdSalesOrder($orderTransfer->getIdSalesOrderOrFail());
47
48
        if ($paymentFirstDataTransfer === null) {
49
            return $orderTransfer;
50
        }
51
52
        $paymentTransfer->setFirstDataCreditCard(
53
            (new FirstDataTransfer())
54
                ->setFirstDataTransactionData(
55
                    (new FirstDataTransactionDataTransfer())->fromArray($paymentFirstDataTransfer->toArray(), true)
56
                )
57
        );
58
59
        return $orderTransfer;
60
    }
61
62
    /**
63
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
64
     *
65
     * @return \Generated\Shared\Transfer\PaymentTransfer|null
66
     */
67
    protected function getFirstDataPaymentFromOrder(OrderTransfer $orderTransfer): ?PaymentTransfer
68
    {
69
        foreach ($orderTransfer->getPayments() as $payment) {
70
            if ($payment->getPaymentProvider() === FirstDataConfig::PAYMENT_PROVIDER_NAME_KEY) {
71
                return $payment;
72
            }
73
        }
74
75
        return null;
76
    }
77
}
78