Completed
Push — master ( ee70ec...2a5669 )
by Alessandro
06:23
created

ClientConfiguration::getHosts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 $hosts;
13
    /** @var string */
14
    private $username;
15
    /** @var string */
16
    private $password;
17
    /** @var array */
18
    private $options;
19
20
    /**
21
     * ClientConfiguration constructor.
22
     *
23
     * @param string $hosts
24
     * @param string $username
25
     * @param string $password
26
     * @param array  $options
27
     */
28 15
    public function __construct(
29
        string $hosts,
30
        string $username = '',
31
        string $password = '',
32
        array $options = []
33
    ) {
34 15
        $this->hosts = $hosts;
35 15
        $this->username = $username;
36 15
        $this->password = $password;
37 15
        $this->options = $options;
38 15
    }
39
40
    /**
41
     * @return string
42
     */
43 15
    public function getHosts(): string
44
    {
45 15
        return $this->hosts;
46
    }
47
48
    /**
49
     * @return string
50
     */
51 5
    public function getUsername(): string
52
    {
53 5
        return $this->username;
54
    }
55
56
    /**
57
     * @return string
58
     */
59 5
    public function getPassword(): string
60
    {
61 5
        return $this->password;
62
    }
63
64
    /**
65
     * @return array
66
     */
67 15
    public function getOptions(): array
68
    {
69 15
        return $this->cleanOptions(
70
            array_merge(
71
                [
72 15
                    'username' => $this->username,
73 15
                    'password' => $this->password,
74
                ],
75 15
                $this->options
76
            )
77
        );
78
    }
79
80
    /**
81
     * @param array $options
82
     *
83
     * @return array
84
     */
85 15
    private function cleanOptions(array $options): array
86
    {
87 15
        return array_filter(
88
            $options,
89 15
            function ($value) {
90 15
                return !empty($value) || is_int($value) || is_bool($value) || is_float($value);
91 15
            }
92
        );
93
    }
94
}
95