Passed
Push — master ( f4feef...3322ef )
by payever
10:36
created

ClientConfiguration::getCustomLiveUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * PHP version 5.4 and 7
5
 *
6
 * @category  Core
7
 * @package   Payever\Core
8
 * @author    payever GmbH <[email protected]>
9
 * @author    Andrey Puhovsky <[email protected]>
10
 * @author    Hennadii.Shymanskyi <[email protected]>
11
 * @copyright 2017-2021 payever GmbH
12
 * @license   MIT <https://opensource.org/licenses/MIT>
13
 * @link      https://docs.payever.org/shopsystems/api/getting-started
14
 */
15
16
namespace Payever\ExternalIntegration\Core;
17
18
use Payever\ExternalIntegration\Core\Base\ClientConfigurationInterface;
19
use Payever\ExternalIntegration\Core\Enum\ChannelSet;
20
use Payever\ExternalIntegration\Core\Exception\ConfigurationException;
21
use Payever\ExternalIntegration\Core\Logger\NullLogger;
22
use Psr\Log\LoggerInterface;
23
24
/**
25
 * @SuppressWarnings(PHPMD.StaticAccess)
26
 */
27
class ClientConfiguration implements ClientConfigurationInterface
28
{
29
    /** @var string */
30
    protected $apiMode = self::API_MODE_LIVE;
31
32
    /** @var string */
33
    protected $clientId;
34
35
    /** @var string */
36
    protected $clientSecret;
37
38
    /** @var string */
39
    protected $customSandboxUrl;
40
41
    /** @var string */
42
    protected $customLiveUrl;
43
44
    /** @var string */
45
    protected $businessUuid;
46
47
    /** @var string */
48
    protected $channelSet = ChannelSet::CHANNEL_OTHER_SHOPSYSTEM;
49
50
    /** @var LoggerInterface */
51
    protected $logger;
52
53
    /**
54
     * @param string|null $clientId
55
     * @param string|null $clientSecret
56
     * @param string|null $businessUuid
57
     */
58
    public function __construct(
59
        $clientId = null,
60
        $clientSecret = null,
61
        $businessUuid = null
62
    ) {
63
        $this->clientId = $clientId;
64
        $this->clientSecret = $clientSecret;
65
        $this->businessUuid = $businessUuid;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getClientId()
72
    {
73
        return $this->clientId;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getClientSecret()
80
    {
81
        return $this->clientSecret;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getBusinessUuid()
88
    {
89
        return $this->businessUuid;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function getApiMode()
96
    {
97
        return $this->apiMode;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function getChannelSet()
104
    {
105
        return $this->channelSet;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function getCustomSandboxUrl()
112
    {
113
        return $this->customSandboxUrl;
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119
    public function getCustomLiveUrl()
120
    {
121
        return $this->customLiveUrl;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127
    public function getHash()
128
    {
129
        return md5($this->getClientId() . $this->getClientSecret());
130
    }
131
132
    /**
133
     * @return LoggerInterface
134
     */
135
    public function getLogger()
136
    {
137
        if (is_null($this->logger)) {
138
            $this->logger = new NullLogger();
139
        }
140
141
        return $this->logger;
142
    }
143
144
    /**
145
     * Sets Client ID
146
     *
147
     * @param mixed $clientId
148
     *
149
     * @return self
150
     */
151
    public function setClientId($clientId)
152
    {
153
        $this->clientId = $clientId;
154
155
        return $this;
156
    }
157
158
    /**
159
     * Sets Client Secret
160
     *
161
     * @param mixed $clientSecret
162
     *
163
     * @return self
164
     */
165
    public function setClientSecret($clientSecret)
166
    {
167
        $this->clientSecret = $clientSecret;
168
169
        return $this;
170
    }
171
172
    /**
173
     * Sets Business UUID
174
     *
175
     * @param mixed $businessUuid
176
     *
177
     * @return self
178
     */
179
    public function setBusinessUuid($businessUuid)
180
    {
181
        $this->businessUuid = $businessUuid;
182
183
        return $this;
184
    }
185
186
    /**
187
     * @param string $apiMode
188
     * @return self
189
     */
190
    public function setApiMode($apiMode)
191
    {
192
        $this->apiMode = $apiMode;
193
194
        return $this;
195
    }
196
197
    /**
198
     * Sets Channel set
199
     *
200
     * @param mixed $channelSet
201
     *
202
     * @return $this
203
     *
204
     * @throws \Exception
205
     */
206
    public function setChannelSet($channelSet = null)
207
    {
208
        if (!in_array($channelSet, ChannelSet::enum())) {
209
            throw new ConfigurationException(sprintf('Channel Set `%s` is not valid', $channelSet));
210
        }
211
        $this->channelSet = $channelSet;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @internal
218
     *
219
     * Sets Custom sandbox API URL for all packages at once
220
     *
221
     * @param string $customSandboxUrl
222
     *
223
     * @return $this
224
     */
225
    public function setCustomSandboxUrl($customSandboxUrl)
226
    {
227
        $this->customSandboxUrl = $customSandboxUrl;
228
229
        return $this;
230
    }
231
232
    /**
233
     * @internal
234
     *
235
     * Sets Custom live API URL for all packages at once
236
     *
237
     * @param string $customLiveUrl
238
     *
239
     * @return $this
240
     */
241
    public function setCustomLiveUrl($customLiveUrl)
242
    {
243
        $this->customLiveUrl = $customLiveUrl;
244
245
        return $this;
246
    }
247
248
    /**
249
     * @param LoggerInterface $logger
250
     *
251
     * @return $this
252
     */
253
    public function setLogger(LoggerInterface $logger)
254
    {
255
        $this->logger = $logger;
256
257
        return $this;
258
    }
259
260
    /**
261
     * @inheritdoc
262
     */
263
    public function isLoaded()
264
    {
265
        return
266
            $this->getClientId() &&
267
            $this->getClientSecret() &&
268
            $this->getBusinessUuid()
269
        ;
270
    }
271
272
    /**
273
     * @inheritdoc
274
     */
275
    public function assertLoaded()
276
    {
277
        if (!$this->isLoaded()) {
278
            throw new ConfigurationException(
279
                'Payever API client credentials (client_id, client_secret, business_uuid) are not set.'
280
            );
281
        }
282
    }
283
}
284