__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 1
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\HeidelpayDirectDebitPaymentOptionsTransfer;
11
use Generated\Shared\Transfer\HeidelpayDirectDebitPaymentTransfer;
12
use Generated\Shared\Transfer\PaymentTransfer;
13
use Generated\Shared\Transfer\QuoteTransfer;
14
use Spryker\Shared\Kernel\Transfer\AbstractTransfer;
15
use Spryker\Yves\StepEngine\Dependency\Step\StepInterface;
16
use SprykerEco\Client\Heidelpay\HeidelpayClientInterface;
17
use SprykerShop\Yves\CheckoutPage\Process\Steps\AbstractBaseStep;
18
use Symfony\Component\HttpFoundation\Request;
19
20
class HeidelpayDirectDebitRegistrationStep extends AbstractBaseStep implements StepInterface
21
{
22
    /**
23
     * @var \SprykerEco\Client\Heidelpay\HeidelpayClientInterface
24
     */
25
    protected $heidelpayClient;
26
27
    /**
28
     * @param string $stepRoute
29
     * @param string $escapeRoute
30
     * @param \SprykerEco\Client\Heidelpay\HeidelpayClientInterface $heidelpayClient
31
     */
32
    public function __construct(
33
        string $stepRoute,
34
        string $escapeRoute,
35
        HeidelpayClientInterface $heidelpayClient
36
    ) {
37
        parent::__construct($stepRoute, $escapeRoute);
38
39
        $this->heidelpayClient = $heidelpayClient;
40
    }
41
42
    /**
43
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $quoteTransfer
44
     *
45
     * @return bool
46
     */
47
    public function requireInput(AbstractTransfer $quoteTransfer): bool
48
    {
49
        return false;
50
    }
51
52
    /**
53
     * @param \Symfony\Component\HttpFoundation\Request $request
54
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
55
     *
56
     * @return \Generated\Shared\Transfer\QuoteTransfer
57
     */
58
    public function execute(Request $request, AbstractTransfer $quoteTransfer): QuoteTransfer
59
    {
60
        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

60
        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...
61
            $quoteTransfer->setPayment(new 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

61
            $quoteTransfer->/** @scrutinizer ignore-call */ 
62
                            setPayment(new 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...
62
        }
63
64
        if ($quoteTransfer->getPayment()->getHeidelpayDirectDebit() !== null) {
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 type-hinted return Generated\Shared\Transfer\QuoteTransfer.
Loading history...
66
        }
67
68
        $directDebitPayment = $this->createDirectDebitPaymentTransfer($quoteTransfer);
69
        $quoteTransfer->getPayment()->setHeidelpayDirectDebit($directDebitPayment);
70
71
        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 type-hinted return Generated\Shared\Transfer\QuoteTransfer.
Loading history...
72
    }
73
74
    /**
75
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer|\Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
76
     *
77
     * @return bool
78
     */
79
    public function postCondition(AbstractTransfer $quoteTransfer): bool
80
    {
81
        return true;
82
    }
83
84
    /**
85
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
86
     *
87
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitPaymentTransfer
88
     */
89
    protected function createDirectDebitPaymentTransfer(QuoteTransfer $quoteTransfer): HeidelpayDirectDebitPaymentTransfer
90
    {
91
        return (new HeidelpayDirectDebitPaymentTransfer())
92
            ->setPaymentOptions(
93
                $this->getDirectDebitPaymentOptions($quoteTransfer)
94
            );
95
    }
96
97
    /**
98
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
99
     *
100
     * @return \Generated\Shared\Transfer\HeidelpayDirectDebitPaymentOptionsTransfer
101
     */
102
    protected function getDirectDebitPaymentOptions(QuoteTransfer $quoteTransfer): HeidelpayDirectDebitPaymentOptionsTransfer
103
    {
104
        return $this->heidelpayClient->getDirectDebitPaymentOptions($quoteTransfer);
105
    }
106
}
107