Completed
Pull Request — master (#7)
by Alessandro
10:19 queued 08:09
created

ClientConfiguration::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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