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

Path   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 9 2
A getPath() 0 3 1
A getScheme() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Dsn\Configuration;
6
7
/**
8
 * A "path like" DSN string.
9
 *
10
 * Example:
11
 * - redis:///var/run/redis/redis.sock
12
 * - memcached://user:password@/var/local/run/memcached.socket?weight=25
13
 *
14
 * @author Tobias Nyholm <[email protected]>
15
 */
16
class Path extends Dsn
17
{
18
    use UserPasswordTrait;
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    public function __construct(string $scheme, string $path, array $parameters = [], array $authentication = [])
25
    {
26
        $this->path = $path;
27
        $this->setAuthentication($authentication);
28
        parent::__construct($scheme, $parameters);
29
    }
30
31
    public function getScheme(): string
32
    {
33
        return parent::getScheme();
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getScheme() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
34
    }
35
36
    public function getPath(): string
37
    {
38
        return $this->path;
39
    }
40
41
    /**
42
     * @var string
43
     */
44
    public function __toString()
45
    {
46
        $parameters = $this->getParameters();
47
48
        return
49
            $this->getScheme().'://'.
50
            $this->getUserInfoString().
51
            $this->getPath().
52
            (empty($parameters) ? '' : '?'.http_build_query($parameters));
53
    }
54
}
55