GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2f0bc6...b62162 )
by Marius
04:15
created

Url::getUrl()   D

Complexity

Conditions 11
Paths 128

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 11

Importance

Changes 0
Metric Value
cc 11
eloc 17
nc 128
nop 0
dl 0
loc 27
ccs 15
cts 15
cp 1
crap 11
rs 4.9629
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Marius Orcsik <[email protected]>
4
 * @created 2015-07-03
5
 */
6
namespace vsc\infrastructure\urls;
7
8
use vsc\infrastructure\Object;
9
10
class Url extends Object
11
{
12
	static protected $queryEncodingType = PHP_QUERY_RFC1738;
13
	static protected $validSchemes = ['http', 'https', 'file'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
14
15
	/**
16
	 * @var string
17
	 */
18
	private $scheme;
19
	/**
20
	 * @var string
21
	 */
22
	private $host;
23
	/**
24
	 * @var int
25
	 */
26
	private $port;
27
	/**
28
	 * @var string
29
	 */
30
	private $path;
31
	/**
32
	 * @var array
33
	 */
34
	private $query = [];
35
	/**
36
	 * @var string
37
	 */
38
	private $fragment;
39
40 1
	public function __toString() {
41 1
		return $this->getUrl();
42
	}
43
44
	/**
45
	 * @param string $scheme
46
	 */
47 19
	public function setScheme($scheme) {
48 19
		if (static::isValidScheme($scheme)) {
49 19
			$this->scheme = $scheme;
50
		}
51 19
	}
52
53
	/**
54
	 * @param string $host
55
	 */
56 2
	public function setHost($host) {
57 2
		$this->host = $host;
58 2
	}
59
60
	/**
61
	 * @param int $port
62
	 */
63 1
	public function setPort($port) {
64 1
		$this->port = $port;
65 1
	}
66
67
	/**
68
	 * @param string $path
69
	 */
70 18
	public function setPath($path) {
71 18
		$this->path = $path;
72 18
	}
73
	/**
74
	 * @param [] $query
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
75
	 */
76 1
	public function setQuery($query) {
77 1
		$this->query = $query;
78 1
	}
79
	/**
80
	 * @param string $query
81
	 */
82 1
	public function setRawQuery($query) {
83 1
		parse_str($query, $this->query);
84 1
	}
85
86
	/**
87
	 * @param string $fragment
88
	 */
89 1
	public function setFragment($fragment) {
90 1
		$this->fragment = $fragment;
91 1
	}
92
93
	/**
94
	 * @return string
95
	 */
96 1
	public function getScheme() {
97 1
		return $this->scheme;
98
	}
99
100
	/**
101
	 * @return string
102
	 */
103 1
	public function getHost() {
104 1
		return $this->host;
105
	}
106
107
	/**
108
	 * @return int
109
	 */
110 1
	public function getPort() {
111 1
		return $this->port;
112
	}
113
114
	/**
115
	 * @return string
116
	 */
117 18
	public function getPath() {
118 18
		return UrlParserA::normalizePath($this->path);
119
	}
120
121
	/**
122
	 * @return array
123
	 */
124 2
	public function getQuery() {
125 2
		return $this->query;
126
	}
127
128
	/**
129
	 * @param bool $encoded
130
	 * @return string
131
	 */
132 1
	public function getRawQueryString($encoded = true) {
133 1
		return http_build_query($this->getQuery(), '', $encoded ? '&amp;' : '&', static::$queryEncodingType);
134
	}
135
136
	/**
137
	 * @return string
138
	 */
139 1
	public function getFragment() {
140 1
		return $this->fragment;
141
	}
142
143
	/**
144
	 * @param string $schema
145
	 * @return bool
146
	 */
147 19
	static public function isValidScheme($schema) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
148 19
		return in_array($schema, static::$validSchemes);
149
	}
150
151
	/**
152
	 * @return bool
153
	 */
154 1
	public function hasScheme() {
155 1
		return static::isValidScheme($this->scheme);
156
	}
157
158
	/**
159
	 * @return bool
160
	 */
161 1
	public function hasHost() {
162 1
		return (null !== $this->host);
163
	}
164
165
	/**
166
	 * @return bool
167
	 */
168
	public function hasPort() {
169
		return (null !== $this->port);
170
	}
171
172
	/**
173
	 * @return bool
174
	 */
175 1
	public function hasPath() {
176 1
		return !empty($this->path);
177
	}
178
179
	/**
180
	 * @return bool
181
	 */
182 1
	public function hasQuery() {
183 1
		return count($this->query) > 0;
184
	}
185
186
	/**
187
	 * @return bool
188
	 */
189 1
	public function hasFragment() {
190 1
		return (null !== $this->fragment);
191
	}
192
193
	/**
194
	 * @return bool
195
	 */
196 3
	public function isLocal() {
197 3
		return (($this->getScheme() == 'file' || !$this->hasScheme()) && !$this->hasHost() && $this->hasPath());
198
	}
199
200
	/**
201
	 * @return string
202
	 */
203 2
	public function getUrl() {
204 2
		$rawUrl = '';
205 2
		if ($this->hasScheme() && $this->hasHost()) {
206 1
			$rawUrl .= $this->getScheme() . '://';
207
		}
208 2
		if ($this->hasHost()) {
209 1
			$rawUrl .= $this->getHost();
210
		}
211 2
		if ($this->hasPort() && $this->getPort() != 80) {
212
			$rawUrl .= ':' . $this->getPort();
213
		}
214 2
		if ($this->hasPath()) {
215
			// this needs normalization
216 1
			$rawUrl .= $this->getPath();
217
		}
218 2
		if (!empty($rawUrl) && !UrlParserA::hasGoodTermination($rawUrl)) {
219
			$rawUrl .= '/';
220
		}
221 2
		if ($this->hasQuery()) {
222 1
			$rawUrl .= '?' . $this->getRawQueryString();
223
		}
224 2
		if ($this->hasFragment()) {
225 1
			$rawUrl .= '#' . $this->getFragment();
226
		}
227
228 2
		return $rawUrl;
229
	}
230
231
	/**
232
	 * @param string $sPath
233
	 * @returns UrlParserA
234
	 */
235 3
	public function addPath($sPath) {
236 3
		$sExistingPath = $this->getPath();
237 3
		if (substr($sExistingPath, -1) != '/') {
238 3
			$sPath = '/' . $sPath;
239
		}
240 3
		$this->setPath($sExistingPath . $sPath);
241 3
		return $this;
242
	}
243
244
}
245