BasicAuth::ensurePassword()   A
last analyzed

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 1
1
<?php
2
namespace DjThossi\SmokeTestingPhp\ValueObject;
3
4
use DjThossi\Ensure\EnsureIsNotEmptyTrait;
5
use DjThossi\Ensure\EnsureIsStringTrait;
6
7
class BasicAuth
8
{
9
    use EnsureIsStringTrait;
10
    use EnsureIsNotEmptyTrait;
11
12
    const USERNAME_IS_NOT_A_STRING = 1;
13
    const USERNAME_IS_EMPTY = 2;
14
    const PASSWORD_IS_NOT_A_STRING = 3;
15
16
    /**
17
     * @var string
18
     */
19
    private $username;
20
21
    /**
22
     * @var string
23
     */
24
    private $password;
25
26
    /**
27
     * @param string $username
28
     * @param string $password
29
     */
30
    public function __construct($username, $password)
31
    {
32
        $this->ensureUsername($username);
33
        $this->ensurePassword($password);
34
35
        $this->username = $username;
36
        $this->password = $password;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getUsername()
43
    {
44
        return $this->username;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getPassword()
51
    {
52
        return $this->password;
53
    }
54
55
    /**
56
     * @param mixed $username
57
     */
58
    private function ensureUsername($username)
59
    {
60
        $this->ensureIsString('Username', $username, self::USERNAME_IS_NOT_A_STRING);
61
        $this->ensureIsNotEmpty('Username', $username, self::USERNAME_IS_EMPTY);
62
    }
63
64
    /**
65
     * @param mixed $password
66
     */
67
    private function ensurePassword($password)
68
    {
69
        $this->ensureIsString('Password', $password, self::PASSWORD_IS_NOT_A_STRING);
70
    }
71
}
72