Passed
Push — master ( f90d44...257288 )
by Mariano
01:13
created

ActionsFactory::createReset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Server\Actions;
20
21
use Mcustiel\Phiremock\Factory as PhiremockFactory;
22
use Mcustiel\Phiremock\Server\Factory\Factory as PhiremockServerFactory;
23
use Mcustiel\Phiremock\Server\Utils\DataStructures\StringObjectArrayMap;
24
25
class ActionsFactory
26
{
27
    /** @var StringObjectArrayMap */
28
    private $factoryCache;
29
    /** @var PhiremockServerFactory */
30
    private $serverFactory;
31
    /** @var PhiremockFactory */
32
    private $phiremockFactory;
33
34
    public function __construct(
35
        PhiremockServerFactory $serverFactory,
36
        PhiremockFactory $phiremockFactory
37
    ) {
38
        $this->factoryCache = new StringObjectArrayMap();
39
        $this->serverFactory = $serverFactory;
40
        $this->phiremockFactory = $phiremockFactory;
41
    }
42
43
    public function createAddExpectation(): AddExpectationAction
44
    {
45
        return new AddExpectationAction(
46
            $this->serverFactory->createRequestToExpectationMapper(),
47
            $this->serverFactory->createExpectationStorage(),
48
            $this->serverFactory->createLogger()
49
        );
50
    }
51
52
    public function createClearExpectations(): ClearExpectationsAction
53
    {
54
        return new ClearExpectationsAction($this->serverFactory->createExpectationStorage());
55
    }
56
57
    public function createClearScenarios(): ClearScenariosAction
58
    {
59
        return new ClearScenariosAction($this->serverFactory->createScenarioStorage());
60
    }
61
62
    public function createCountRequests(): CountRequestsAction
63
    {
64
        return new CountRequestsAction(
65
            $this->serverFactory->createRequestToExpectationMapper(),
66
            $this->serverFactory->createRequestStorage(),
67
            $this->serverFactory->createRequestExpectationComparator(),
68
            $this->serverFactory->createLogger()
69
        );
70
    }
71
72
    public function createListExpectations(): ListExpectationsAction
73
    {
74
        return new ListExpectationsAction(
75
            $this->serverFactory->createExpectationStorage(),
76
            $this->phiremockFactory->createExpectationToArrayConverter()
77
        );
78
    }
79
80
    public function createListRequests(): ListRequestsAction
81
    {
82
        return new ListRequestsAction(
83
            $this->serverFactory->createRequestToExpectationMapper(),
84
            $this->serverFactory->createRequestStorage(),
85
            $this->serverFactory->createRequestExpectationComparator(),
86
            $this->serverFactory->createLogger()
87
        );
88
    }
89
90
    public function createReloadPreconfiguredExpectations(): ReloadPreconfiguredExpectationsAction
91
    {
92
        return new ReloadPreconfiguredExpectationsAction(
93
            $this->serverFactory->createExpectationStorage(),
94
            $this->serverFactory->createExpectationBackup(),
95
            $this->serverFactory->createLogger()
96
        );
97
    }
98
99
    public function createResetRequestsCount(): ResetRequestsCountAction
100
    {
101
        return new ResetRequestsCountAction($this->serverFactory->createRequestStorage());
102
    }
103
104
    public function createReset(): ResetAction
105
    {
106
        return new ResetAction(
107
            $this->createClearScenarios(),
108
            $this->createResetRequestsCount(),
109
            $this->createReloadPreconfiguredExpectations(),
110
            $this->serverFactory->createLogger()
111
        );
112
    }
113
114
    public function createSearchRequest(): SearchRequestAction
115
    {
116
        return new SearchRequestAction(
117
            $this->serverFactory->createExpectationStorage(),
118
            $this->serverFactory->createRequestExpectationComparator(),
119
            $this->serverFactory->createResponseStrategyLocator(),
120
            $this->serverFactory->createRequestStorage(),
121
            $this->serverFactory->createLogger()
122
        );
123
    }
124
125
    public function createSetScenarioState(): SetScenarioStateAction
126
    {
127
        return new SetScenarioStateAction(
128
            $this->phiremockFactory->createArrayToScenarioStateInfoConverter(),
129
            $this->serverFactory->createScenarioStorage(),
130
            $this->serverFactory->createLogger()
131
        );
132
    }
133
}
134