Completed
Push — master ( 16e812...ea693b )
by mains
02:48
created
php/Requests/GetKarma.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 
4
-class GetKarma extends AbstractRequest {
4
+class GetKarma extends AbstractRequest
5
+{
5 6
 		
6 7
     function getApiEndPoint()
7 8
     {
Please login to merge, or discard this patch.
php/Requests/SetLocation.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 
4
-class SetLocation extends AbstractRequest {
4
+class SetLocation extends AbstractRequest
5
+{
5 6
 		 /**
6 7
      * @var Location
7 8
      */
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Cookie/Jar.php 1 patch
Braces   +40 added lines, -20 removed lines patch added patch discarded remove patch
@@ -25,7 +25,8 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param array $cookies Existing cookie values
27 27
 	 */
28
-	public function __construct($cookies = array()) {
28
+	public function __construct($cookies = array())
29
+	{
29 30
 		$this->cookies = $cookies;
30 31
 	}
31 32
 
@@ -35,8 +36,10 @@  discard block
 block discarded – undo
35 36
 	 * @param string|Requests_Cookie $cookie
36 37
 	 * @return Requests_Cookie
37 38
 	 */
38
-	public function normalize_cookie($cookie, $key = null) {
39
-		if ($cookie instanceof Requests_Cookie) {
39
+	public function normalize_cookie($cookie, $key = null)
40
+	{
41
+		if ($cookie instanceof Requests_Cookie)
42
+		{
40 43
 			return $cookie;
41 44
 		}
42 45
 
@@ -50,7 +53,8 @@  discard block
 block discarded – undo
50 53
 	 * @deprecated Use {@see Requests_Cookie_Jar::normalize_cookie}
51 54
 	 * @return Requests_Cookie
52 55
 	 */
53
-	public function normalizeCookie($cookie, $key = null) {
56
+	public function normalizeCookie($cookie, $key = null)
57
+	{
54 58
 		return $this->normalize_cookie($cookie, $key);
55 59
 	}
56 60
 
@@ -60,7 +64,8 @@  discard block
 block discarded – undo
60 64
 	 * @param string $key Item key
61 65
 	 * @return boolean Does the item exist?
62 66
 	 */
63
-	public function offsetExists($key) {
67
+	public function offsetExists($key)
68
+	{
64 69
 		return isset($this->cookies[$key]);
65 70
 	}
66 71
 
@@ -70,8 +75,10 @@  discard block
 block discarded – undo
70 75
 	 * @param string $key Item key
71 76
 	 * @return string Item value
72 77
 	 */
73
-	public function offsetGet($key) {
74
-		if (!isset($this->cookies[$key])) {
78
+	public function offsetGet($key)
79
+	{
80
+		if (!isset($this->cookies[$key]))
81
+		{
75 82
 			return null;
76 83
 		}
77 84
 
@@ -86,8 +93,10 @@  discard block
 block discarded – undo
86 93
 	 * @param string $key Item name
87 94
 	 * @param string $value Item value
88 95
 	 */
89
-	public function offsetSet($key, $value) {
90
-		if ($key === null) {
96
+	public function offsetSet($key, $value)
97
+	{
98
+		if ($key === null)
99
+		{
91 100
 			throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
92 101
 		}
93 102
 
@@ -99,7 +108,8 @@  discard block
 block discarded – undo
99 108
 	 *
100 109
 	 * @param string $key
101 110
 	 */
102
-	public function offsetUnset($key) {
111
+	public function offsetUnset($key)
112
+	{
103 113
 		unset($this->cookies[$key]);
104 114
 	}
105 115
 
@@ -108,7 +118,8 @@  discard block
 block discarded – undo
108 118
 	 *
109 119
 	 * @return ArrayIterator
110 120
 	 */
111
-	public function getIterator() {
121
+	public function getIterator()
122
+	{
112 123
 		return new ArrayIterator($this->cookies);
113 124
 	}
114 125
 
@@ -117,7 +128,8 @@  discard block
 block discarded – undo
117 128
 	 *
118 129
 	 * @param Requests_Hooker $hooks Hooking system
119 130
 	 */
120
-	public function register(Requests_Hooker $hooks) {
131
+	public function register(Requests_Hooker $hooks)
132
+	{
121 133
 		$hooks->register('requests.before_request', array($this, 'before_request'));
122 134
 		$hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check'));
123 135
 	}
@@ -133,22 +145,28 @@  discard block
 block discarded – undo
133 145
 	 * @param string $type
134 146
 	 * @param array $options
135 147
 	 */
136
-	public function before_request($url, &$headers, &$data, &$type, &$options) {
137
-		if (!$url instanceof Requests_IRI) {
148
+	public function before_request($url, &$headers, &$data, &$type, &$options)
149
+	{
150
+		if (!$url instanceof Requests_IRI)
151
+		{
138 152
 			$url = new Requests_IRI($url);
139 153
 		}
140 154
 
141
-		if (!empty($this->cookies)) {
155
+		if (!empty($this->cookies))
156
+		{
142 157
 			$cookies = array();
143
-			foreach ($this->cookies as $key => $cookie) {
158
+			foreach ($this->cookies as $key => $cookie)
159
+			{
144 160
 				$cookie = $this->normalize_cookie($cookie, $key);
145 161
 
146 162
 				// Skip expired cookies
147
-				if ($cookie->is_expired()) {
163
+				if ($cookie->is_expired())
164
+				{
148 165
 					continue;
149 166
 				}
150 167
 
151
-				if ($cookie->domain_matches($url->host)) {
168
+				if ($cookie->domain_matches($url->host))
169
+				{
152 170
 					$cookies[] = $cookie->format_for_header();
153 171
 				}
154 172
 			}
@@ -162,9 +180,11 @@  discard block
 block discarded – undo
162 180
 	 *
163 181
 	 * @var Requests_Response $response
164 182
 	 */
165
-	public function before_redirect_check(Requests_Response &$return) {
183
+	public function before_redirect_check(Requests_Response &$return)
184
+	{
166 185
 		$url = $return->url;
167
-		if (!$url instanceof Requests_IRI) {
186
+		if (!$url instanceof Requests_IRI)
187
+		{
168 188
 			$url = new Requests_IRI($url);
169 189
 		}
170 190
 
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Auth.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,8 @@
 block discarded – undo
18 18
  * @package Requests
19 19
  * @subpackage Authentication
20 20
  */
21
-interface Requests_Auth {
21
+interface Requests_Auth
22
+{
22 23
 	/**
23 24
 	 * Register hooks as needed
24 25
 	 *
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Proxy/HTTP.php 1 patch
Braces   +30 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,7 +16,8 @@  discard block
 block discarded – undo
16 16
  * @subpackage Proxy
17 17
  * @since 1.6
18 18
  */
19
-class Requests_Proxy_HTTP implements Requests_Proxy {
19
+class Requests_Proxy_HTTP implements Requests_Proxy
20
+{
20 21
 	/**
21 22
 	 * Proxy host and port
22 23
 	 *
@@ -54,19 +55,25 @@  discard block
 block discarded – undo
54 55
 	 * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`)
55 56
 	 * @param array|null $args Array of user and password. Must have exactly two elements
56 57
 	 */
57
-	public function __construct($args = null) {
58
-		if (is_string($args)) {
58
+	public function __construct($args = null)
59
+	{
60
+		if (is_string($args))
61
+		{
59 62
 			$this->proxy = $args;
60 63
 		}
61
-		elseif (is_array($args)) {
62
-			if (count($args) == 1) {
64
+		elseif (is_array($args))
65
+		{
66
+			if (count($args) == 1)
67
+			{
63 68
 				list($this->proxy) = $args;
64 69
 			}
65
-			elseif (count($args) == 3) {
70
+			elseif (count($args) == 3)
71
+			{
66 72
 				list($this->proxy, $this->user, $this->pass) = $args;
67 73
 				$this->use_authentication = true;
68 74
 			}
69
-			else {
75
+			else
76
+			{
70 77
 				throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs');
71 78
 			}
72 79
 		}
@@ -82,12 +89,14 @@  discard block
 block discarded – undo
82 89
 	 * @see fsockopen_header
83 90
 	 * @param Requests_Hooks $hooks Hook system
84 91
 	 */
85
-	public function register(Requests_Hooks &$hooks) {
92
+	public function register(Requests_Hooks &$hooks)
93
+	{
86 94
 		$hooks->register('curl.before_send', array(&$this, 'curl_before_send'));
87 95
 
88 96
 		$hooks->register('fsockopen.remote_socket', array(&$this, 'fsockopen_remote_socket'));
89 97
 		$hooks->register('fsockopen.remote_host_path', array(&$this, 'fsockopen_remote_host_path'));
90
-		if ($this->use_authentication) {
98
+		if ($this->use_authentication)
99
+		{
91 100
 			$hooks->register('fsockopen.after_headers', array(&$this, 'fsockopen_header'));
92 101
 		}
93 102
 	}
@@ -98,11 +107,13 @@  discard block
 block discarded – undo
98 107
 	 * @since 1.6
99 108
 	 * @param resource $handle cURL resource
100 109
 	 */
101
-	public function curl_before_send(&$handle) {
110
+	public function curl_before_send(&$handle)
111
+	{
102 112
 		curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
103 113
 		curl_setopt($handle, CURLOPT_PROXY, $this->proxy);
104 114
 
105
-		if ($this->use_authentication) {
115
+		if ($this->use_authentication)
116
+		{
106 117
 			curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
107 118
 			curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string());
108 119
 		}
@@ -114,7 +125,8 @@  discard block
 block discarded – undo
114 125
 	 * @since 1.6
115 126
 	 * @param string $remote_socket Socket connection string
116 127
 	 */
117
-	public function fsockopen_remote_socket(&$remote_socket) {
128
+	public function fsockopen_remote_socket(&$remote_socket)
129
+	{
118 130
 		$remote_socket = $this->proxy;
119 131
 	}
120 132
 
@@ -125,7 +137,8 @@  discard block
 block discarded – undo
125 137
 	 * @param string $path Path to send in HTTP request string ("GET ...")
126 138
 	 * @param string $url Full URL we're requesting
127 139
 	 */
128
-	public function fsockopen_remote_host_path(&$path, $url) {
140
+	public function fsockopen_remote_host_path(&$path, $url)
141
+	{
129 142
 		$path = $url;
130 143
 	}
131 144
 
@@ -135,7 +148,8 @@  discard block
 block discarded – undo
135 148
 	 * @since 1.6
136 149
 	 * @param string $out HTTP header string
137 150
 	 */
138
-	public function fsockopen_header(&$out) {
151
+	public function fsockopen_header(&$out)
152
+	{
139 153
 		$out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string()));
140 154
 	}
141 155
 
@@ -145,7 +159,8 @@  discard block
 block discarded – undo
145 159
 	 * @since 1.6
146 160
 	 * @return string
147 161
 	 */
148
-	public function get_auth_string() {
162
+	public function get_auth_string()
163
+	{
149 164
 		return $this->user . ':' . $this->pass;
150 165
 	}
151 166
 }
152 167
\ No newline at end of file
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Transport/cURL.php 1 patch
Braces   +134 added lines, -67 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
  * @package Requests
13 13
  * @subpackage Transport
14 14
  */
15
-class Requests_Transport_cURL implements Requests_Transport {
15
+class Requests_Transport_cURL implements Requests_Transport
16
+{
16 17
 	const CURL_7_10_5 = 0x070A05;
17 18
 	const CURL_7_16_2 = 0x071002;
18 19
 
@@ -89,20 +90,24 @@  discard block
 block discarded – undo
89 90
 	/**
90 91
 	 * Constructor
91 92
 	 */
92
-	public function __construct() {
93
+	public function __construct()
94
+	{
93 95
 		$curl = curl_version();
94 96
 		$this->version = $curl['version_number'];
95 97
 		$this->handle = curl_init();
96 98
 
97 99
 		curl_setopt($this->handle, CURLOPT_HEADER, false);
98 100
 		curl_setopt($this->handle, CURLOPT_RETURNTRANSFER, 1);
99
-		if ($this->version >= self::CURL_7_10_5) {
101
+		if ($this->version >= self::CURL_7_10_5)
102
+		{
100 103
 			curl_setopt($this->handle, CURLOPT_ENCODING, '');
101 104
 		}
102
-		if (defined('CURLOPT_PROTOCOLS')) {
105
+		if (defined('CURLOPT_PROTOCOLS'))
106
+		{
103 107
 			curl_setopt($this->handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
104 108
 		}
105
-		if (defined('CURLOPT_REDIR_PROTOCOLS')) {
109
+		if (defined('CURLOPT_REDIR_PROTOCOLS'))
110
+		{
106 111
 			curl_setopt($this->handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
107 112
 		}
108 113
 	}
@@ -110,8 +115,10 @@  discard block
 block discarded – undo
110 115
 	/**
111 116
 	 * Destructor
112 117
 	 */
113
-	public function __destruct() {
114
-		if (is_resource($this->handle)) {
118
+	public function __destruct()
119
+	{
120
+		if (is_resource($this->handle))
121
+		{
115 122
 			curl_close($this->handle);
116 123
 		}
117 124
 	}
@@ -127,35 +134,42 @@  discard block
 block discarded – undo
127 134
 	 * @param array $options Request options, see {@see Requests::response()} for documentation
128 135
 	 * @return string Raw HTTP result
129 136
 	 */
130
-	public function request($url, $headers = array(), $data = array(), $options = array()) {
137
+	public function request($url, $headers = array(), $data = array(), $options = array())
138
+	{
131 139
 		$this->hooks = $options['hooks'];
132 140
 
133 141
 		$this->setup_handle($url, $headers, $data, $options);
134 142
 
135 143
 		$options['hooks']->dispatch('curl.before_send', array(&$this->handle));
136 144
 
137
-		if ($options['filename'] !== false) {
145
+		if ($options['filename'] !== false)
146
+		{
138 147
 			$this->stream_handle = fopen($options['filename'], 'wb');
139 148
 		}
140 149
 
141 150
 		$this->response_data = '';
142 151
 		$this->response_bytes = 0;
143 152
 		$this->response_byte_limit = false;
144
-		if ($options['max_bytes'] !== false) {
153
+		if ($options['max_bytes'] !== false)
154
+		{
145 155
 			$this->response_byte_limit = $options['max_bytes'];
146 156
 		}
147 157
 
148
-		if (isset($options['verify'])) {
149
-			if ($options['verify'] === false) {
158
+		if (isset($options['verify']))
159
+		{
160
+			if ($options['verify'] === false)
161
+			{
150 162
 				curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
151 163
 				curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
152 164
 			}
153
-			elseif (is_string($options['verify'])) {
165
+			elseif (is_string($options['verify']))
166
+			{
154 167
 				curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
155 168
 			}
156 169
 		}
157 170
 
158
-		if (isset($options['verifyname']) && $options['verifyname'] === false) {
171
+		if (isset($options['verifyname']) && $options['verifyname'] === false)
172
+		{
159 173
 			curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
160 174
 		}
161 175
 
@@ -164,7 +178,8 @@  discard block
 block discarded – undo
164 178
 
165 179
 		$options['hooks']->dispatch('curl.after_send', array());
166 180
 
167
-		if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61) {
181
+		if (curl_errno($this->handle) === 23 || curl_errno($this->handle) === 61)
182
+		{
168 183
 			// Reset encoding and try again
169 184
 			curl_setopt($this->handle, CURLOPT_ENCODING, 'none');
170 185
 
@@ -191,9 +206,11 @@  discard block
 block discarded – undo
191 206
 	 * @param array $options Global options
192 207
 	 * @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
193 208
 	 */
194
-	public function request_multiple($requests, $options) {
209
+	public function request_multiple($requests, $options)
210
+	{
195 211
 		// If you're not requesting, we can't get any responses ¯\_(ツ)_/¯
196
-		if (empty($requests)) {
212
+		if (empty($requests))
213
+		{
197 214
 			return array();
198 215
 		}
199 216
 
@@ -202,7 +219,8 @@  discard block
 block discarded – undo
202 219
 		$subhandles = array();
203 220
 
204 221
 		$class = get_class($this);
205
-		foreach ($requests as $id => $request) {
222
+		foreach ($requests as $id => $request)
223
+		{
206 224
 			$subrequests[$id] = new $class();
207 225
 			$subhandles[$id] = $subrequests[$id]->get_subrequest_handle($request['url'], $request['headers'], $request['data'], $request['options']);
208 226
 			$request['options']['hooks']->dispatch('curl.before_multi_add', array(&$subhandles[$id]));
@@ -214,10 +232,12 @@  discard block
 block discarded – undo
214 232
 
215 233
 		$request['options']['hooks']->dispatch('curl.before_multi_exec', array(&$multihandle));
216 234
 
217
-		do {
235
+		do
236
+		{
218 237
 			$active = false;
219 238
 
220
-			do {
239
+			do
240
+			{
221 241
 				$status = curl_multi_exec($multihandle, $active);
222 242
 			}
223 243
 			while ($status === CURLM_CALL_MULTI_PERFORM);
@@ -225,17 +245,21 @@  discard block
 block discarded – undo
225 245
 			$to_process = array();
226 246
 
227 247
 			// Read the information as needed
228
-			while ($done = curl_multi_info_read($multihandle)) {
248
+			while ($done = curl_multi_info_read($multihandle))
249
+			{
229 250
 				$key = array_search($done['handle'], $subhandles, true);
230
-				if (!isset($to_process[$key])) {
251
+				if (!isset($to_process[$key]))
252
+				{
231 253
 					$to_process[$key] = $done;
232 254
 				}
233 255
 			}
234 256
 
235 257
 			// Parse the finished requests before we start getting the new ones
236
-			foreach ($to_process as $key => $done) {
258
+			foreach ($to_process as $key => $done)
259
+			{
237 260
 				$options = $requests[$key]['options'];
238
-				if (CURLE_OK !== $done['result']) {
261
+				if (CURLE_OK !== $done['result'])
262
+				{
239 263
 					//get error string for handle.
240 264
 					$reason = curl_error($done['handle']);
241 265
 					$exception = new Requests_Exception_Transport_cURL(
@@ -247,7 +271,8 @@  discard block
 block discarded – undo
247 271
 					$responses[$key] = $exception;
248 272
 					$options['hooks']->dispatch('transport.internal.parse_error', array(&$responses[$key], $requests[$key]));
249 273
 				}
250
-				else {
274
+				else
275
+				{
251 276
 					$responses[$key] = $subrequests[$key]->process_response($subrequests[$key]->response_data, $options);
252 277
 
253 278
 					$options['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$key], $requests[$key]));
@@ -256,7 +281,8 @@  discard block
 block discarded – undo
256 281
 				curl_multi_remove_handle($multihandle, $done['handle']);
257 282
 				curl_close($done['handle']);
258 283
 
259
-				if (!is_string($responses[$key])) {
284
+				if (!is_string($responses[$key]))
285
+				{
260 286
 					$options['hooks']->dispatch('multiple.request.complete', array(&$responses[$key], $key));
261 287
 				}
262 288
 				$completed++;
@@ -283,14 +309,16 @@  discard block
 block discarded – undo
283 309
 	public function &get_subrequest_handle($url, $headers, $data, $options) {
284 310
 		$this->setup_handle($url, $headers, $data, $options);
285 311
 
286
-		if ($options['filename'] !== false) {
312
+		if ($options['filename'] !== false)
313
+		{
287 314
 			$this->stream_handle = fopen($options['filename'], 'wb');
288 315
 		}
289 316
 
290 317
 		$this->response_data = '';
291 318
 		$this->response_bytes = 0;
292 319
 		$this->response_byte_limit = false;
293
-		if ($options['max_bytes'] !== false) {
320
+		if ($options['max_bytes'] !== false)
321
+		{
294 322
 			$this->response_byte_limit = $options['max_bytes'];
295 323
 		}
296 324
 		$this->hooks = $options['hooks'];
@@ -306,29 +334,35 @@  discard block
 block discarded – undo
306 334
 	 * @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
307 335
 	 * @param array $options Request options, see {@see Requests::response()} for documentation
308 336
 	 */
309
-	protected function setup_handle($url, $headers, $data, $options) {
337
+	protected function setup_handle($url, $headers, $data, $options)
338
+	{
310 339
 		$options['hooks']->dispatch('curl.before_request', array(&$this->handle));
311 340
 
312 341
 		// Force closing the connection for old versions of cURL (<7.22).
313
-		if ( ! isset( $headers['Connection'] ) ) {
342
+		if ( ! isset( $headers['Connection'] ) )
343
+		{
314 344
 			$headers['Connection'] = 'close';
315 345
 		}
316 346
 
317 347
 		$headers = Requests::flatten($headers);
318 348
 
319
-		if (!empty($data)) {
349
+		if (!empty($data))
350
+		{
320 351
 			$data_format = $options['data_format'];
321 352
 
322
-			if ($data_format === 'query') {
353
+			if ($data_format === 'query')
354
+			{
323 355
 				$url = self::format_get($url, $data);
324 356
 				$data = '';
325 357
 			}
326
-			elseif (!is_string($data)) {
358
+			elseif (!is_string($data))
359
+			{
327 360
 				$data = http_build_query($data, null, '&');
328 361
 			}
329 362
 		}
330 363
 
331
-		switch ($options['type']) {
364
+		switch ($options['type'])
365
+		{
332 366
 			case Requests::POST:
333 367
 				curl_setopt($this->handle, CURLOPT_POST, true);
334 368
 				curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
@@ -346,7 +380,8 @@  discard block
 block discarded – undo
346 380
 			case Requests::OPTIONS:
347 381
 			default:
348 382
 				curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, $options['type']);
349
-				if (!empty($data)) {
383
+				if (!empty($data))
384
+				{
350 385
 					curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);
351 386
 				}
352 387
 		}
@@ -359,33 +394,41 @@  discard block
 block discarded – undo
359 394
 		// https://github.com/curl/curl/blob/4f45240bc84a9aa648c8f7243be7b79e9f9323a5/lib/hostip.c#L606-L609
360 395
 		$timeout = max($options['timeout'], 1);
361 396
 
362
-		if (is_int($timeout) || $this->version < self::CURL_7_16_2) {
397
+		if (is_int($timeout) || $this->version < self::CURL_7_16_2)
398
+		{
363 399
 			curl_setopt($this->handle, CURLOPT_TIMEOUT, ceil($timeout));
364 400
 		}
365
-		else {
401
+		else
402
+		{
366 403
 			curl_setopt($this->handle, CURLOPT_TIMEOUT_MS, round($timeout * 1000));
367 404
 		}
368 405
 
369
-		if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2) {
406
+		if (is_int($options['connect_timeout']) || $this->version < self::CURL_7_16_2)
407
+		{
370 408
 			curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
371 409
 		}
372
-		else {
410
+		else
411
+		{
373 412
 			curl_setopt($this->handle, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
374 413
 		}
375 414
 		curl_setopt($this->handle, CURLOPT_URL, $url);
376 415
 		curl_setopt($this->handle, CURLOPT_REFERER, $url);
377 416
 		curl_setopt($this->handle, CURLOPT_USERAGENT, $options['useragent']);
378
-		if (!empty($headers)) {
417
+		if (!empty($headers))
418
+		{
379 419
 			curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
380 420
 		}
381
-		if ($options['protocol_version'] === 1.1) {
421
+		if ($options['protocol_version'] === 1.1)
422
+		{
382 423
 			curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
383 424
 		}
384
-		else {
425
+		else
426
+		{
385 427
 			curl_setopt($this->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
386 428
 		}
387 429
 
388
-		if (true === $options['blocking']) {
430
+		if (true === $options['blocking'])
431
+		{
389 432
 			curl_setopt($this->handle, CURLOPT_HEADERFUNCTION, array(&$this, 'stream_headers'));
390 433
 			curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
391 434
 			curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
@@ -399,21 +442,26 @@  discard block
 block discarded – undo
399 442
 	 * @param array $options Request options
400 443
 	 * @return string HTTP response data including headers
401 444
 	 */
402
-	public function process_response($response, $options) {
403
-		if ($options['blocking'] === false) {
445
+	public function process_response($response, $options)
446
+	{
447
+		if ($options['blocking'] === false)
448
+		{
404 449
 			$fake_headers = '';
405 450
 			$options['hooks']->dispatch('curl.after_request', array(&$fake_headers));
406 451
 			return false;
407 452
 		}
408
-		if ($options['filename'] !== false) {
453
+		if ($options['filename'] !== false)
454
+		{
409 455
 			fclose($this->stream_handle);
410 456
 			$this->headers = trim($this->headers);
411 457
 		}
412
-		else {
458
+		else
459
+		{
413 460
 			$this->headers .= $response;
414 461
 		}
415 462
 
416
-		if (curl_errno($this->handle)) {
463
+		if (curl_errno($this->handle))
464
+		{
417 465
 			$error = sprintf(
418 466
 				'cURL error %s: %s',
419 467
 				curl_errno($this->handle),
@@ -434,17 +482,20 @@  discard block
 block discarded – undo
434 482
 	 * @param string $headers Header string
435 483
 	 * @return integer Length of provided header
436 484
 	 */
437
-	public function stream_headers($handle, $headers) {
485
+	public function stream_headers($handle, $headers)
486
+	{
438 487
 		// Why do we do this? cURL will send both the final response and any
439 488
 		// interim responses, such as a 100 Continue. We don't need that.
440 489
 		// (We may want to keep this somewhere just in case)
441
-		if ($this->done_headers) {
490
+		if ($this->done_headers)
491
+		{
442 492
 			$this->headers = '';
443 493
 			$this->done_headers = false;
444 494
 		}
445 495
 		$this->headers .= $headers;
446 496
 
447
-		if ($headers === "\r\n") {
497
+		if ($headers === "\r\n")
498
+		{
448 499
 			$this->done_headers = true;
449 500
 		}
450 501
 		return strlen($headers);
@@ -459,28 +510,34 @@  discard block
 block discarded – undo
459 510
 	 * @param string $data Body data
460 511
 	 * @return integer Length of provided data
461 512
 	 */
462
-	public function stream_body($handle, $data) {
513
+	public function stream_body($handle, $data)
514
+	{
463 515
 		$this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit));
464 516
 		$data_length = strlen($data);
465 517
 
466 518
 		// Are we limiting the response size?
467
-		if ($this->response_byte_limit) {
468
-			if ($this->response_bytes === $this->response_byte_limit) {
519
+		if ($this->response_byte_limit)
520
+		{
521
+			if ($this->response_bytes === $this->response_byte_limit)
522
+			{
469 523
 				// Already at maximum, move on
470 524
 				return $data_length;
471 525
 			}
472 526
 
473
-			if (($this->response_bytes + $data_length) > $this->response_byte_limit) {
527
+			if (($this->response_bytes + $data_length) > $this->response_byte_limit)
528
+			{
474 529
 				// Limit the length
475 530
 				$limited_length = ($this->response_byte_limit - $this->response_bytes);
476 531
 				$data = substr($data, 0, $limited_length);
477 532
 			}
478 533
 		}
479 534
 
480
-		if ($this->stream_handle) {
535
+		if ($this->stream_handle)
536
+		{
481 537
 			fwrite($this->stream_handle, $data);
482 538
 		}
483
-		else {
539
+		else
540
+		{
484 541
 			$this->response_data .= $data;
485 542
 		}
486 543
 
@@ -495,23 +552,29 @@  discard block
 block discarded – undo
495 552
 	 * @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
496 553
 	 * @return string URL with data
497 554
 	 */
498
-	protected static function format_get($url, $data) {
499
-		if (!empty($data)) {
555
+	protected static function format_get($url, $data)
556
+	{
557
+		if (!empty($data))
558
+		{
500 559
 			$url_parts = parse_url($url);
501
-			if (empty($url_parts['query'])) {
560
+			if (empty($url_parts['query']))
561
+			{
502 562
 				$query = $url_parts['query'] = '';
503 563
 			}
504
-			else {
564
+			else
565
+			{
505 566
 				$query = $url_parts['query'];
506 567
 			}
507 568
 
508 569
 			$query .= '&' . http_build_query($data, null, '&');
509 570
 			$query = trim($query, '&');
510 571
 
511
-			if (empty($url_parts['query'])) {
572
+			if (empty($url_parts['query']))
573
+			{
512 574
 				$url .= '?' . $query;
513 575
 			}
514
-			else {
576
+			else
577
+			{
515 578
 				$url = str_replace($url_parts['query'], $query, $url);
516 579
 			}
517 580
 		}
@@ -524,15 +587,19 @@  discard block
 block discarded – undo
524 587
 	 * @codeCoverageIgnore
525 588
 	 * @return boolean True if the transport is valid, false otherwise.
526 589
 	 */
527
-	public static function test($capabilities = array()) {
528
-		if (!function_exists('curl_init') || !function_exists('curl_exec')) {
590
+	public static function test($capabilities = array())
591
+	{
592
+		if (!function_exists('curl_init') || !function_exists('curl_exec'))
593
+		{
529 594
 			return false;
530 595
 		}
531 596
 
532 597
 		// If needed, check that our installed curl version supports SSL
533
-		if (isset($capabilities['ssl']) && $capabilities['ssl']) {
598
+		if (isset($capabilities['ssl']) && $capabilities['ssl'])
599
+		{
534 600
 			$curl_version = curl_version();
535
-			if (!(CURL_VERSION_SSL & $curl_version['features'])) {
601
+			if (!(CURL_VERSION_SSL & $curl_version['features']))
602
+			{
536 603
 				return false;
537 604
 			}
538 605
 		}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Transport/fsockopen.php 1 patch
Braces   +142 added lines, -71 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
  * @package Requests
13 13
  * @subpackage Transport
14 14
  */
15
-class Requests_Transport_fsockopen implements Requests_Transport {
15
+class Requests_Transport_fsockopen implements Requests_Transport
16
+{
16 17
 	/**
17 18
 	 * Second to microsecond conversion
18 19
 	 *
@@ -55,11 +56,13 @@  discard block
 block discarded – undo
55 56
 	 * @param array $options Request options, see {@see Requests::response()} for documentation
56 57
 	 * @return string Raw HTTP result
57 58
 	 */
58
-	public function request($url, $headers = array(), $data = array(), $options = array()) {
59
+	public function request($url, $headers = array(), $data = array(), $options = array())
60
+	{
59 61
 		$options['hooks']->dispatch('fsockopen.before_request');
60 62
 
61 63
 		$url_parts = parse_url($url);
62
-		if (empty($url_parts)) {
64
+		if (empty($url_parts))
65
+		{
63 66
 			throw new Requests_Exception('Invalid URL.', 'invalidurl', $url);
64 67
 		}
65 68
 		$host = $url_parts['host'];
@@ -68,9 +71,11 @@  discard block
 block discarded – undo
68 71
 		$case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers);
69 72
 
70 73
 		// HTTPS support
71
-		if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
74
+		if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
75
+		{
72 76
 			$remote_socket = 'ssl://' . $host;
73
-			if (!isset($url_parts['port'])) {
77
+			if (!isset($url_parts['port']))
78
+			{
74 79
 				$url_parts['port'] = 443;
75 80
 			}
76 81
 
@@ -82,36 +87,44 @@  discard block
 block discarded – undo
82 87
 			$verifyname = true;
83 88
 
84 89
 			// SNI, if enabled (OpenSSL >=0.9.8j)
85
-			if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) {
90
+			if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME)
91
+			{
86 92
 				$context_options['SNI_enabled'] = true;
87
-				if (isset($options['verifyname']) && $options['verifyname'] === false) {
93
+				if (isset($options['verifyname']) && $options['verifyname'] === false)
94
+				{
88 95
 					$context_options['SNI_enabled'] = false;
89 96
 				}
90 97
 			}
91 98
 
92
-			if (isset($options['verify'])) {
93
-				if ($options['verify'] === false) {
99
+			if (isset($options['verify']))
100
+			{
101
+				if ($options['verify'] === false)
102
+				{
94 103
 					$context_options['verify_peer'] = false;
95 104
 				}
96
-				elseif (is_string($options['verify'])) {
105
+				elseif (is_string($options['verify']))
106
+				{
97 107
 					$context_options['cafile'] = $options['verify'];
98 108
 				}
99 109
 			}
100 110
 
101
-			if (isset($options['verifyname']) && $options['verifyname'] === false) {
111
+			if (isset($options['verifyname']) && $options['verifyname'] === false)
112
+			{
102 113
 				$context_options['verify_peer_name'] = false;
103 114
 				$verifyname = false;
104 115
 			}
105 116
 
106 117
 			stream_context_set_option($context, array('ssl' => $context_options));
107 118
 		}
108
-		else {
119
+		else
120
+		{
109 121
 			$remote_socket = 'tcp://' . $host;
110 122
 		}
111 123
 
112 124
 		$this->max_bytes = $options['max_bytes'];
113 125
 
114
-		if (!isset($url_parts['port'])) {
126
+		if (!isset($url_parts['port']))
127
+		{
115 128
 			$url_parts['port'] = 80;
116 129
 		}
117 130
 		$remote_socket .= ':' . $url_parts['port'];
@@ -124,12 +137,15 @@  discard block
 block discarded – undo
124 137
 
125 138
 		restore_error_handler();
126 139
 
127
-		if ($verifyname && !$this->verify_certificate_from_context($host, $context)) {
140
+		if ($verifyname && !$this->verify_certificate_from_context($host, $context))
141
+		{
128 142
 			throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match');
129 143
 		}
130 144
 
131
-		if (!$socket) {
132
-			if ($errno === 0) {
145
+		if (!$socket)
146
+		{
147
+			if ($errno === 0)
148
+			{
133 149
 				// Connection issue
134 150
 				throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error');
135 151
 			}
@@ -139,11 +155,13 @@  discard block
 block discarded – undo
139 155
 
140 156
 		$data_format = $options['data_format'];
141 157
 
142
-		if ($data_format === 'query') {
158
+		if ($data_format === 'query')
159
+		{
143 160
 			$path = self::format_get($url_parts, $data);
144 161
 			$data = '';
145 162
 		}
146
-		else {
163
+		else
164
+		{
147 165
 			$path = self::format_get($url_parts, array());
148 166
 		}
149 167
 
@@ -152,56 +170,69 @@  discard block
 block discarded – undo
152 170
 		$request_body = '';
153 171
 		$out = sprintf("%s %s HTTP/%.1f\r\n", $options['type'], $path, $options['protocol_version']);
154 172
 
155
-		if ($options['type'] !== Requests::TRACE) {
156
-			if (is_array($data)) {
173
+		if ($options['type'] !== Requests::TRACE)
174
+		{
175
+			if (is_array($data))
176
+			{
157 177
 				$request_body = http_build_query($data, null, '&');
158 178
 			}
159
-			else {
179
+			else
180
+			{
160 181
 				$request_body = $data;
161 182
 			}
162 183
 
163
-			if (!empty($data)) {
164
-				if (!isset($case_insensitive_headers['Content-Length'])) {
184
+			if (!empty($data))
185
+			{
186
+				if (!isset($case_insensitive_headers['Content-Length']))
187
+				{
165 188
 					$headers['Content-Length'] = strlen($request_body);
166 189
 				}
167 190
 
168
-				if (!isset($case_insensitive_headers['Content-Type'])) {
191
+				if (!isset($case_insensitive_headers['Content-Type']))
192
+				{
169 193
 					$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
170 194
 				}
171 195
 			}
172 196
 		}
173 197
 
174
-		if (!isset($case_insensitive_headers['Host'])) {
198
+		if (!isset($case_insensitive_headers['Host']))
199
+		{
175 200
 			$out .= sprintf('Host: %s', $url_parts['host']);
176 201
 
177
-			if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 )) {
202
+			if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443 ))
203
+			{
178 204
 				$out .= ':' . $url_parts['port'];
179 205
 			}
180 206
 			$out .= "\r\n";
181 207
 		}
182 208
 
183
-		if (!isset($case_insensitive_headers['User-Agent'])) {
209
+		if (!isset($case_insensitive_headers['User-Agent']))
210
+		{
184 211
 			$out .= sprintf("User-Agent: %s\r\n", $options['useragent']);
185 212
 		}
186 213
 
187 214
 		$accept_encoding = $this->accept_encoding();
188
-		if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) {
215
+		if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding))
216
+		{
189 217
 			$out .= sprintf("Accept-Encoding: %s\r\n", $accept_encoding);
190 218
 		}
191 219
 
192 220
 		$headers = Requests::flatten($headers);
193 221
 
194
-		if (!empty($headers)) {
222
+		if (!empty($headers))
223
+		{
195 224
 			$out .= implode($headers, "\r\n") . "\r\n";
196 225
 		}
197 226
 
198 227
 		$options['hooks']->dispatch('fsockopen.after_headers', array(&$out));
199 228
 
200
-		if (substr($out, -2) !== "\r\n") {
229
+		if (substr($out, -2) !== "\r\n")
230
+		{
201 231
 			$out .= "\r\n";
202 232
 		}
203 233
 
204
-		if (!isset($case_insensitive_headers['Connection'])) {
234
+		if (!isset($case_insensitive_headers['Connection']))
235
+		{
205 236
 			$out .= "Connection: Close\r\n";
206 237
 		}
207 238
 
@@ -212,7 +243,8 @@  discard block
 block discarded – undo
212 243
 		fwrite($socket, $out);
213 244
 		$options['hooks']->dispatch('fsockopen.after_send', array($out));
214 245
 
215
-		if (!$options['blocking']) {
246
+		if (!$options['blocking'])
247
+		{
216 248
 			fclose($socket);
217 249
 			$fake_headers = '';
218 250
 			$options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers));
@@ -220,10 +252,12 @@  discard block
 block discarded – undo
220 252
 		}
221 253
 
222 254
 		$timeout_sec = (int) floor($options['timeout']);
223
-		if ($timeout_sec == $options['timeout']) {
255
+		if ($timeout_sec == $options['timeout'])
256
+		{
224 257
 			$timeout_msec = 0;
225 258
 		}
226
-		else {
259
+		else
260
+		{
227 261
 			$timeout_msec = self::SECOND_IN_MICROSECONDS * $options['timeout'] % self::SECOND_IN_MICROSECONDS;
228 262
 		}
229 263
 		stream_set_timeout($socket, $timeout_sec, $timeout_msec);
@@ -233,35 +267,44 @@  discard block
 block discarded – undo
233 267
 		$size = 0;
234 268
 		$doingbody = false;
235 269
 		$download = false;
236
-		if ($options['filename']) {
270
+		if ($options['filename'])
271
+		{
237 272
 			$download = fopen($options['filename'], 'wb');
238 273
 		}
239 274
 
240
-		while (!feof($socket)) {
275
+		while (!feof($socket))
276
+		{
241 277
 			$this->info = stream_get_meta_data($socket);
242
-			if ($this->info['timed_out']) {
278
+			if ($this->info['timed_out'])
279
+			{
243 280
 				throw new Requests_Exception('fsocket timed out', 'timeout');
244 281
 			}
245 282
 
246 283
 			$block = fread($socket, Requests::BUFFER_SIZE);
247
-			if (!$doingbody) {
284
+			if (!$doingbody)
285
+			{
248 286
 				$response .= $block;
249
-				if (strpos($response, "\r\n\r\n")) {
287
+				if (strpos($response, "\r\n\r\n"))
288
+				{
250 289
 					list($headers, $block) = explode("\r\n\r\n", $response, 2);
251 290
 					$doingbody = true;
252 291
 				}
253 292
 			}
254 293
 
255 294
 			// Are we in body mode now?
256
-			if ($doingbody) {
295
+			if ($doingbody)
296
+			{
257 297
 				$options['hooks']->dispatch('request.progress', array($block, $size, $this->max_bytes));
258 298
 				$data_length = strlen($block);
259
-				if ($this->max_bytes) {
299
+				if ($this->max_bytes)
300
+				{
260 301
 					// Have we already hit a limit?
261
-					if ($size === $this->max_bytes) {
302
+					if ($size === $this->max_bytes)
303
+					{
262 304
 						continue;
263 305
 					}
264
-					if (($size + $data_length) > $this->max_bytes) {
306
+					if (($size + $data_length) > $this->max_bytes)
307
+					{
265 308
 						// Limit the length
266 309
 						$limited_length = ($this->max_bytes - $size);
267 310
 						$block = substr($block, 0, $limited_length);
@@ -269,20 +312,24 @@  discard block
 block discarded – undo
269 312
 				}
270 313
 
271 314
 				$size += strlen($block);
272
-				if ($download) {
315
+				if ($download)
316
+				{
273 317
 					fwrite($download, $block);
274 318
 				}
275
-				else {
319
+				else
320
+				{
276 321
 					$body .= $block;
277 322
 				}
278 323
 			}
279 324
 		}
280 325
 		$this->headers = $headers;
281 326
 
282
-		if ($download) {
327
+		if ($download)
328
+		{
283 329
 			fclose($download);
284 330
 		}
285
-		else {
331
+		else
332
+		{
286 333
 			$this->headers .= "\r\n\r\n" . $body;
287 334
 		}
288 335
 		fclose($socket);
@@ -298,21 +345,26 @@  discard block
 block discarded – undo
298 345
 	 * @param array $options Global options, see {@see Requests::response()} for documentation
299 346
 	 * @return array Array of Requests_Response objects (may contain Requests_Exception or string responses as well)
300 347
 	 */
301
-	public function request_multiple($requests, $options) {
348
+	public function request_multiple($requests, $options)
349
+	{
302 350
 		$responses = array();
303 351
 		$class = get_class($this);
304
-		foreach ($requests as $id => $request) {
305
-			try {
352
+		foreach ($requests as $id => $request)
353
+		{
354
+			try
355
+			{
306 356
 				$handler = new $class();
307 357
 				$responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']);
308 358
 
309 359
 				$request['options']['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$id], $request));
310 360
 			}
311
-			catch (Requests_Exception $e) {
361
+			catch (Requests_Exception $e)
362
+			{
312 363
 				$responses[$id] = $e;
313 364
 			}
314 365
 
315
-			if (!is_string($responses[$id])) {
366
+			if (!is_string($responses[$id]))
367
+			{
316 368
 				$request['options']['hooks']->dispatch('multiple.request.complete', array(&$responses[$id], $id));
317 369
 			}
318 370
 		}
@@ -325,13 +377,16 @@  discard block
 block discarded – undo
325 377
 	 *
326 378
 	 * @return string Accept-Encoding header value
327 379
 	 */
328
-	protected static function accept_encoding() {
380
+	protected static function accept_encoding()
381
+	{
329 382
 		$type = array();
330
-		if (function_exists('gzinflate')) {
383
+		if (function_exists('gzinflate'))
384
+		{
331 385
 			$type[] = 'deflate;q=1.0';
332 386
 		}
333 387
 
334
-		if (function_exists('gzuncompress')) {
388
+		if (function_exists('gzuncompress'))
389
+		{
335 390
 			$type[] = 'compress;q=0.5';
336 391
 		}
337 392
 
@@ -347,24 +402,31 @@  discard block
 block discarded – undo
347 402
 	 * @param array|object $data Data to build query using, see {@see https://secure.php.net/http_build_query}
348 403
 	 * @return string URL with data
349 404
 	 */
350
-	protected static function format_get($url_parts, $data) {
351
-		if (!empty($data)) {
352
-			if (empty($url_parts['query'])) {
405
+	protected static function format_get($url_parts, $data)
406
+	{
407
+		if (!empty($data))
408
+		{
409
+			if (empty($url_parts['query']))
410
+			{
353 411
 				$url_parts['query'] = '';
354 412
 			}
355 413
 
356 414
 			$url_parts['query'] .= '&' . http_build_query($data, null, '&');
357 415
 			$url_parts['query'] = trim($url_parts['query'], '&');
358 416
 		}
359
-		if (isset($url_parts['path'])) {
360
-			if (isset($url_parts['query'])) {
417
+		if (isset($url_parts['path']))
418
+		{
419
+			if (isset($url_parts['query']))
420
+			{
361 421
 				$get = $url_parts['path'] . '?' . $url_parts['query'];
362 422
 			}
363
-			else {
423
+			else
424
+			{
364 425
 				$get = $url_parts['path'];
365 426
 			}
366 427
 		}
367
-		else {
428
+		else
429
+		{
368 430
 			$get = '/';
369 431
 		}
370 432
 		return $get;
@@ -376,9 +438,11 @@  discard block
 block discarded – undo
376 438
 	 * @param int $errno Error number (e.g. E_WARNING)
377 439
 	 * @param string $errstr Error message
378 440
 	 */
379
-	public function connect_error_handler($errno, $errstr) {
441
+	public function connect_error_handler($errno, $errstr)
442
+	{
380 443
 		// Double-check we can handle it
381
-		if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) {
444
+		if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0)
445
+		{
382 446
 			// Return false to indicate the default error handler should engage
383 447
 			return false;
384 448
 		}
@@ -402,12 +466,14 @@  discard block
 block discarded – undo
402 466
 	 * @param resource $context Stream context
403 467
 	 * @return bool
404 468
 	 */
405
-	public function verify_certificate_from_context($host, $context) {
469
+	public function verify_certificate_from_context($host, $context)
470
+	{
406 471
 		$meta = stream_context_get_options($context);
407 472
 
408 473
 		// If we don't have SSL options, then we couldn't make the connection at
409 474
 		// all
410
-		if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) {
475
+		if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate']))
476
+		{
411 477
 			throw new Requests_Exception(rtrim($this->connect_error), 'ssl.connect_error');
412 478
 		}
413 479
 
@@ -422,19 +488,24 @@  discard block
 block discarded – undo
422 488
 	 * @codeCoverageIgnore
423 489
 	 * @return boolean True if the transport is valid, false otherwise.
424 490
 	 */
425
-	public static function test($capabilities = array()) {
426
-		if (!function_exists('fsockopen')) {
491
+	public static function test($capabilities = array())
492
+	{
493
+		if (!function_exists('fsockopen'))
494
+		{
427 495
 			return false;
428 496
 		}
429 497
 
430 498
 		// If needed, check that streams support SSL
431
-		if (isset($capabilities['ssl']) && $capabilities['ssl']) {
432
-			if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) {
499
+		if (isset($capabilities['ssl']) && $capabilities['ssl'])
500
+		{
501
+			if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse'))
502
+			{
433 503
 				return false;
434 504
 			}
435 505
 
436 506
 			// Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156
437
-			if (defined('HHVM_VERSION')) {
507
+			if (defined('HHVM_VERSION'))
508
+			{
438 509
 				return false;
439 510
 			}
440 511
 		}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Session.php 1 patch
Braces   +50 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
  * @package Requests
18 18
  * @subpackage Session Handler
19 19
  */
20
-class Requests_Session {
20
+class Requests_Session
21
+{
21 22
 	/**
22 23
 	 * Base URL for requests
23 24
 	 *
@@ -63,13 +64,15 @@  discard block
 block discarded – undo
63 64
 	 * @param array $data Default data for requests
64 65
 	 * @param array $options Default options for requests
65 66
 	 */
66
-	public function __construct($url = null, $headers = array(), $data = array(), $options = array()) {
67
+	public function __construct($url = null, $headers = array(), $data = array(), $options = array())
68
+	{
67 69
 		$this->url = $url;
68 70
 		$this->headers = $headers;
69 71
 		$this->data = $data;
70 72
 		$this->options = $options;
71 73
 
72
-		if (empty($this->options['cookies'])) {
74
+		if (empty($this->options['cookies']))
75
+		{
73 76
 			$this->options['cookies'] = new Requests_Cookie_Jar();
74 77
 		}
75 78
 	}
@@ -80,8 +83,10 @@  discard block
 block discarded – undo
80 83
 	 * @param string $key Property key
81 84
 	 * @return mixed|null Property value, null if none found
82 85
 	 */
83
-	public function __get($key) {
84
-		if (isset($this->options[$key])) {
86
+	public function __get($key)
87
+	{
88
+		if (isset($this->options[$key]))
89
+		{
85 90
 			return $this->options[$key];
86 91
 		}
87 92
 
@@ -94,7 +99,8 @@  discard block
 block discarded – undo
94 99
 	 * @param string $key Property key
95 100
 	 * @param mixed $value Property value
96 101
 	 */
97
-	public function __set($key, $value) {
102
+	public function __set($key, $value)
103
+	{
98 104
 		$this->options[$key] = $value;
99 105
 	}
100 106
 
@@ -103,7 +109,8 @@  discard block
 block discarded – undo
103 109
 	 *
104 110
 	 * @param string $key Property key
105 111
 	 */
106
-	public function __isset($key) {
112
+	public function __isset($key)
113
+	{
107 114
 		return isset($this->options[$key]);
108 115
 	}
109 116
 
@@ -112,8 +119,10 @@  discard block
 block discarded – undo
112 119
 	 *
113 120
 	 * @param string $key Property key
114 121
 	 */
115
-	public function __unset($key) {
116
-		if (isset($this->options[$key])) {
122
+	public function __unset($key)
123
+	{
124
+		if (isset($this->options[$key]))
125
+		{
117 126
 			unset($this->options[$key]);
118 127
 		}
119 128
 	}
@@ -128,21 +137,24 @@  discard block
 block discarded – undo
128 137
 	/**
129 138
 	 * Send a GET request
130 139
 	 */
131
-	public function get($url, $headers = array(), $options = array()) {
140
+	public function get($url, $headers = array(), $options = array())
141
+	{
132 142
 		return $this->request($url, $headers, null, Requests::GET, $options);
133 143
 	}
134 144
 
135 145
 	/**
136 146
 	 * Send a HEAD request
137 147
 	 */
138
-	public function head($url, $headers = array(), $options = array()) {
148
+	public function head($url, $headers = array(), $options = array())
149
+	{
139 150
 		return $this->request($url, $headers, null, Requests::HEAD, $options);
140 151
 	}
141 152
 
142 153
 	/**
143 154
 	 * Send a DELETE request
144 155
 	 */
145
-	public function delete($url, $headers = array(), $options = array()) {
156
+	public function delete($url, $headers = array(), $options = array())
157
+	{
146 158
 		return $this->request($url, $headers, null, Requests::DELETE, $options);
147 159
 	}
148 160
 	/**#@-*/
@@ -158,14 +170,16 @@  discard block
 block discarded – undo
158 170
 	/**
159 171
 	 * Send a POST request
160 172
 	 */
161
-	public function post($url, $headers = array(), $data = array(), $options = array()) {
173
+	public function post($url, $headers = array(), $data = array(), $options = array())
174
+	{
162 175
 		return $this->request($url, $headers, $data, Requests::POST, $options);
163 176
 	}
164 177
 
165 178
 	/**
166 179
 	 * Send a PUT request
167 180
 	 */
168
-	public function put($url, $headers = array(), $data = array(), $options = array()) {
181
+	public function put($url, $headers = array(), $data = array(), $options = array())
182
+	{
169 183
 		return $this->request($url, $headers, $data, Requests::PUT, $options);
170 184
 	}
171 185
 
@@ -177,7 +191,8 @@  discard block
 block discarded – undo
177 191
 	 *
178 192
 	 * @link https://tools.ietf.org/html/rfc5789
179 193
 	 */
180
-	public function patch($url, $headers, $data = array(), $options = array()) {
194
+	public function patch($url, $headers, $data = array(), $options = array())
195
+	{
181 196
 		return $this->request($url, $headers, $data, Requests::PATCH, $options);
182 197
 	}
183 198
 	/**#@-*/
@@ -199,7 +214,8 @@  discard block
 block discarded – undo
199 214
 	 * @param array $options Options for the request (see {@see Requests::request})
200 215
 	 * @return Requests_Response
201 216
 	 */
202
-	public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array()) {
217
+	public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array())
218
+	{
203 219
 		$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
204 220
 
205 221
 		return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
@@ -214,8 +230,10 @@  discard block
 block discarded – undo
214 230
 	 * @param array $options Global and default options (see {@see Requests::request})
215 231
 	 * @return array Responses (either Requests_Response or a Requests_Exception object)
216 232
 	 */
217
-	public function request_multiple($requests, $options = array()) {
218
-		foreach ($requests as $key => $request) {
233
+	public function request_multiple($requests, $options = array())
234
+	{
235
+		foreach ($requests as $key => $request)
236
+		{
219 237
 			$requests[$key] = $this->merge_request($request, false);
220 238
 		}
221 239
 
@@ -234,27 +252,34 @@  discard block
 block discarded – undo
234 252
 	 * @param boolean $merge_options Should we merge options as well?
235 253
 	 * @return array Request data
236 254
 	 */
237
-	protected function merge_request($request, $merge_options = true) {
238
-		if ($this->url !== null) {
255
+	protected function merge_request($request, $merge_options = true)
256
+	{
257
+		if ($this->url !== null)
258
+		{
239 259
 			$request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
240 260
 			$request['url'] = $request['url']->uri;
241 261
 		}
242 262
 
243
-		if (empty($request['headers'])) {
263
+		if (empty($request['headers']))
264
+		{
244 265
 			$request['headers'] = array();
245 266
 		}
246 267
 		$request['headers'] = array_merge($this->headers, $request['headers']);
247 268
 
248
-		if (empty($request['data'])) {
249
-			if (is_array($this->data)) {
269
+		if (empty($request['data']))
270
+		{
271
+			if (is_array($this->data))
272
+			{
250 273
 				$request['data'] = $this->data;
251 274
 			}
252 275
 		}
253
-		elseif (is_array($request['data']) && is_array($this->data)) {
276
+		elseif (is_array($request['data']) && is_array($this->data))
277
+		{
254 278
 			$request['data'] = array_merge($this->data, $request['data']);
255 279
 		}
256 280
 
257
-		if ($merge_options !== false) {
281
+		if ($merge_options !== false)
282
+		{
258 283
 			$request['options'] = array_merge($this->options, $request['options']);
259 284
 
260 285
 			// Disallow forcing the type, as that's a per request setting
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Transport.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
  * @package Requests
13 13
  * @subpackage Transport
14 14
  */
15
-interface Requests_Transport {
15
+interface Requests_Transport
16
+{
16 17
 	/**
17 18
 	 * Perform a request
18 19
 	 *
Please login to merge, or discard this patch.