Passed
Push — dev ( 65ef69...e609af )
by Aleksey
05:20
created

HeidelpayEasycreditInitializeStep::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\Yves\Heidelpay\CheckoutPage\Process\Steps;
9
10
use Generated\Shared\Transfer\HeidelpayPaymentTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfer\HeidelpayPaymentTransfer 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\HeidelpayResponseTransfer;
1 ignored issue
show
Bug introduced by
The type Generated\Shared\Transfe...idelpayResponseTransfer 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\PaymentTransfer;
1 ignored issue
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...
13
use Generated\Shared\Transfer\QuoteTransfer;
1 ignored issue
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...
14
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
15
use SprykerEco\Client\Heidelpay\HeidelpayClientInterface;
16
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
17
use SprykerShop\Yves\CheckoutPage\Process\Steps\AbstractBaseStep;
1 ignored issue
show
Bug introduced by
The type SprykerShop\Yves\Checkou...\Steps\AbstractBaseStep 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...
18
use Symfony\Component\HttpFoundation\Request;
19
20
class HeidelpayEasycreditInitializeStep extends AbstractBaseStep
21
{
22
    /**
23
     * @var \SprykerEco\Client\Heidelpay\HeidelpayClientInterface
24
     */
25
    protected $heidelpayClient;
26
27
    /**
28
     * @var string
29
     */
30
    protected $externalRedirectUrl;
31
32
    /**
33
     * @param string $stepRoute
34
     * @param string $escapeRoute
35
     * @param \SprykerEco\Client\Heidelpay\HeidelpayClientInterface $heidelpayClient
36
     */
37
    public function __construct(
38
        string $stepRoute,
39
        string $escapeRoute,
40
        HeidelpayClientInterface $heidelpayClient
41
    ) {
42
        parent::__construct($stepRoute, $escapeRoute);
43
44
        $this->heidelpayClient = $heidelpayClient;
45
    }
46
47
    /**
48
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $quoteTransfer
49
     *
50
     * @return bool
51
     */
52
    public function requireInput(AbstractTransfer $quoteTransfer)
53
    {
54
        return false;
55
    }
56
57
    /**
58
     * Empty quote transfer and mark logged in customer as "dirty" to force update it in the next request.
59
     *
60
     * @param \Symfony\Component\HttpFoundation\Request $request
61
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
62
     *
63
     * @return \Generated\Shared\Transfer\QuoteTransfer|\Spryker\Shared\Kernel\Transfer\AbstractTransfer
64
     */
65
    public function execute(Request $request, AbstractTransfer $quoteTransfer)
66
    {
67
        $heidelpayPaymentTransfer = $quoteTransfer->getHeidelpayPayment();
0 ignored issues
show
Bug introduced by
The method getHeidelpayPayment() 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

67
        /** @scrutinizer ignore-call */ 
68
        $heidelpayPaymentTransfer = $quoteTransfer->getHeidelpayPayment();

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...
68
69
        if ($heidelpayPaymentTransfer !== null
70
            && $heidelpayPaymentTransfer->getLegalText() !== null
71
            && $heidelpayPaymentTransfer->getExternalRedirectUrl() !== null
72
        ) {
73
            return $quoteTransfer;
74
        }
75
76
        $easyCreditInitializeResponse = $this->getEasyCreditInitializeResponse($quoteTransfer);
77
78
        if ($easyCreditInitializeResponse->getIsSuccess() === true) {
79
            if (!$quoteTransfer->getHeidelpayPayment()) {
80
                $quoteTransfer->setHeidelpayPayment(new HeidelpayPaymentTransfer());
0 ignored issues
show
Bug introduced by
The method setHeidelpayPayment() 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

80
                $quoteTransfer->/** @scrutinizer ignore-call */ 
81
                                setHeidelpayPayment(new HeidelpayPaymentTransfer());

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...
81
            }
82
            $quoteTransfer->getHeidelpayPayment()->setLegalText($easyCreditInitializeResponse->getLegalText());
83
            $quoteTransfer->getHeidelpayPayment()->setExternalRedirectUrl($easyCreditInitializeResponse->getPaymentFormUrl());
84
        }
85
86
        return $quoteTransfer;
87
    }
88
89
    /**
90
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer|\Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
91
     *
92
     * @return bool
93
     */
94
    public function postCondition(AbstractTransfer $quoteTransfer)
95
    {
96
        return true;
97
    }
98
99
    /**
100
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
101
     *
102
     * @return \Generated\Shared\Transfer\HeidelpayResponseTransfer
103
     */
104
    protected function getEasyCreditInitializeResponse(QuoteTransfer $quoteTransfer): HeidelpayResponseTransfer
105
    {
106
        $quoteTransferMock = clone($quoteTransfer);
107
        $quoteTransferMock->setPayment(
108
            (new PaymentTransfer())
109
                ->setPaymentMethod(HeidelpayConfig::PAYMENT_METHOD_EASY_CREDIT)
110
        );
111
112
        return $this->heidelpayClient->sendHeidelpayEasycreditInitializeRequest($quoteTransferMock);
113
    }
114
}
115