mapFirstDataPaymentToQuote()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 2
nc 2
nop 2
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\Mapper;
9
10
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...
11
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...
12
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer 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\RestCheckoutRequestAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...questAttributesTransfer 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 Generated\Shared\Transfer\RestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestPaymentTransfer 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...
15
16
class FirstDataPaymentQuoteMapper implements FirstDataPaymentQuoteMapperInterface
17
{
18
    /**
19
     * @param \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer
20
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
21
     *
22
     * @return \Generated\Shared\Transfer\QuoteTransfer
23
     */
24
    public function mapFirstDataPaymentToQuote(
25
        RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer,
26
        QuoteTransfer $quoteTransfer
27
    ): QuoteTransfer {
28
        $restPaymentTransfers = $restCheckoutRequestAttributesTransfer->getPayments();
29
30
        if (!$restPaymentTransfers->count()) {
31
            return $quoteTransfer;
32
        }
33
34
        $paymentTransfer = $this->createPaymentTransfer(
35
            $restPaymentTransfers->getIterator()->current(),
36
            $restCheckoutRequestAttributesTransfer
37
        );
38
39
        $quoteTransfer->setPayment($paymentTransfer);
40
41
        return $quoteTransfer;
42
    }
43
44
    /**
45
     * @param \Generated\Shared\Transfer\RestPaymentTransfer $restPaymentTransfer
46
     * @param \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer
47
     *
48
     * @return \Generated\Shared\Transfer\PaymentTransfer
49
     */
50
    protected function createPaymentTransfer(
51
        RestPaymentTransfer $restPaymentTransfer,
52
        RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer
53
    ): PaymentTransfer {
54
        $paymentTransfer = (new PaymentTransfer())->fromArray($restPaymentTransfer->toArray(), true);
55
        $firstDataTransfer = (new FirstDataTransfer())
56
            ->setFirstDataTransactionData($restCheckoutRequestAttributesTransfer->getFirstDataTransactionData());
57
58
        $paymentTransfer->setPaymentProvider($restPaymentTransfer->getPaymentProviderName())
59
            ->setPaymentMethod($restPaymentTransfer->getPaymentMethodName())
60
            ->setFirstDataCreditCard($firstDataTransfer);
61
62
        return $paymentTransfer;
63
    }
64
}
65