Completed
Push — master ( ca6bb7...fdd070 )
by Alessandro
9s
created

ClientConfiguration::hasCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Models;
6
7
/**
8
 * Class ClientConfiguration.
9
 */
10
class ClientConfiguration
11
{
12
    /** @var string */
13
    private $host;
14
    /** @var int */
15
    private $port;
16
    /** @var string */
17
    private $username;
18
    /** @var string */
19
    private $password;
20
21
    /**
22
     * ClientConfiguration constructor.
23
     *
24
     * @param string $host
25
     * @param int    $port
26
     * @param string $username
27
     * @param string $password
28
     */
29 4
    public function __construct(string $host, int $port, string $username = '', string $password = '')
30
    {
31 4
        $this->host = $host;
32 4
        $this->port = $port;
33 4
        $this->username = $username;
34 4
        $this->password = $password;
35 4
    }
36
37
    /**
38
     * @return string
39
     */
40 4
    public function getHost(): string
41
    {
42 4
        return $this->host;
43
    }
44
45
    /**
46
     * @return int
47
     */
48 4
    public function getPort(): int
49
    {
50 4
        return $this->port;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 2
    public function getUsername(): string
57
    {
58 2
        return $this->username;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function hasCredentials(): bool
65
    {
66
        return !empty($this->username);
67
    }
68
69
    /**
70
     * @return string
71
     */
72 2
    public function getPassword(): string
73
    {
74 2
        return $this->password;
75
    }
76
77
    /**
78
     * @return array
79
     */
80 2
    public function getCredentialsArray(): array
81
    {
82
        return [
83 2
            'username' => $this->username,
84 2
            'password' => $this->password,
85
        ];
86
    }
87
}
88