Sdk::getTimeout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * The Imaging Source Download System PHP Wrapper
6
 *
7
 * PHP wrapper for The Imaging Source Download System Web API. Authored and supported by The Imaging Source Europe GmbH.
8
 *
9
 * @link      http://dl-gui.theimagingsource.com to learn more about The Imaging Source Download System
10
 * @link      https://github.com/jonathanmaron/theimagingsource-tisd-sdk for the canonical source repository
11
 * @license   https://github.com/jonathanmaron/theimagingsource-tisd-sdk/blob/master/LICENSE.md
12
 * @copyright © 2022 The Imaging Source Europe GmbH
13
 */
14
15
namespace Tisd\Sdk;
16
17
use Tisd\Sdk\Cache\Cache;
18
use Tisd\Sdk\Defaults\Defaults;
19
20
/**
21
 * Class Sdk
22
 *
23
 * @package Tisd\Sdk
24
 */
25
class Sdk
26
{
27
    use ConsolidatedTrait;
28
    use ContextsTrait;
29
    use FilterTrait;
30
    use LocalesTrait;
31
    use MetaTrait;
32
    use PackagesTrait;
33
    use PackageTrait;
34
35
    /**
36
     * Cache
37
     *
38
     * @var Cache
39
     */
40
    protected Cache $cache;
41
42
    /**
43
     * Context
44
     *
45
     * @var string
46
     */
47
    protected string $context;
48
49
    /**
50
     * Hostname
51
     *
52
     * @var string
53
     */
54
    protected string $hostname;
55
56
    /**
57
     * Locale
58
     *
59
     * @var string
60
     */
61
    protected string $locale;
62
63
    /**
64
     * Timeout
65
     *
66
     * @var int
67
     */
68
    protected int $timeout;
69
70
    /**
71
     * Version
72
     *
73
     * @var string
74
     */
75
    protected string $version;
76
77
    /**
78
     * Sdk constructor
79
     *
80
     * @param array $options
81
     */
82 47
    public function __construct(array $options = [])
83
    {
84 47
        $defaults = new Defaults();
85
86 47
        $optionKeys = [
87 47
            'context',
88 47
            'hostname',
89 47
            'locale',
90 47
            'timeout',
91 47
            'version',
92 47
        ];
93
94 47
        foreach ($optionKeys as $optionKey) {
95 47
            if (array_key_exists($optionKey, $options)) {
96 1
                $value = $options[$optionKey];
97
            } else {
98 47
                $getter = sprintf('get%s', ucfirst($optionKey));
99
                // @phpstan-ignore-next-line
100 47
                $value = $defaults->$getter();
101
            }
102
103 47
            $setter = sprintf('set%s', ucfirst($optionKey));
104
            // @phpstan-ignore-next-line
105 47
            $this->$setter($value);
106
        }
107
108 47
        $cache = new Cache();
109
110 47
        if (array_key_exists('ttl', $options)) {
111 1
            $ttl = $options['ttl'];
112
        } else {
113 47
            $ttl = Defaults::TTL;
114
        }
115
116 47
        $cache->setTtl($ttl);
117
118 47
        $this->setCache($cache);
119
    }
120
121
    /**
122
     * Get the Cache instance
123
     *
124
     * @return Cache
125
     */
126 41
    public function getCache(): Cache
127
    {
128 41
        return $this->cache;
129
    }
130
131
    /**
132
     * Set the Cache instance
133
     *
134
     * @param Cache $cache
135
     *
136
     * @return $this
137
     */
138 47
    public function setCache(Cache $cache): self
139
    {
140 47
        $this->cache = $cache;
141
142 47
        return $this;
143
    }
144
145
    /**
146
     * Get the context
147
     *
148
     * @return string
149
     */
150 41
    public function getContext(): string
151
    {
152 41
        return $this->context;
153
    }
154
155
    /**
156
     * Set the context
157
     *
158
     * @param string $context
159
     *
160
     * @return $this
161
     */
162 47
    public function setContext(string $context): self
163
    {
164 47
        $this->context = $context;
165
166 47
        return $this;
167
    }
168
169
    /**
170
     * Get the hostname
171
     *
172
     * @return string
173
     */
174 7
    public function getHostname(): string
175
    {
176 7
        return $this->hostname;
177
    }
178
179
    /**
180
     * Set the hostname
181
     *
182
     * @param string $hostname
183
     *
184
     * @return $this
185
     */
186 47
    public function setHostname(string $hostname): self
187
    {
188 47
        $this->hostname = $hostname;
189
190 47
        return $this;
191
    }
192
193
    /**
194
     * Get the locale
195
     *
196
     * @return string
197
     */
198 41
    public function getLocale(): string
199
    {
200 41
        return $this->locale;
201
    }
202
203
    /**
204
     * Set the locale
205
     *
206
     * @param string $locale
207
     *
208
     * @return $this
209
     */
210 47
    public function setLocale(string $locale): self
211
    {
212 47
        $this->locale = $locale;
213
214 47
        $this->setConsolidated([]);
215
216 47
        return $this;
217
    }
218
219
    /**
220
     * Get the timeout
221
     *
222
     * @return int
223
     */
224 7
    public function getTimeout(): int
225
    {
226 7
        return $this->timeout;
227
    }
228
229
    /**
230
     * Set the timeout
231
     *
232
     * @param int $timeout
233
     *
234
     * @return $this
235
     */
236 47
    public function setTimeout(int $timeout): self
237
    {
238 47
        $this->timeout = $timeout;
239
240 47
        return $this;
241
    }
242
243
    /**
244
     * Get the version
245
     *
246
     * @return string
247
     */
248 7
    public function getVersion(): string
249
    {
250 7
        return $this->version;
251
    }
252
253
    /**
254
     * Set the version
255
     *
256
     * @param string $version
257
     *
258
     * @return $this
259
     */
260 47
    public function setVersion(string $version): self
261
    {
262 47
        $this->version = $version;
263
264 47
        return $this;
265
    }
266
}
267