Passed
Push — feature/eco-574/eco-2266-check... ( efd21d )
by Aleksey
08:13
created

AfterpayFactory::createAfterpayAuthorizeWorkflow()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
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\Afterpay;
9
10
use Spryker\Yves\Kernel\AbstractFactory;
11
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface;
12
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface;
13
use SprykerEco\Client\Afterpay\AfterpayClientInterface;
14
use SprykerEco\Shared\Afterpay\AfterpayConfig;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, SprykerEco\Yves\Afterpay\AfterpayConfig. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use SprykerEco\Shared\Afterpay\AfterpayConstants;
16
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface;
17
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\OneStepAuthorizeWorkflow;
18
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStep;
19
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStepInterface;
20
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStep;
21
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStepInterface;
0 ignored issues
show
Bug introduced by
The type SprykerEco\Yves\Afterpay...ormsFilterStepInterface 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...
22
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\TwoStepsAuthorizeWorkflow;
23
use SprykerEco\Yves\Afterpay\Dependency\Client\AfterpayToQuoteClientInterface;
24
use SprykerEco\Yves\Afterpay\Form\DataProvider\InvoiceDataProvider;
25
use SprykerEco\Yves\Afterpay\Form\InvoiceSubForm;
26
27
/**
28
 * @method \SprykerEco\Yves\Afterpay\AfterpayConfig getConfig()
29
 */
30
class AfterpayFactory extends AbstractFactory
31
{
32
    /**
33
     * @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface
34
     */
35
    public function createInvoiceForm(): SubFormInterface
36
    {
37
        return new InvoiceSubForm();
38
    }
39
40
    /**
41
     * @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface
42
     */
43
    public function createInvoiceFormDataProvider(): StepEngineFormDataProviderInterface
44
    {
45
        return new InvoiceDataProvider();
46
    }
47
48
    /**
49
     * @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface
50
     */
51
    public function createAfterpayAuthorizeWorkflow()
52
    {
53
        $authorizeWorkflow = $this->getConfig()->getAfterpayAuthorizeWorkflow();
54
55
        switch ($authorizeWorkflow) {
56
            case AfterpayConfig::AFTERPAY_AUTHORIZE_WORKFLOW_ONE_STEP:
57
                return $this->createOneStepAuthorizeWorkflow();
58
            case AfterpayConfig::AFTERPAY_AUTHORIZE_WORKFLOW_TWO_STEPS:
59
                return $this->createTwoStepsAuthorizeWorkflow();
60
            default:
61
                return $this->createOneStepAuthorizeWorkflow();
62
        }
63
    }
64
65
    /**
66
     * @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface
67
     */
68
    public function createOneStepAuthorizeWorkflow(): AfterpayAuthorizeWorkflowInterface
69
    {
70
        return new OneStepAuthorizeWorkflow();
71
    }
72
73
    /**
74
     * @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface
75
     */
76
    public function createTwoStepsAuthorizeWorkflow(): AfterpayAuthorizeWorkflowInterface
77
    {
78
        return new TwoStepsAuthorizeWorkflow(
79
            $this->createAvailablePaymentMethodsStep(),
80
            $this->createPaymentSubformsFilter()
81
        );
82
    }
83
84
    /**
85
     * @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStepInterface
86
     */
87
    public function createAvailablePaymentMethodsStep(): AvailablePaymentMethodsStepInterface
88
    {
89
        return new AvailablePaymentMethodsStep($this->getAfterpayClient());
90
    }
91
92
    /**
93
     * @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStepInterface
94
     */
95
    public function createPaymentSubformsFilter(): PaymentSubFormsFilterStepInterface
96
    {
97
        return new PaymentSubFormsFilterStep(
98
            $this->getConfig(),
99
            $this->getQuoteClient()
100
        );
101
    }
102
103
    /**
104
     * @return \SprykerEco\Client\Afterpay\AfterpayClientInterface
105
     */
106
    public function getAfterpayClient(): AfterpayClientInterface
107
    {
108
        return $this->getProvidedDependency(AfterpayDependencyProvider::CLIENT_AFTERPAY);
109
    }
110
111
    /**
112
     * @return \SprykerEco\Yves\Afterpay\Dependency\Client\AfterpayToQuoteClientInterface
113
     */
114
    public function getQuoteClient(): AfterpayToQuoteClientInterface
115
    {
116
        return $this->getProvidedDependency(AfterpayDependencyProvider::CLIENT_QUOTE);
117
    }
118
}
119