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

InitializeOptions::setOptions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 12
1
<?php
2
3
namespace AudioManager\Adapter\Polly;
4
5
/**
6
 * Class InitializeOptions
7
 * @package Adapter\Polly
8
 */
9
class InitializeOptions
10
{
11
    protected $version;
12
    protected $region;
13
    protected $credentials;
14
15
    /**
16
     * InitializeOptions constructor.
17
     * @param array $options
18
     */
19
    public function __construct(array $options = [])
20
    {
21
        if (!empty($options)) {
22
            $this->setOptions($options);
23
        }
24
    }
25
26
    /**
27
     * Set options
28
     * @param array $options
29
     */
30
    public function setOptions(array $options)
31
    {
32
        foreach ($options as $option => $value) {
33
            $methodName = 'set'.ucfirst($option);
34
            if (method_exists($this, $methodName)) {
35
                $this->$methodName($value);
36
            }
37
        }
38
    }
39
40
    /**
41
     * @return mixed
42
     */
43
    public function getVersion()
44
    {
45
        return $this->version;
46
    }
47
48
    /**
49
     * @param mixed $version
50
     * @return $this
51
     */
52
    public function setVersion($version)
53
    {
54
        $this->version = $version;
55
        return $this;
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getRegion()
62
    {
63
        return $this->region;
64
    }
65
66
    /**
67
     * @param mixed $region
68
     * @return $this
69
     */
70
    public function setRegion($region)
71
    {
72
        $this->region = $region;
73
        return $this;
74
    }
75
76
    /**
77
     * @return CredentialsOptions
78
     */
79
    public function getCredentials()
80
    {
81
        return $this->credentials;
82
    }
83
84
    /**
85
     * @param CredentialsOptions|array $credentials
86
     * @return CredentialsOptions
87
     */
88
    public function setCredentials($credentials = [])
89
    {
90
        if ($credentials instanceof CredentialsOptions) {
91
            $this->credentials = $credentials;
92
        } elseif (is_array($credentials)) {
93
            $this->credentials = new CredentialsOptions($credentials);
94
        } else {
95
            $this->credentials = new CredentialsOptions();
96
        }
97
        return $this->credentials;
98
    }
99
}
100