Passed
Push — master ( a2100c...af4f13 )
by Andrey
06:37
created

AbstractConverter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertPriceToTransfer() 0 8 1
B convertStatusToTransfer() 0 53 6
A updateNameData() 0 13 2
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\Api\Converter;
9
10
use Generated\Shared\Transfer\AmazonpayPriceTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayPriceTransfer 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\AmazonpayStatusTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\AmazonpayStatusTransfer 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 SprykerEco\Shared\Amazonpay\AmazonpayConstants;
13
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
14
15
abstract class AbstractConverter
16
{
17
18
    const STATUS_DECLINED = 'Declined';
19
    const STATUS_PENDING = 'Pending';
20
    const STATUS_OPEN = 'Open';
21
    const STATUS_CLOSED = 'Closed';
22
    const STATUS_COMPLETED = 'Completed';
23
    const STATUS_SUSPENDED = 'Suspended';
24
25
    /**
26
     * @param array $priceData
27
     *
28
     * @return \Generated\Shared\Transfer\AmazonpayPriceTransfer
29
     */
30
    protected function convertPriceToTransfer(array $priceData)
31
    {
32
        $priceTransfer = new AmazonpayPriceTransfer();
33
34
        $priceTransfer->setAmount($priceData['Amount']);
35
        $priceTransfer->setCurrencyCode($priceData['CurrencyCode']);
36
37
        return $priceTransfer;
38
    }
39
40
    /**
41
     * @param array $statusData
42
     *
43
     * @return \Generated\Shared\Transfer\AmazonpayStatusTransfer
44
     */
45
    protected function convertStatusToTransfer(array $statusData)
46
    {
47
        $status = new AmazonpayStatusTransfer();
48
49
        if (!empty($statusData['LastUpdateTimestamp'])) {
50
            $status->setLastUpdateTimestamp($statusData['LastUpdateTimestamp']);
51
        }
52
53
        $status->setState($statusData['State']);
54
55
        if (!empty($statusData['ReasonCode'])) {
56
            $status->setReasonCode($statusData['ReasonCode']);
57
            $status->setIsReauthorizable(
58
                $statusData['ReasonCode'] === AmazonpayConstants::REASON_CODE_SELLER_CLOSED
59
                || $statusData['ReasonCode'] === AmazonpayConstants::REASON_CODE_EXPIRED_UNUSED
60
            );
61
62
            $status->setIsPaymentMethodInvalid(
63
                $statusData['ReasonCode'] === AmazonpayConstants::REASON_CODE_PAYMENT_METHOD_INVALID
64
            );
65
66
            $status->setIsClosedByAmazon(
67
                $statusData['ReasonCode'] === AmazonpayConstants::REASON_CODE_AMAZON_CLOSED
68
            );
69
        }
70
71
        if ($statusData['State'] === static::STATUS_DECLINED) {
72
            $status->setIsSuspended($status->getIsPaymentMethodInvalid());
73
            $status->setIsDeclined(true);
74
        }
75
76
        if ($statusData['State'] === static::STATUS_SUSPENDED) {
77
            $status->setIsSuspended(true);
78
            $status->setIsDeclined(true);
79
        }
80
81
        $status->setIsPending(
82
            $statusData['State'] === static::STATUS_PENDING
83
        );
84
85
        $status->setIsOpen(
86
            $statusData['State'] === static::STATUS_OPEN
87
        );
88
89
        $status->setIsClosed(
90
            $statusData['State'] === static::STATUS_CLOSED
91
        );
92
93
        $status->setIsCompleted(
94
            $statusData['State'] === static::STATUS_COMPLETED
95
        );
96
97
        return $status;
98
    }
99
100
    /**
101
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $transfer
102
     * @param string $name
103
     *
104
     * @return \Spryker\Shared\Kernel\Transfer\AbstractTransfer
105
     */
106
    protected function updateNameData(AbstractTransfer $transfer, $name)
107
    {
108
        $names = explode(' ', $name, 2);
109
110
        if (count($names) >= 2) {
111
            $transfer->setFirstName($names[0]);
0 ignored issues
show
Bug introduced by
The method setFirstName() 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

111
            $transfer->/** @scrutinizer ignore-call */ 
112
                       setFirstName($names[0]);

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...
112
            $transfer->setLastName($names[1]);
0 ignored issues
show
Bug introduced by
The method setLastName() 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

112
            $transfer->/** @scrutinizer ignore-call */ 
113
                       setLastName($names[1]);

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...
113
        } else {
114
            $transfer->setFirstName($name);
115
            $transfer->setLastName($name);
116
        }
117
118
        return $transfer;
119
    }
120
121
}
122