Completed
Pull Request — master (#7)
by Alessandro
03:00 queued 52s
created

ClientConfiguration::cleanOptions()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.2
cc 4
eloc 3
nc 1
nop 1
crap 4
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 7
    public function __construct(
35
        string $host,
36
        int $port,
37
        string $username = '',
38
        string $password = '',
39
        array $options = []
40
    ) {
41 7
        $this->host = $host;
42 7
        $this->port = $port;
43 7
        $this->username = $username;
44 7
        $this->password = $password;
45 7
        $this->options = $options;
46 7
    }
47
48
    /**
49
     * @return string
50
     */
51 7
    public function getHost(): string
52
    {
53 7
        return $this->host;
54
    }
55
56
    /**
57
     * @return int
58
     */
59 7
    public function getPort(): int
60
    {
61 7
        return $this->port;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 5
    public function getUsername(): string
68
    {
69 5
        return $this->username;
70
    }
71
72
    /**
73
     * @return string
74
     */
75 5
    public function getPassword(): string
76
    {
77 5
        return $this->password;
78
    }
79
80
    /**
81
     * @return array
82
     */
83 7
    public function getOptions(): array
84
    {
85 7
        return $this->cleanOptions(array_merge(
86
            [
87 7
                'username' => $this->username,
88 7
                'password' => $this->password,
89
            ],
90 7
            $this->options
91
        ));
92
    }
93
94
    /**
95
     * @param array $options
96
     *
97
     * @return array
98
     */
99
    private function cleanOptions(array $options): array
100
    {
101 7
        return array_filter($options, function ($value) {
102 7
            return !empty($value) || is_int($value) || is_bool($value) || is_float($value);
103 7
        });
104
    }
105
}
106