Completed
Pull Request — master (#7)
by Alessandro
08:41 queued 01:13
created

ClientConfiguration::getCredentialsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A ClientConfiguration::getPassword() 0 4 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 4
     * @param int    $port
30
     * @param string $username
31 4
     * @param string $password
32 4
     * @param array  $options
33 4
     */
34 4
    public function __construct(
35 4
        string $host,
36
        int $port,
37
        string $username = '',
38
        string $password = '',
39
        array $options = []
40 4
    ) {
41
        $this->host = $host;
42 4
        $this->port = $port;
43
        $this->username = $username;
44
        $this->password = $password;
45
        $this->options = $this->cleanOptions($options);
46
    }
47
48 4
    /**
49
     * @return string
50 4
     */
51
    public function getHost(): string
52
    {
53
        return $this->host;
54
    }
55
56 2
    /**
57
     * @return int
58 2
     */
59
    public function getPort(): int
60
    {
61
        return $this->port;
62
    }
63
64 2
    /**
65
     * @return string
66 2
     */
67
    public function getUsername(): string
68
    {
69
        return $this->username;
70
    }
71
72 2
    /**
73
     * @return string
74
     */
75 2
    public function getPassword(): string
76 2
    {
77
        return $this->password;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getOptions(): array
84
    {
85
        return array_merge(
86
            [
87
                'username' => $this->username,
88
                'password' => $this->password,
89
            ],
90
            $this->options
91
        );
92
    }
93
94
    /**
95
     * @param array $options
96
     *
97
     * @return array
98
     */
99
    private function cleanOptions(array $options): array
100
    {
101
        return array_filter($options, function($value) {
102
            return !empty($value) || is_int($value) || is_bool($value) || is_float($value);
103
        });
104
    }
105
}
106