@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * |
19 | 19 | */ |
20 | -class Response implements ResponseInterface{ |
|
20 | +class Response implements ResponseInterface { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var resource |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @throws \chillerlan\TinyCurl\Response\ResponseException |
53 | 53 | */ |
54 | - public function __construct($curl){ |
|
54 | + public function __construct($curl) { |
|
55 | 55 | |
56 | - if(!$curl){ |
|
56 | + if (!$curl) { |
|
57 | 57 | throw new ResponseException('!$curl'); |
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->curl = $curl; |
61 | - $this->curl_info = new stdClass; |
|
61 | + $this->curl_info = new stdClass; |
|
62 | 62 | $this->response_error = new stdClass; |
63 | 63 | $this->response_headers = new stdClass; |
64 | 64 | |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | /** |
69 | 69 | * Farewell. |
70 | 70 | */ |
71 | - public function __destruct(){ |
|
72 | - if($this->curl){ |
|
71 | + public function __destruct() { |
|
72 | + if ($this->curl) { |
|
73 | 73 | curl_close($this->curl); |
74 | 74 | } |
75 | 75 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @return mixed |
81 | 81 | * @throws \chillerlan\TinyCurl\Response\ResponseException |
82 | 82 | */ |
83 | - public function __get($property){ |
|
83 | + public function __get($property) { |
|
84 | 84 | |
85 | - switch($property){ |
|
85 | + switch ($property) { |
|
86 | 86 | case 'body' : return $this->getBody(); |
87 | 87 | case 'info' : return $this->curl_info; |
88 | 88 | case 'json' : return json_decode($this->response_body); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * Fills self::$response_body and calls self::getInfo() |
98 | 98 | */ |
99 | - protected function exec(){ |
|
99 | + protected function exec() { |
|
100 | 100 | curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, 'headerLine']); |
101 | 101 | $this->response_body = curl_exec($this->curl); |
102 | 102 | $this->getInfo(); |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @link http://php.net/manual/function.curl-setopt.php CURLOPT_HEADERFUNCTION |
112 | 112 | */ |
113 | - protected function headerLine(/** @noinspection PhpUnusedParameterInspection */$curl, $header_line){ |
|
113 | + protected function headerLine(/** @noinspection PhpUnusedParameterInspection */$curl, $header_line) { |
|
114 | 114 | |
115 | - if(substr($header_line, 0, 4) === 'HTTP'){ |
|
115 | + if (substr($header_line, 0, 4) === 'HTTP') { |
|
116 | 116 | $status = explode(' ', $header_line, 3); |
117 | 117 | |
118 | 118 | $this->response_headers->httpversion = explode('/', $status[0], 2)[1]; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $h = explode(':', $header_line, 2); |
124 | - if(count($h) === 2){ |
|
124 | + if (count($h) === 2) { |
|
125 | 125 | $this->response_headers->{trim(strtolower($h[0]))} = trim($h[1]); |
126 | 126 | } |
127 | 127 | |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * @return \stdClass |
133 | 133 | */ |
134 | - protected function getBody(){ |
|
134 | + protected function getBody() { |
|
135 | 135 | $body = new stdClass; |
136 | 136 | |
137 | 137 | $body->content = $this->response_body; |
138 | 138 | $body->length = strlen($this->response_body); |
139 | 139 | |
140 | - if(isset($this->curl_info->content_type) && !empty($this->curl_info->content_type)){ |
|
140 | + if (isset($this->curl_info->content_type) && !empty($this->curl_info->content_type)) { |
|
141 | 141 | $body->content_type = $this->curl_info->content_type; |
142 | 142 | } |
143 | 143 | // @codeCoverageIgnoreStart |
144 | - elseif(isset($this->response_headers->content_type) && !empty($this->response_headers->content_type)){ |
|
144 | + elseif (isset($this->response_headers->content_type) && !empty($this->response_headers->content_type)) { |
|
145 | 145 | $body->content_type = $this->response_headers->content_type; |
146 | 146 | } |
147 | 147 | // @codeCoverageIgnoreEnd |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * |
154 | 154 | */ |
155 | - protected function getInfo(){ |
|
155 | + protected function getInfo() { |
|
156 | 156 | $curl_info = curl_getinfo($this->curl); |
157 | - if(is_array($curl_info)){ |
|
158 | - foreach($curl_info as $key => $value){ |
|
157 | + if (is_array($curl_info)) { |
|
158 | + foreach ($curl_info as $key => $value) { |
|
159 | 159 | $this->curl_info->{$key} = $value; |
160 | 160 | } |
161 | 161 | } |
@@ -16,6 +16,6 @@ |
||
16 | 16 | /** |
17 | 17 | * Class ResponseException |
18 | 18 | */ |
19 | -class ResponseException extends Exception{ |
|
19 | +class ResponseException extends Exception { |
|
20 | 20 | |
21 | 21 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * @property mixed info |
18 | 18 | * @property mixed json |
19 | 19 | */ |
20 | -interface ResponseInterface{ |
|
20 | +interface ResponseInterface { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param string $property |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * Trait RequestTrait |
20 | 20 | */ |
21 | -trait RequestTrait{ |
|
21 | +trait RequestTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Path to the CA cert file |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @return \chillerlan\TinyCurl\Response\ResponseInterface |
39 | 39 | * @throws \chillerlan\TinyCurl\RequestException |
40 | 40 | */ |
41 | - protected function fetch($url, array $params = [], array $curl_options = []){ |
|
41 | + protected function fetch($url, array $params = [], array $curl_options = []) { |
|
42 | 42 | $requestOptions = new RequestOptions; |
43 | 43 | $requestOptions->curl_options = $curl_options; |
44 | 44 | $requestOptions->ca_info = $this->ca_info; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return $this |
55 | 55 | */ |
56 | - protected function setRequestCA($ca_info){ |
|
56 | + protected function setRequestCA($ca_info) { |
|
57 | 57 | $this->ca_info = $ca_info; |
58 | 58 | |
59 | 59 | return $this; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @property array params |
26 | 26 | * @property array parsedquery |
27 | 27 | */ |
28 | -class URL{ |
|
28 | +class URL { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var string |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * @param array $params |
85 | 85 | * @param string $method |
86 | 86 | */ |
87 | - public function __construct($url, array $params = [], $method = 'GET'){ |
|
87 | + public function __construct($url, array $params = [], $method = 'GET') { |
|
88 | 88 | $this->url = $url; |
89 | 89 | $this->params = $params; |
90 | 90 | |
91 | - if(in_array(strtoupper($method), ['GET', 'POST'])){ |
|
91 | + if (in_array(strtoupper($method), ['GET', 'POST'])) { |
|
92 | 92 | $this->method = $method; |
93 | 93 | } |
94 | 94 | |
95 | 95 | $url = parse_url($url); |
96 | - $this->host = !isset($url['host']) ? null : $url['host']; |
|
97 | - $this->port = !isset($url['port']) ? null : $url['port']; |
|
98 | - $this->path = !isset($url['path']) ? null : $url['path']; |
|
99 | - $this->scheme = !isset($url['scheme']) ? null : $url['scheme']; |
|
100 | - $this->query = !isset($url['query']) ? null : $url['query']; |
|
101 | - $this->fragment = !isset($url['fragment']) ? null : $url['fragment']; |
|
102 | - |
|
103 | - if($this->query){ |
|
96 | + $this->host = !isset($url['host']) ? null : $url['host']; |
|
97 | + $this->port = !isset($url['port']) ? null : $url['port']; |
|
98 | + $this->path = !isset($url['path']) ? null : $url['path']; |
|
99 | + $this->scheme = !isset($url['scheme']) ? null : $url['scheme']; |
|
100 | + $this->query = !isset($url['query']) ? null : $url['query']; |
|
101 | + $this->fragment = !isset($url['fragment']) ? null : $url['fragment']; |
|
102 | + |
|
103 | + if ($this->query) { |
|
104 | 104 | parse_str($this->query, $this->parsedquery); |
105 | 105 | } |
106 | 106 | |
@@ -111,21 +111,21 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return mixed |
113 | 113 | */ |
114 | - public function __get($name){ |
|
114 | + public function __get($name) { |
|
115 | 115 | return $this->{$name}; |
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - public function __toString(){ |
|
121 | + public function __toString() { |
|
122 | 122 | return $this->mergeParams(); |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public function overrideParams(){ |
|
128 | + public function overrideParams() { |
|
129 | 129 | $url = $this->getURL(); |
130 | 130 | $url .= '?'.http_build_query($this->params); |
131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function mergeParams(){ |
|
138 | + public function mergeParams() { |
|
139 | 139 | $url = $this->getURL(); |
140 | 140 | $url .= '?'.http_build_query(array_merge($this->parsedquery, $this->params)); |
141 | 141 | |
@@ -145,23 +145,23 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - protected function getURL(){ |
|
148 | + protected function getURL() { |
|
149 | 149 | $url = ''; |
150 | 150 | |
151 | - if($this->scheme){ |
|
151 | + if ($this->scheme) { |
|
152 | 152 | $url .= $this->scheme.':'; |
153 | 153 | } |
154 | 154 | |
155 | - if($this->host){ |
|
155 | + if ($this->host) { |
|
156 | 156 | $url .= '//'.$this->host; |
157 | 157 | |
158 | - if($this->port){ |
|
158 | + if ($this->port) { |
|
159 | 159 | $url .= ':'.$this->port; |
160 | 160 | } |
161 | 161 | |
162 | 162 | } |
163 | 163 | |
164 | - if($this->path){ |
|
164 | + if ($this->path) { |
|
165 | 165 | $url .= $this->path; |
166 | 166 | } |
167 | 167 |