Completed
Push — master ( d608d1...623c6b )
by Alessandro
08:12 queued 06:25
created

ClientConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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