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

ClientConfiguration   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 86
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getHosts() 0 4 1
A getUsername() 0 4 1
A getPassword() 0 4 1
A getOptions() 0 12 1
A cleanOptions() 0 9 4
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