Completed
Pull Request — master (#64)
by
unknown
06:13 queued 10s
created

KlarnaDataProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 49
c 1
b 0
f 0
dl 0
loc 105
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 20 2
A getKlarnaPayMethods() 0 6 1
A getPayMethods() 0 4 1
A getData() 0 11 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\Payone\Form\DataProvider;
9
10
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...
11
use Generated\Shared\Transfer\PayonePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentTransfer 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 Spryker\Shared\Kernel\Store;
13
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
14
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface;
15
use SprykerEco\Yves\Payone\Form\KlarnaSubForm;
16
17
class KlarnaDataProvider implements StepEngineFormDataProviderInterface
18
{
19
    protected const ADDRESS_SEPARATOR = ' ';
20
21
    protected const GIVEN_NAME = 'given_name';
22
    protected const FAMILY_NAME = 'family_name';
23
    protected const EMAIL = 'email';
24
    protected const STREET_ADDRESS = 'street_address';
25
    protected const POSTAL_CODE = 'postal_code';
26
    protected const CITY = 'city';
27
    protected const COUNTRY = 'country';
28
    protected const PHONE = 'phone';
29
30
    protected const DATE_OF_BIRTH = 'date_of_birth';
31
32
    protected const SLICE_IT_PAY_METHOD = 'Slice it';
33
    protected const PAY_LATER_PAY_METHOD = 'Pay later';
34
    protected const PAY_NOW_PAY_METHOD = 'Pay now';
35
36
    protected const SLICE_IT_PAY_METHOD_CODE = 'KIS';
37
    protected const PAY_LATER_PAY_METHOD_CODE = 'KIV';
38
    protected const PAY_NOW_PAY_METHOD_CODE = 'KDD';
39
40
    protected const SLICE_IT_WIDGET_PAY_METHOD_CODE = 'pay_over_time';
41
    protected const PAY_LATER_WIDGET_PAY_METHOD_CODE = 'pay_later';
42
    protected const PAY_NOW_WIDGET_PAY_METHOD_CODE = 'pay_now';
43
44
    /**
45
     * @var \Spryker\Shared\Kernel\Store
46
     */
47
    protected $store;
48
49
    /**
50
     * @param \Spryker\Shared\Kernel\Store $store
51
     */
52
    public function __construct(Store $store)
53
    {
54
        $this->store = $store;
55
    }
56
57
    /**
58
     * @param \Generated\Shared\Transfer\QuoteTransfer $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...
59
     *
60
     * @return \Generated\Shared\Transfer\QuoteTransfer
61
     */
62
    public function getData(AbstractTransfer $quoteTransfer): AbstractTransfer
63
    {
64
        if ($quoteTransfer->getPayment() !== null) {
0 ignored issues
show
Bug introduced by
The method getPayment() 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

64
        if ($quoteTransfer->/** @scrutinizer ignore-call */ getPayment() !== null) {

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...
65
            return $quoteTransfer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $quoteTransfer returns the type Spryker\Shared\Kernel\Transfer\AbstractTransfer which is incompatible with the documented return type Generated\Shared\Transfer\QuoteTransfer.
Loading history...
66
        }
67
68
        $paymentTransfer = new PaymentTransfer();
69
        $paymentTransfer->setPayone(new PayonePaymentTransfer());
70
        $quoteTransfer->setPayment($paymentTransfer);
0 ignored issues
show
Bug introduced by
The method setPayment() 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

70
        $quoteTransfer->/** @scrutinizer ignore-call */ 
71
                        setPayment($paymentTransfer);

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...
71
72
        return $quoteTransfer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $quoteTransfer returns the type Spryker\Shared\Kernel\Transfer\AbstractTransfer which is incompatible with the documented return type Generated\Shared\Transfer\QuoteTransfer.
Loading history...
73
    }
74
75
    /**
76
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
77
     *
78
     * @return string[]
79
     */
80
    public function getOptions(AbstractTransfer $quoteTransfer): array
81
    {
82
        $billingAddress = $quoteTransfer->getBillingAddress();
0 ignored issues
show
Bug introduced by
The method getBillingAddress() 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

82
        /** @scrutinizer ignore-call */ 
83
        $billingAddress = $quoteTransfer->getBillingAddress();

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...
83
84
        return [
85
            KlarnaSubForm::PAY_METHOD_CHOICES => $this->getPayMethods(),
86
            KlarnaSubForm::BILLING_ADDRESS_DATA => [
87
                static::GIVEN_NAME => $billingAddress->getFirstName(),
88
                static::FAMILY_NAME => $billingAddress->getLastName(),
89
                static::EMAIL => $quoteTransfer->getCustomer()->getEmail(),
0 ignored issues
show
Bug introduced by
The method getCustomer() 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

89
                static::EMAIL => $quoteTransfer->/** @scrutinizer ignore-call */ getCustomer()->getEmail(),

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...
90
                static::STREET_ADDRESS => implode(self::ADDRESS_SEPARATOR, [$billingAddress->getAddress1(), $billingAddress->getAddress2()]),
91
                static::POSTAL_CODE => $billingAddress->getZipCode(),
92
                static::CITY => $billingAddress->getCity(),
93
                static::COUNTRY => $this->store->getCurrentCountry(),
94
                static::PHONE => $billingAddress->getPhone(),
95
            ],
96
            KlarnaSubForm::CUSTOMER_DATA => [
97
                static::DATE_OF_BIRTH => $quoteTransfer->getCustomer() ? $quoteTransfer->getCustomer()->getDateOfBirth() : null,
98
            ],
99
            KlarnaSubForm::WIDGET_PAY_METHODS => $this->getKlarnaPayMethods(),
100
        ];
101
    }
102
103
    /**
104
     * @return string[]
105
     */
106
    protected function getPayMethods(): array
107
    {
108
        return [
109
            static::PAY_LATER_PAY_METHOD => static::PAY_LATER_PAY_METHOD_CODE,
110
        ];
111
    }
112
113
    /**
114
     * @return array
115
     */
116
    protected function getKlarnaPayMethods(): array
117
    {
118
        return [
119
            static::SLICE_IT_PAY_METHOD_CODE => static::SLICE_IT_WIDGET_PAY_METHOD_CODE,
120
            static::PAY_LATER_PAY_METHOD_CODE => static::PAY_LATER_WIDGET_PAY_METHOD_CODE,
121
            static::PAY_NOW_PAY_METHOD_CODE => static::PAY_NOW_WIDGET_PAY_METHOD_CODE,
122
        ];
123
    }
124
}
125