DatabaseSourceConfig::setPassword()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Charcoal\Source;
4
5
use InvalidArgumentException;
6
7
// From 'charcoal-core'
8
use Charcoal\Source\SourceConfig;
9
10
/**
11
 *
12
 */
13
class DatabaseSourceConfig extends SourceConfig
14
{
15
    /**
16
     * @var string $hostname
17
     */
18
    private $hostname;
19
20
    /**
21
     * @var string $username
22
     */
23
    private $username;
24
25
    /**
26
     * @var string $password
27
     */
28
    private $password;
29
30
    /**
31
     * @var string $database
32
     */
33
    private $database;
34
35
36
    /**
37
     * @var boolean $disableUtf8
38
     */
39
    private $disableUtf8;
40
41
    /**
42
     * @return array
43
     */
44
    public function defaults()
45
    {
46
        return [
47
            'type'         => 'mysql',
48
            'hostname'     => 'localhost',
49
            'username'     => '',
50
            'password'     => '',
51
            'database'     => '',
52
            'table'        => '',
53
            'disable_ytf8' => false
54
        ];
55
    }
56
57
    /**
58
     * Set hostname
59
     *
60
     * @param string $hostname The database hostname.
61
     * @throws InvalidArgumentException If hostname is not a string.
62
     * @return self
63
     */
64
    public function setHostname($hostname)
65
    {
66
        if (!is_string($hostname)) {
0 ignored issues
show
introduced by
The condition is_string($hostname) is always true.
Loading history...
67
            throw new InvalidArgumentException(
68
                'Hostname must be a string.'
69
            );
70
        }
71
        $this->hostname = $hostname;
72
        return $this;
73
    }
74
75
    /**
76
     * Get hostname
77
     *
78
     * @return string
79
     */
80
    public function hostname()
81
    {
82
        return $this->hostname;
83
    }
84
85
    /**
86
     * Set username
87
     *
88
     * @param string $username The database username.
89
     * @throws InvalidArgumentException If username is not a string.
90
     * @return self
91
     */
92
    public function setUsername($username)
93
    {
94
        if (!is_string($username)) {
0 ignored issues
show
introduced by
The condition is_string($username) is always true.
Loading history...
95
            throw new InvalidArgumentException(
96
                'Username must be a string.'
97
            );
98
        }
99
        $this->username = $username;
100
        return $this;
101
    }
102
103
    /**
104
     * Get username
105
     *
106
     * @return string
107
     */
108
    public function username()
109
    {
110
        return $this->username;
111
    }
112
113
    /**
114
     * Set password
115
     *
116
     * @param string $password The database password.
117
     * @throws InvalidArgumentException If password is not a string.
118
     * @return self
119
     */
120
    public function setPassword($password)
121
    {
122
        if (!is_string($password)) {
0 ignored issues
show
introduced by
The condition is_string($password) is always true.
Loading history...
123
            throw new InvalidArgumentException(
124
                'Password must be a string.'
125
            );
126
        }
127
        $this->password = $password;
128
        return $this;
129
    }
130
131
    /**
132
     * Get password
133
     *
134
     * @return string
135
     */
136
    public function password()
137
    {
138
        return $this->password;
139
    }
140
141
    /**
142
     * Set database
143
     *
144
     * @param string $database The database name.
145
     * @throws InvalidArgumentException If database is not a string.
146
     * @return self
147
     */
148
    public function setDatabase($database)
149
    {
150
        if (!is_string($database)) {
0 ignored issues
show
introduced by
The condition is_string($database) is always true.
Loading history...
151
            throw new InvalidArgumentException(
152
                'Database must be a string.'
153
            );
154
        }
155
        $this->database = $database;
156
        return $this;
157
    }
158
159
    /**
160
     * Get database
161
     *
162
     * @return string
163
     */
164
    public function database()
165
    {
166
        return $this->database;
167
    }
168
169
    /**
170
     * @param boolean $disableUtf8 The "disable UTF8" flag.
171
     * @return self
172
     */
173
    public function setDisableUtf8($disableUtf8)
174
    {
175
        $this->disableUtf8 = !!$disableUtf8;
176
        return $this;
177
    }
178
179
    /**
180
     * @return boolean
181
     */
182
    public function disableUtf8()
183
    {
184
        return $this->disableUtf8;
185
    }
186
}
187