Completed
Push — master ( 4b7f62...6a99e5 )
by Nazar
04:14
created

prepare.php ➔ http_build_url()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 13
nc 4
nop 2
dl 0
loc 17
rs 9.2
1
<?php
2
/**
3
 * @package   OAuth2
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace	cs\modules\OAuth2;
10
/**
11
 * Just replaces first "?" symbol by "#"
12
 *
13
 * @param string	$str
14
 *
15
 * @return string
16
 */
17
function uri_for_token ($str) {
18
	return implode(
19
		'#',
20
		explode(
21
			'?',
22
			$str,
23
			2
24
		)
25
	);
26
}
27
/**
28
 * @param string	$url
0 ignored issues
show
Documentation introduced by
Should the type for parameter $url not be mixed? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
 * @param string[]	$parts
0 ignored issues
show
Documentation introduced by
Should the type for parameter $parts not be mixed? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
30
 *
31
 * @return string
32
 */
33
function http_build_url ($url, $parts) {
34
	$url	= explode('?', $url, 2);
35
	$params	= [];
36
	if (isset($url[1])) {
37
		foreach (explode('&', $url[1]) as $u) {
38
			$params[]	= $u;
39
		}
40
		unset($u, $url[1]);
41
	}
42
	$url	= $url[0];
43
	foreach ($parts as $name => $value) {
44
		$params[]	= $name.'='.urlencode($value);
45
	}
46
	unset($parts, $p);
47
	$params	= array_unique($params);
48
	return "$url?".implode('&', $params);
49
}
50