Completed
Push — master ( da88de...163d4a )
by Joschi
03:49
created

Psr7Trait   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 228
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 228
ccs 34
cts 34
cp 1
rs 10
wmc 20
lcom 1
cbo 1

23 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
A getHost() 0 4 2
A getPort() 0 4 2
A getFragment() 0 4 2
A getQuery() 0 4 2
A getScheme() 0 4 2
A getAuthority() 0 6 1
A getUserInfo() 0 6 1
A withScheme() 0 4 1
A withUserInfo() 0 4 1
A withHost() 0 4 1
A withPort() 0 4 1
A withPath() 0 4 1
A withQuery() 0 4 1
A withFragment() 0 4 1
setScheme() 0 1 ?
setUser() 0 1 ?
setHost() 0 1 ?
setPort() 0 1 ?
setPath() 0 1 ?
setQuery() 0 1 ?
setFragment() 0 1 ?
getUrlInternal() 0 1 ?
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Domain
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Domain\Model\Uri\Traits;
38
39
use Apparat\Object\Domain\Model\Uri\Url;
40
41
/**
42
 * PSR-7 URI trait
43
 *
44
 * @package Apparat\Object\Domain\Model\Uri\Traits
45
 * @property array $urlParts
46
 */
47
trait Psr7Trait
48
{
49
    /**
50
     * Return the URL path
51
     *
52
     * @return string URL path
53
     */
54 43
    public function getPath()
55
    {
56 43
        return $this->urlParts['path'];
57
    }
58
59
    /**
60
     * Return the URL host
61
     *
62
     * @return string URL host
63
     */
64 36
    public function getHost()
65
    {
66 36
        return isset($this->urlParts['host']) ? $this->urlParts['host'] : null;
67
    }
68
69
    /**
70
     * Return the URL port
71
     *
72
     * @return int URL port
73
     */
74 12
    public function getPort()
75
    {
76 12
        return isset($this->urlParts['port']) ? $this->urlParts['port'] : null;
77
    }
78
79
    /**
80
     * Return the URL fragment
81
     *
82
     * @return string URL fragment
83
     */
84 12
    public function getFragment()
85
    {
86 12
        return isset($this->urlParts['fragment']) ? $this->urlParts['fragment'] : null;
87
    }
88
89
    /**
90
     * Return the URL query
91
     *
92
     * @return array URL query
93
     */
94 7
    public function getQuery()
95
    {
96 7
        return isset($this->urlParts['query']) ? $this->urlParts['query'] : '';
97
    }
98
99
    /**
100
     * Return the URL scheme
101
     *
102
     * @return string URL scheme
103
     */
104 36
    public function getScheme()
105
    {
106 36
        return isset($this->urlParts['scheme']) ? $this->urlParts['scheme'] : null;
107
    }
108
109
    /**
110
     * Return the URL authority
111
     *
112
     * @return string
113
     */
114 1
    public function getAuthority()
115
    {
116 1
        $uriParts = [];
117 1
        $this->getUrlInternal($uriParts);
118 1
        return $uriParts['user'].$uriParts['pass'].$uriParts['host'].$uriParts['port'];
119
    }
120
121
    /**
122
     * Return the URL user info
123
     *
124
     * @return string
125
     */
126 1
    public function getUserInfo()
127
    {
128 1
        $uriParts = [];
129 1
        $this->getUrlInternal($uriParts);
130 1
        return rtrim($uriParts['user'].$uriParts['pass'], '@');
131
    }
132
133
    /**
134
     * Return an instance of this URL with the given scheme
135
     *
136
     * @param string $scheme Scheme
137
     * @return Url Instance with the given scheme
138
     */
139 1
    public function withScheme($scheme)
140
    {
141 1
        return $this->setScheme($scheme);
142
    }
143
144
    /**
145
     * Return an instance of this URL with the given user info
146
     *
147
     * @param string $user User name
148
     * @param string|null $password Password
149
     * @return Url URL instance with given user info
150
     */
151 1
    public function withUserInfo($user, $password = null)
152
    {
153 1
        return $this->setUser($user)->setPassword($password);
154
    }
155
156
    /**
157
     * Return an instance of this URL with the given host
158
     *
159
     * @param string $host Host
160
     * @return Url Instance with the given host
161
     */
162 1
    public function withHost($host)
163
    {
164 1
        return $this->setHost($host);
165
    }
166
167
    /**
168
     * Return an instance of this URL with the given port
169
     *
170
     * @param null|int $port Port
171
     * @return Url Instance with the given port
172
     */
173 1
    public function withPort($port)
174
    {
175 1
        return $this->setPort($port);
176
    }
177
178
    /**
179
     * Return an instance of this URL with the given path
180
     *
181
     * @param null|int $path Path
182
     * @return Url Instance with the given path
183
     */
184 1
    public function withPath($path)
185
    {
186 1
        return $this->setPath($path);
187
    }
188
189
    /**
190
     * Return an instance of this URL with the given query
191
     *
192
     * @param null|string $query Query
193
     * @return Url Instance with the given query
194
     */
195 1
    public function withQuery($query)
196
    {
197 1
        return $this->setQuery($query);
198
    }
199
200
    /**
201
     * Return an instance of this URL with the given fragment
202
     *
203
     * @param null|int $fragment Fragment
204
     * @return Url Instance with the given fragment
205
     */
206 1
    public function withFragment($fragment)
207
    {
208 1
        return $this->setFragment($fragment);
209
    }
210
211
    /**
212
     * Set the URL scheme
213
     *
214
     * @param string $scheme URL scheme
215
     * @return Url New URL
216
     */
217
    abstract public function setScheme($scheme);
218
219
    /**
220
     * Set the URL user
221
     *
222
     * @param string|NULL $user URL user
223
     * @return Url New URL
224
     */
225
    abstract public function setUser($user);
226
227
    /**
228
     * Set the URL host
229
     *
230
     * @param string $host URL host
231
     * @return Url New URL
232
     */
233
    abstract public function setHost($host);
234
235
    /**
236
     * Set the URL port
237
     *
238
     * @param int|null $port URL port
239
     * @return Url New URL
240
     */
241
    abstract public function setPort($port);
242
243
    /**
244
     * Set the URL path
245
     *
246
     * @param string $path URL path
247
     * @return Url New URL
248
     */
249
    abstract public function setPath($path);
250
251
    /**
252
     * Set the URL query
253
     *
254
     * @param string $query URL query
255
     * @return Url New URL
256
     */
257
    abstract public function setQuery($query);
258
259
    /**
260
     * Set the URL fragment
261
     *
262
     * @param string $fragment URL fragment
263
     * @return Url New URL
264
     */
265
    abstract public function setFragment($fragment);
266
267
    /**
268
     * Return the a complete serialized URL
269
     *
270
     * @param array $override Override components
271
     * @return string Serialized URL
272
     */
273
    abstract protected function getUrlInternal(array &$override = []);
274
}
275