Manager   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 214
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 6

Test Coverage

Coverage 89.29%

Importance

Changes 12
Bugs 4 Features 2
Metric Value
wmc 24
c 12
b 4
f 2
lcom 4
cbo 6
dl 0
loc 214
ccs 50
cts 56
cp 0.8929
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __clone() 0 3 1
A getConfiguration() 0 4 1
A getLogger() 0 4 1
A isEnabled() 0 4 1
A getInstance() 0 8 2
A setConfiguration() 0 5 1
A getPartnerApiClient() 0 7 2
A getVentureApiClient() 0 8 2
A setLogger() 0 5 1
A setPartnerApiClient() 0 5 1
A setVentureApiClient() 0 5 1
A getService() 0 6 2
A setService() 0 5 1
A getSaleWrapper() 0 5 2
A setSaleWrapper() 0 5 1
A getOrderMapping() 0 5 2
A setOrderMapping() 0 5 1
1
<?php
2
3
namespace Iris;
4
5
use Iris\Interfaces\Configuration;
6
use Iris\Interfaces\Service;
7
use Iris\Factory;
8
use Iris\SaleWrapper;
9
use Iris\Mapping;
10
use Iris\Api\PartnerClient;
11
use Iris\Api\VentureClient;
12
13
class Manager
14
{
15
    /**
16
     * @var \Iris\Manager
17
     */
18
    private static $instance;
19
20
    /**
21
     * @var \Iris\Interfaces\Configuration
22
     */
23
    private $configuration;
24
25
    /**
26
     * @var \Iris\Api\PartnerClient
27
     */
28
    private $partnerApiClient;
29
30
    /**
31
     * @var \Iris\Api\VentureClient
32
     */
33
    private $ventureApiClient;
34
35
    /**
36
     * @var array
37
     */
38
    private $services = [];
39
40
    /**
41
     * @var array
42
     */
43
    private $saleWrapper;
44
45
    /**
46
     * @var \Iris\Mapping\Order
47
     */
48
    private $orderMapping;
49
50
    /**
51
     * @var \Psr\Log\LoggerInterface
52
     */
53
    private $logger;
54
55 1
    private function __construct()
56
    {
57 1
    }
58
59
    /**
60
     * @return void
61
     */
62
    private function __clone()
63
    {
64
    }
65
66
    /**
67
     * @return \Iris\Manager
68
     */
69 1
    public static function getInstance()
70
    {
71 1
        if (!self::$instance) {
72 1
            self::$instance = new self();
73 1
        }
74
75 1
        return self::$instance;
76
    }
77
78
    /**
79
     * @return \Iris\Interfaces\Configuration
80
     */
81 3
    public function getConfiguration()
82
    {
83 3
        return $this->configuration;
84
    }
85
86
    /**
87
     * @param \Iris\Interfaces\Configuration $configuration
88
     * @return \Iris\Manager
89
     */
90 3
    public function setConfiguration(Configuration $configuration)
91
    {
92 3
        $this->configuration = $configuration;
93 3
        return $this;
94
    }
95
96
    /**
97
     * @return \Iris\Api\PartnerClient
98
     */
99 1
    public function getPartnerApiClient()
100
    {
101 1
        if (!$this->partnerApiClient) {
102
            $this->setPartnerApiClient(new PartnerClient($this->getConfiguration(), $this->getLogger()));
103
        }
104 1
        return $this->partnerApiClient;
105
    }
106
107
    /**
108
     * @return \Iris\Api\VentureClient
109
     */
110 1
    public function getVentureApiClient()
111
    {
112 1
        if (!$this->ventureApiClient) {
113
            $this->setVentureApiClient(new VentureClient($this->getConfiguration(), $this->getLogger()));
114
        }
115
116 1
        return $this->ventureApiClient;
117
    }
118
119
    /**
120
     * @param \Psr\Log\LoggerInterface
121
     * @return \Iris\Manager
122
     */
123 1
    public function setLogger(\Psr\Log\LoggerInterface $logger)
124
    {
125 1
        $this->logger = $logger;
126 1
        return $this;
127
    }
128
129
    /**
130
     * @return \Psr\Log\LoggerInterface
131
     */
132 1
    public function getLogger()
133
    {
134 1
        return $this->logger;
135
    }
136
137
    /**
138
     * @param \Iris\Api\PartnerClient $client
139
     * @return \Iris\Manager
140
     */
141 1
    public function setPartnerApiClient(PartnerClient $client)
142
    {
143 1
        $this->partnerApiClient = $client;
144 1
        return $this;
145
    }
146
147
    /**
148
     * @param \Iris\Api\VentureClient $client
149
     * @return \Iris\Manager
150
     */
151 1
    public function setVentureApiClient(VentureClient $client)
152
    {
153 1
        $this->ventureApiClient = $client;
154 1
        return $this;
155
    }
156
157
    /**
158
     * @param string $name
159
     * @return \Iris\Interfaces\Service
160
     */
161 1
    public function getService($name)
162
    {
163 1
        $className = $this->getConfiguration()->getService($name);
164 1
        empty($this->services[$name]) && $this->setService($name, Factory::create($name, $className, $this));
165 1
        return $this->services[$name];
166
    }
167
168
    /**
169
     * @param string $name
170
     * @param \Iris\Interfaces\Service $service
171
     * @return \Iris\Manager
172
     */
173 1
    public function setService($name, Service $service)
174
    {
175 1
        $this->services[$name] = $service;
176 1
        return $this;
177
    }
178
179
    /**
180
     * @param string $name
181
     * @return \Iris\Model\SaleWrapper\Base
182
     */
183 1
    public function getSaleWrapper($name)
184
    {
185 1
        empty($this->saleWrapper[$name]) && ($this->saleWrapper[$name] = SaleWrapper\Factory::create($name, $this));
186 1
        return $this->saleWrapper[$name];
187
    }
188
189
    /**
190
     * @param string                         $name
191
     * @param \Iris\SaleWrapper\Base $saleWrapper
192
     * @return \Iris\Manager
193
     */
194 1
    public function setSaleWrapper($name, SaleWrapper\Base $saleWrapper)
195
    {
196 1
        $this->saleWrapper[$name] = $saleWrapper;
197 1
        return $this;
198
    }
199
200
    /**
201
     * @return \Iris\Mapping\Order
202
     */
203 1
    public function getOrderMapping()
204
    {
205 1
        $this->orderMapping || $this->setOrderMapping(Mapping\Order::getInstance());
206 1
        return $this->orderMapping;
207
    }
208
209
    /**
210
     * @param \Iris\Mapping\Order $orderMapping
211
     * @return \Iris\Manager
212
     */
213 1
    public function setOrderMapping(Mapping\Order $orderMapping)
214
    {
215 1
        $this->orderMapping = $orderMapping;
216 1
        return $this;
217
    }
218
219
    /**
220
     * @return bool
221
     */
222 1
    public function isEnabled()
223
    {
224 1
        return $this->getConfiguration()->isEnabled();
225
    }
226
}
227