Completed
Push — master ( 9db63e...40913a )
by Oleksandr
24s queued 13s
created

KlarnaDataProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 11 2
A __construct() 0 3 1
A getOptions() 0 23 2
A getKlarnaPayMethods() 0 6 1
A getPayMethods() 0 4 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\Transfer\AbstractTransfer;
13
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface;
14
use SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface;
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 \SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface
46
     */
47
    protected $storeClient;
48
49
    /**
50
     * @param \SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface $storeClient
51
     */
52
    public function __construct(PayoneToStoreClientInterface $storeClient)
53
    {
54
        $this->storeClient = $storeClient;
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 array
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
        $currentStoreCountryList = $this->storeClient->getCurrentStore()->getCountries();
85
        $firstCurrentStoreCountry = reset($currentStoreCountryList);
86
87
        return [
88
            KlarnaSubForm::PAY_METHOD_CHOICES => $this->getPayMethods(),
89
            KlarnaSubForm::BILLING_ADDRESS_DATA => [
90
                static::GIVEN_NAME => $billingAddress->getFirstName(),
91
                static::FAMILY_NAME => $billingAddress->getLastName(),
92
                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

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