Completed
Pull Request — master (#62)
by .
08:28
created

ClientConfiguration::getProto()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Facile\MongoDbBundle\Models;
4
5
/**
6
 * Class ClientConfiguration.
7
 * @internal
8
 */
9
final class ClientConfiguration
10
{
11
    /** @var string */
12
    private $proto;
13
    /** @var string */
14
    private $hosts;
15
    /** @var string */
16
    private $username;
17
    /** @var string */
18
    private $password;
19
    /** @var array */
20
    private $options;
21
    /** @var null|string */
22
    private $authSource;
23
24
    /**
25
     * ClientConfiguration constructor.
26
     *
27
     * @param string $proto
28
     * @param string $hosts
29
     * @param string $username
30
     * @param string $password
31 35
     * @param string|null $authSource
32
     * @param array $options
33
     */
34
    public function __construct(
35
        string $proto,
36
        string $hosts,
37
        string $username = '',
38 35
        string $password = '',
39 35
        string $authSource = null,
40 35
        array $options = []
41 35
    ) {
42 35
        $this->proto = $proto;
43 35
        $this->hosts = $hosts;
44
        $this->username = $username;
45
        $this->password = $password;
46
        $this->options = $options;
47
        $this->authSource = $authSource;
48 33
    }
49
50 33
    /**
51
     * @return string
52
     */
53
    public function getProto(): string
54
    {
55
        return $this->proto;
56 5
    }
57
58 5
    /**
59
     * @return string
60
     */
61
    public function getHosts(): string
62
    {
63
        return $this->hosts;
64 5
    }
65
66 5
    /**
67
     * @return string
68
     */
69
    public function getUsername(): string
70
    {
71
        return $this->username;
72 28
    }
73
74 28
    /**
75
     * @return string
76
     */
77
    public function getPassword(): string
78
    {
79
        return $this->password;
80 33
    }
81
82 33
    /**
83 33
     * @return null|string
84
     */
85 33
    public function getAuthSource()
86 33
    {
87
        return $this->authSource;
88 33
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getOptions(): array
94
    {
95
        return $this->cleanOptions(
96
            array_merge(
97
                [
98 33
                    'username' => $this->username,
99
                    'password' => $this->password,
100 33
                ],
101 33
                $this->options
102 33
            )
103 33
        );
104 33
    }
105
106
    /**
107
     * @param array $options
108
     *
109
     * @return array
110
     */
111
    private function cleanOptions(array $options): array
112
    {
113
        return array_filter(
114
            $options,
115
            function ($value) {
116
                return ! empty($value) || \is_int($value) || \is_bool($value) || \is_float($value);
117
            }
118
        );
119
    }
120
}
121