ClientConfiguration::getAuthSource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Models;
6
7
/**
8
 * Class ClientConfiguration.
9
 *
10
 * @internal
11
 */
12
final class ClientConfiguration
13
{
14
    /** @var string */
15
    private $uri;
16
17
    /** @var string */
18
    private $username;
19
20
    /** @var string */
21
    private $password;
22
23
    /** @var array */
24
    private $options;
25
26
    /** @var null|string */
27
    private $authSource;
28
29
    /** @var array */
30
    private $driverOptions;
31
32
    /**
33
     * ClientConfiguration constructor.
34
     *
35
     * @param string        $uri
36 36
     * @param string        $username
37
     * @param string        $password
38
     * @param string|null   $authSource
39
     * @param array         $options
40
     * @param array         $driverOptions
41
     */
42
    public function __construct(
43 36
        string $uri,
44 36
        string $username = '',
45 36
        string $password = '',
46 36
        string $authSource = null,
47 36
        array $options = [],
48 36
        array $driverOptions = []
49
    ) {
50
        $this->uri = $uri;
51
        $this->username = $username;
52
        $this->password = $password;
53 34
        $this->options = $options;
54
        $this->authSource = $authSource;
55 34
        $this->driverOptions = $driverOptions;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 5
    public function getUri(): string
62
    {
63 5
        return $this->uri;
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 29
    public function getPassword(): string
78
    {
79 29
        return $this->password;
80
    }
81
82
    /**
83
     * @return null|string
84
     */
85 34
    public function getAuthSource()
86
    {
87 34
        return $this->authSource;
88 34
    }
89
90 34
    /**
91 34
     * @return array
92
     */
93 34
    public function getOptions(): array
94
    {
95
        return $this->cleanOptions(
96
            array_merge(
97
                [
98
                    'username' => $this->username,
99
                    'password' => $this->password,
100
                ],
101
                $this->options
102
            )
103 34
        );
104
    }
105 34
106 34
    /**
107 34
     * @return array
108 34
     */
109 34
    public function getDriverOptions(): array
110
    {
111
        return $this->driverOptions;
112
    }
113
114
    /**
115
     * @param array $options
116
     *
117
     * @return array
118
     */
119
    private function cleanOptions(array $options): array
120
    {
121
        return array_filter(
122
            $options,
123
            function ($value): bool {
124
                return ! empty($value) || \is_int($value) || \is_bool($value) || \is_float($value);
125
            }
126
        );
127
    }
128
}
129