Completed
Push — master ( c8e10c...47e8bc )
by
unknown
21s queued 16s
created

createMerchantSwitcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Spryker Marketplace License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerShop\Yves\MerchantSwitcherWidget;
9
10
use ArrayObject;
11
use Spryker\Shared\Kernel\Communication\Application;
12
use Spryker\Yves\Kernel\AbstractFactory;
13
use SprykerShop\Yves\MerchantSwitcherWidget\Cookie\SelectedMerchantCookie;
14
use SprykerShop\Yves\MerchantSwitcherWidget\Cookie\SelectedMerchantCookieInterface;
15
use SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSearchClientInterface;
16
use SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSwitcherClientInterface;
17
use SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToQuoteClientInterface;
18
use SprykerShop\Yves\MerchantSwitcherWidget\MerchantReader\MerchantReader;
19
use SprykerShop\Yves\MerchantSwitcherWidget\MerchantReader\MerchantReaderInterface;
20
use SprykerShop\Yves\MerchantSwitcherWidget\MerchantSwitcher\MerchantSwitcher;
21
use SprykerShop\Yves\MerchantSwitcherWidget\MerchantSwitcher\MerchantSwitcherInterface;
22
use Symfony\Component\HttpFoundation\Request;
23
24
/**
25
 * @method \SprykerShop\Yves\MerchantSwitcherWidget\MerchantSwitcherWidgetConfig getConfig()
26
 */
27
class MerchantSwitcherWidgetFactory extends AbstractFactory
28
{
29
    /**
30
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\MerchantReader\MerchantReaderInterface
31
     */
32
    public function createMerchantReader(): MerchantReaderInterface
33
    {
34
        return new MerchantReader(
35
            $this->getMerchantSearchClient(),
36
            $this->createSelectedMerchantCookie(),
37
            $this->createMerchantSwitcher()
38
        );
39
    }
40
41
    /**
42
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\MerchantSwitcher\MerchantSwitcherInterface
43
     */
44
    public function createMerchantSwitcher(): MerchantSwitcherInterface
45
    {
46
        return new MerchantSwitcher(
47
            $this->getQuoteClient(),
48
            $this->getMerchantSwitcherClient()
49
        );
50
    }
51
52
    /**
53
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\Cookie\SelectedMerchantCookieInterface
54
     */
55
    public function createSelectedMerchantCookie(): SelectedMerchantCookieInterface
56
    {
57
        return new SelectedMerchantCookie(
58
            $this->getCookies(),
59
            $this->getRequest(),
60
            $this->getConfig()
61
        );
62
    }
63
64
    /**
65
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSearchClientInterface
66
     */
67
    public function getMerchantSearchClient(): MerchantSwitcherWidgetToMerchantSearchClientInterface
68
    {
69
        return $this->getProvidedDependency(MerchantSwitcherWidgetDependencyProvider::CLIENT_MERCHANT_SEARCH);
70
    }
71
72
    /**
73
     * @return \Symfony\Component\HttpFoundation\Request
74
     */
75
    public function getRequest(): Request
76
    {
77
        return $this->getApplication()['request'];
78
    }
79
80
    /**
81
     * @return \ArrayObject|\Symfony\Component\HttpFoundation\Cookie[]
82
     */
83
    public function getCookies(): ArrayObject
84
    {
85
        return $this->getApplication()['cookies'];
86
    }
87
88
    /**
89
     * @return \Spryker\Shared\Kernel\Communication\Application
90
     */
91
    public function getApplication(): Application
92
    {
93
        return $this->getProvidedDependency(MerchantSwitcherWidgetDependencyProvider::PLUGIN_APPLICATION);
94
    }
95
96
    /**
97
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToQuoteClientInterface
98
     */
99
    public function getQuoteClient(): MerchantSwitcherWidgetToQuoteClientInterface
100
    {
101
        return $this->getProvidedDependency(MerchantSwitcherWidgetDependencyProvider::CLIENT_QUOTE);
102
    }
103
104
    /**
105
     * @return \SprykerShop\Yves\MerchantSwitcherWidget\Dependency\Client\MerchantSwitcherWidgetToMerchantSwitcherClientInterface
106
     */
107
    public function getMerchantSwitcherClient(): MerchantSwitcherWidgetToMerchantSwitcherClientInterface
108
    {
109
        return $this->getProvidedDependency(MerchantSwitcherWidgetDependencyProvider::CLIENT_MERCHANT_SWITCHER);
110
    }
111
}
112