BasicAuth   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getUsername() 0 4 1
A getPassword() 0 4 1
A ensureUsername() 0 5 1
A ensurePassword() 0 4 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