Completed
Pull Request — master (#62)
by .
03:13
created

ClientConfiguration   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 112
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 12 1
A __construct() 0 15 1
A getProto() 0 4 1
A getHosts() 0 4 1
A getUsername() 0 4 1
A getPassword() 0 4 1
A getAuthSource() 0 4 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 $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
     * @param string|null $authSource
32
     * @param array $options
33
     */
34 35
    public function __construct(
35
        string $proto,
36
        string $hosts,
37
        string $username = '',
38
        string $password = '',
39
        string $authSource = null,
40
        array $options = []
41
    ) {
42 35
        $this->proto = $proto;
43 35
        $this->hosts = $hosts;
44 35
        $this->username = $username;
45 35
        $this->password = $password;
46 35
        $this->options = $options;
47 35
        $this->authSource = $authSource;
48 35
    }
49
50
    /**
51
     * @return string
52
     */
53 33
    public function getProto(): string
54
    {
55 33
        return $this->proto;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 33
    public function getHosts(): string
62
    {
63 33
        return $this->hosts;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 5
    public function getUsername(): string
70
    {
71 5
        return $this->username;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 5
    public function getPassword(): string
78
    {
79 5
        return $this->password;
80
    }
81
82
    /**
83
     * @return null|string
84
     */
85 28
    public function getAuthSource()
86
    {
87 28
        return $this->authSource;
88
    }
89
90
    /**
91
     * @return array
92
     */
93 33
    public function getOptions(): array
94
    {
95 33
        return $this->cleanOptions(
96 33
            array_merge(
97
                [
98 33
                    'username' => $this->username,
99 33
                    'password' => $this->password,
100
                ],
101 33
                $this->options
102
            )
103
        );
104
    }
105
106
    /**
107
     * @param array $options
108
     *
109
     * @return array
110
     */
111 33
    private function cleanOptions(array $options): array
112
    {
113 33
        return array_filter(
114 33
            $options,
115 33
            function ($value) {
116 33
                return ! empty($value) || \is_int($value) || \is_bool($value) || \is_float($value);
117 33
            }
118
        );
119
    }
120
}
121