Passed
Push — master ( 1b37b7...612acf )
by Tobias
01:49
created

Dsn   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
eloc 14
c 1
b 0
f 1
dl 0
loc 64
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPassword() 0 3 1
A getParameters() 0 3 1
A getScheme() 0 3 1
A getPort() 0 3 1
A getPath() 0 3 1
A getParameter() 0 3 2
A __toString() 0 3 2
A getHost() 0 3 1
A getUser() 0 3 1
1
<?php
2
3
namespace Nyholm\Dsn\Configuration;
4
5
/**
6
 * Base DSN object.
7
 *
8
 * Example:
9
 * - null://
10
 * - redis:?host[h1]&host[h2]&host[/foo:]
11
 *
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
class Dsn
15
{
16
    /**
17
     * @var string|null
18
     */
19
    private $scheme;
20
21
    /**
22
     * @var array
23
     */
24
    private $parameters = [];
25
26
    public function __construct(?string $scheme, array $parameters = [])
27
    {
28
        $this->scheme = $scheme;
29
        $this->parameters = $parameters;
30
    }
31
32
    public function getScheme(): ?string
33
    {
34
        return $this->scheme;
35
    }
36
37
    public function getParameters(): array
38
    {
39
        return $this->parameters;
40
    }
41
42
    public function getParameter(string $key, $default = null)
43
    {
44
        return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
45
    }
46
47
    public function getHost(): ?string
48
    {
49
        return null;
50
    }
51
52
    public function getPort(): ?int
53
    {
54
        return null;
55
    }
56
57
    public function getPath(): ?string
58
    {
59
        return null;
60
    }
61
62
    public function getUser(): ?string
63
    {
64
        return null;
65
    }
66
67
    public function getPassword(): ?string
68
    {
69
        return null;
70
    }
71
72
    /**
73
     * @var string
74
     */
75
    public function __toString()
76
    {
77
        return sprintf('%s://%s', $this->getScheme(), empty($this->parameters) ? '' : '?'.http_build_query($this->parameters));
78
    }
79
}
80