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

HeidelpayEasycreditStep::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 Spryker\Shared\Kernel\Transfer\AbstractTransfer;
11
use Spryker\Yves\StepEngine\Dependency\Step\StepWithExternalRedirectInterface;
12
use SprykerEco\Shared\Heidelpay\HeidelpayConfig;
13
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...
14
use Symfony\Component\HttpFoundation\Request;
15
16
class HeidelpayEasycreditStep extends AbstractBaseStep implements StepWithExternalRedirectInterface
17
{
18
    public const HEIDELPAY_EASYCREDIT_STEP_ROUTE = 'HEIDELPAY_EASYCREDIT_STEP_ROUTE';
19
20
    /**
21
     * @var string
22
     */
23
    protected $externalRedirectUrl;
24
25
    /**
26
     * @param string $stepRoute
27
     * @param string $escapeRoute
28
     */
29
    public function __construct(
30
        string $stepRoute,
31
        string $escapeRoute
32
    ) {
33
        parent::__construct($stepRoute, $escapeRoute);
34
    }
35
36
    /**
37
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer $quoteTransfer
38
     *
39
     * @return bool
40
     */
41
    public function requireInput(AbstractTransfer $quoteTransfer)
42
    {
43
        return false;
44
    }
45
46
    /**
47
     * Empty quote transfer and mark logged in customer as "dirty" to force update it in the next request.
48
     *
49
     * @param \Symfony\Component\HttpFoundation\Request $request
50
     * @param \Generated\Shared\Transfer\QuoteTransfer $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...
51
     *
52
     * @return \Generated\Shared\Transfer\QuoteTransfer|\Spryker\Shared\Kernel\Transfer\AbstractTransfer
53
     */
54
    public function execute(Request $request, AbstractTransfer $quoteTransfer)
55
    {
56
        if ($this->isEasyCreditPaymentMethod($quoteTransfer) === false) {
57
            return $quoteTransfer;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $quoteTransfer returns the type Spryker\Shared\Kernel\Transfer\AbstractTransfer which is incompatible with the return type mandated by Spryker\Yves\StepEngine\...tepInterface::execute() of Generated\Shared\Transfer\QuoteTransfer.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
58
        }
59
60
        $this->externalRedirectUrl = $quoteTransfer->getHeidelpayPayment()->getExternalRedirectUrl();
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

60
        $this->externalRedirectUrl = $quoteTransfer->/** @scrutinizer ignore-call */ getHeidelpayPayment()->getExternalRedirectUrl();

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
62
        return $quoteTransfer;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $quoteTransfer returns the type Spryker\Shared\Kernel\Transfer\AbstractTransfer which is incompatible with the return type mandated by Spryker\Yves\StepEngine\...tepInterface::execute() of Generated\Shared\Transfer\QuoteTransfer.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getExternalRedirectUrl()
69
    {
70
        return $this->externalRedirectUrl;
71
    }
72
73
    /**
74
     * @param \Spryker\Shared\Kernel\Transfer\AbstractTransfer|\Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
75
     *
76
     * @return bool
77
     */
78
    public function postCondition(AbstractTransfer $quoteTransfer)
79
    {
80
        return true;
81
    }
82
83
    /**
84
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
85
     *
86
     * @return bool
87
     */
88
    protected function isEasyCreditPaymentMethod(AbstractTransfer $quoteTransfer): bool
89
    {
90
        $result = ($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

90
        $result = ($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...
91
            && $quoteTransfer->getPayment()->getPaymentSelection() === HeidelpayConfig::PAYMENT_METHOD_EASY_CREDIT);
92
93
        return $result;
94
    }
95
}
96