Passed
Push — 4 ( 35dfb3...cb05e5 )
by Maxime
07:42 queued 14s
created

MockUri   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 96
rs 10
wmc 18

17 Methods

Rating   Name   Duplication   Size   Complexity  
A withFragment() 0 3 1
A __construct() 0 7 1
A withScheme() 0 3 1
A getHost() 0 3 1
A getUserInfo() 0 2 1
A withPath() 0 3 1
A getFragment() 0 2 1
A withUserInfo() 0 3 1
A __toString() 0 9 2
A getAuthority() 0 2 1
A getPort() 0 2 1
A getScheme() 0 3 1
A withPort() 0 3 1
A withHost() 0 3 1
A getQuery() 0 3 1
A withQuery() 0 3 1
A getPath() 0 3 1
1
<?php
2
3
namespace SilverStripe\View\Tests\Embed;
4
5
use Psr\Http\Message\UriInterface;
6
7
class MockUri implements UriInterface
8
{
9
    private string $scheme;
10
    private string $host;
11
    private string $path;
12
    private string $query;
13
14
    public function __construct(string $url)
15
    {
16
        $p = parse_url($url);
17
        $this->scheme = $p['scheme'] ?? '';
18
        $this->host = $p['host'] ?? '';
19
        $this->path = $p['path'] ?? '';
20
        $this->query = $p['query'] ?? '';
21
    }
22
23
    public function getScheme()
24
    {
25
        return $this->scheme;
26
    }
27
28
    public function getHost()
29
    {
30
        return $this->host;
31
    }
32
33
    public function getPath()
34
    {
35
        return $this->path;
36
    }
37
38
    public function getQuery()
39
    {
40
        return $this->query;
41
    }
42
43
    public function getPort()
44
    {
45
    }
46
47
    public function getAuthority()
48
    {
49
    }
50
51
    public function getUserInfo()
52
    {
53
    }
54
55
    public function getFragment()
56
    {
57
    }
58
59
    public function withPath($path)
60
    {
61
        return $this;
62
    }
63
64
    public function withScheme($scheme)
65
    {
66
        return $this;
67
    }
68
69
    public function withUserInfo($user, $password = null)
70
    {
71
        return $this;
72
    }
73
74
    public function withHost($host)
75
    {
76
        return $this;
77
    }
78
79
    public function withPort($port)
80
    {
81
        return $this;
82
    }
83
84
    public function withQuery($query)
85
    {
86
        return $this;
87
    }
88
89
    public function withFragment($fragment)
90
    {
91
        return $this;
92
    }
93
94
    public function __toString()
95
    {
96
        $query = $this->getQuery();
97
        return sprintf(
98
            '%s://%s%s%s',
99
            $this->getScheme(),
100
            $this->getHost(),
101
            '/' . ltrim($this->getPath(), '/'),
102
            $query ? "?$query" : ''
103
        );
104
    }
105
}
106