Completed
Push — master ( 479a96...af667a )
by
unknown
03:16
created

ClientConfiguration::getUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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