Completed
Push — master ( 600877...0dfca5 )
by smiley
01:35
created

HTTPClientTrait::normalizeRequestHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Trait HTTPClientTrait
4
 *
5
 * @filesource   HTTPClientTrait.php
6
 * @created      28.01.2018
7
 * @package      chillerlan\HTTP
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\HTTP;
14
15
trait HTTPClientTrait{
16
17
	/**
18
	 * @var \chillerlan\HTTP\HTTPClientInterface
19
	 */
20
	private $http;
21
22
	/**
23
	 * @param \chillerlan\HTTP\HTTPClientInterface $http
24
	 *
25
	 * @return $this
26
	 */
27
	protected function setHTTPClient(HTTPClientInterface $http){
28
		$this->http = $http;
29
30
		return $this;
31
	}
32
33
	/**
34
	 * @param string      $url
35
	 * @param array|null  $params
36
	 * @param string|null $method
37
	 * @param null        $body
38
	 * @param array|null  $headers
39
	 *
40
	 * @return \chillerlan\HTTP\HTTPResponseInterface
41
	 */
42
	protected function httpRequest(string $url, array $params = null, string $method = null, $body = null, array $headers = null):HTTPResponseInterface{
43
		return $this->http->request($url, $params, $method, $body, $headers);
44
	}
45
46
	/**
47
	 * @param string     $url
48
	 * @param array|null $params
49
	 * @param array|null $headers
50
	 *
51
	 * @return \chillerlan\HTTP\HTTPResponseInterface
52
	 */
53
	protected function httpDELETE(string $url, array $params = null, array $headers = null):HTTPResponseInterface{
54
		return $this->http->request($url, $params, 'DELETE', null, $headers);
55
	}
56
57
	/**
58
	 * @param string     $url
59
	 * @param array|null $params
60
	 * @param array|null $headers
61
	 *
62
	 * @return \chillerlan\HTTP\HTTPResponseInterface
63
	 */
64
	protected function httpGET(string $url, array $params = null, array $headers = null):HTTPResponseInterface{
65
		return $this->http->request($url, $params, 'GET', null, $headers);
66
	}
67
68
	/**
69
	 * @param string     $url
70
	 * @param array|null $params
71
	 * @param null       $body
72
	 * @param array|null $headers
73
	 *
74
	 * @return \chillerlan\HTTP\HTTPResponseInterface
75
	 */
76
	protected function httpPATCH(string $url, array $params = null, $body = null, array $headers = null):HTTPResponseInterface{
77
		return $this->http->request($url, $params, 'PATCH', $body, $headers);
78
	}
79
80
	/**
81
	 * @param string     $url
82
	 * @param array|null $params
83
	 * @param null       $body
84
	 * @param array|null $headers
85
	 *
86
	 * @return \chillerlan\HTTP\HTTPResponseInterface
87
	 */
88
	protected function httpPOST(string $url, array $params = null, $body = null, array $headers = null):HTTPResponseInterface{
89
		return $this->http->request($url, $params, 'POST', $body, $headers);
90
	}
91
92
	/**
93
	 * @param string     $url
94
	 * @param array|null $params
95
	 * @param null       $body
96
	 * @param array|null $headers
97
	 *
98
	 * @return \chillerlan\HTTP\HTTPResponseInterface
99
	 */
100
	protected function httpPUT(string $url, array $params = null, $body = null, array $headers = null):HTTPResponseInterface{
101
		return $this->http->request($url, $params, 'PUT', $body, $headers);
102
	}
103
104
	/**
105
	 * @param array $headers
106
	 */
107
	protected function normalizeRequestHeaders(array $headers){
108
		$this->http->normalizeRequestHeaders($headers);
109
	}
110
111
	/**
112
	 * @param mixed     $params
113
	 * @param bool|null $booleans_as_string
114
	 *
115
	 * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be object|integer|double|string|null|boolean|array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
116
	 */
117
	protected function checkParams($params, bool $booleans_as_string = null){
118
119
		if(is_array($params)){
120
			$this->http->checkQueryParams($params, $booleans_as_string);
121
		}
122
123
		return $params;
124
	}
125
126
	/**
127
	 * @param array       $params
128
	 * @param bool|null   $urlencode
129
	 * @param string|null $delimiter
130
	 * @param string|null $enclosure
131
	 *
132
	 * @return string
133
	 */
134
	protected function httpBuildQuery(array $params, bool $urlencode = null, string $delimiter = null, string $enclosure = null):string {
135
		return $this->http->buildQuery($params, $urlencode, $delimiter, $enclosure);
136
	}
137
138
}
139