Completed
Pull Request — master (#64)
by .
03:42
created

ClientConfiguration::getAuthSource()   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
 * @internal
8
 */
9
final class ClientConfiguration
10
{
11
    /** @var string */
12
    private $uri;
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 $uri
26
     * @param string $username
27
     * @param string $password
28
     * @param string|null $authSource
29
     * @param array $options
30
     */
31 36
    public function __construct(
32
        string $uri,
33
        string $username = '',
34
        string $password = '',
35
        string $authSource = null,
36
        array $options = []
37
    ) {
38 36
        $this->uri = $uri;
39 36
        $this->username = $username;
40 36
        $this->password = $password;
41 36
        $this->options = $options;
42 36
        $this->authSource = $authSource;
43 36
    }
44
45
    /**
46
     * @return string
47
     */
48 34
    public function getUri(): string
49
    {
50 34
        return $this->uri;
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 29
    public function getAuthSource()
73
    {
74 29
        return $this->authSource;
75
    }
76
77
    /**
78
     * @return array
79
     */
80 34
    public function getOptions(): array
81
    {
82 34
        return $this->cleanOptions(
83 34
            array_merge(
84
                [
85 34
                    'username' => $this->username,
86 34
                    'password' => $this->password,
87
                ],
88 34
                $this->options
89
            )
90
        );
91
    }
92
93
    /**
94
     * @param array $options
95
     *
96
     * @return array
97
     */
98 34
    private function cleanOptions(array $options): array
99
    {
100 34
        return array_filter(
101 34
            $options,
102 34
            function ($value) {
103 34
                return ! empty($value) || \is_int($value) || \is_bool($value) || \is_float($value);
104 34
            }
105
        );
106
    }
107
}
108