Completed
Pull Request — master (#13)
by Vadim
06:54
created

CredentialsOptions::getSecret()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace AudioManager\Adapter\Polly;
4
5
use AudioManager\Exception\RuntimeException;
6
7
/**
8
 * @package Adapter\Polly
9
 */
10
class CredentialsOptions
11
{
12
    protected $key;
13
    protected $secret;
14
15
    /**
16
     * CredentialsOptions constructor.
17
     * @param array $options
18
     */
19
    public function __construct(array $options = [])
20
    {
21
        if (!empty($options)) {
22
            if (isset($options['key']) && isset($options['secret'])) {
23
                $this->key = $options['key'];
24
                $this->secret = $options['secret'];
25
            } else {
26
                throw new RuntimeException('Need to setup array[\'key\'=>\'\',\'secret\'=>\'\']');
27
            }
28
        }
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getKey()
35
    {
36
        if (!$this->key) {
37
            throw new RuntimeException('Need setup `key` to credentials');
38
        }
39
        return $this->key;
40
    }
41
42
    /**
43
     * @param string $key
44
     * @return CredentialsOptions
45
     */
46
    public function setKey($key)
47
    {
48
        $this->key = $key;
49
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSecret()
56
    {
57
        if (!$this->key) {
58
            throw new RuntimeException('Need setup `secret` to credentials');
59
        }
60
        return $this->secret;
61
    }
62
63
    /**
64
     * @param string $secret
65
     * @return CredentialsOptions
66
     */
67
    public function setSecret($secret)
68
    {
69
        $this->secret = $secret;
70
        return $this;
71
    }
72
}
73