Completed
Push — master ( 24e24a...fca7db )
by mains
02:44
created
php/Requests/libary/Requests/Exception/HTTP/305.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,8 @@
 block discarded – undo
10 10
  *
11 11
  * @package Requests
12 12
  */
13
-class Requests_Exception_HTTP_305 extends Requests_Exception_HTTP {
13
+class Requests_Exception_HTTP_305 extends Requests_Exception_HTTP
14
+{
14 15
 	/**
15 16
 	 * HTTP status code
16 17
 	 *
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Hooks.php 1 patch
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
  * @package Requests
13 13
  * @subpackage Utilities
14 14
  */
15
-class Requests_Hooks implements Requests_Hooker {
15
+class Requests_Hooks implements Requests_Hooker
16
+{
16 17
 	/**
17 18
 	 * Registered callbacks for each hook
18 19
 	 *
@@ -23,7 +24,8 @@  discard block
 block discarded – undo
23 24
 	/**
24 25
 	 * Constructor
25 26
 	 */
26
-	public function __construct() {
27
+	public function __construct()
28
+	{
27 29
 		// pass
28 30
 	}
29 31
 
@@ -34,11 +36,14 @@  discard block
 block discarded – undo
34 36
 	 * @param callback $callback Function/method to call on event
35 37
 	 * @param int $priority Priority number. <0 is executed earlier, >0 is executed later
36 38
 	 */
37
-	public function register($hook, $callback, $priority = 0) {
38
-		if (!isset($this->hooks[$hook])) {
39
+	public function register($hook, $callback, $priority = 0)
40
+	{
41
+		if (!isset($this->hooks[$hook]))
42
+		{
39 43
 			$this->hooks[$hook] = array();
40 44
 		}
41
-		if (!isset($this->hooks[$hook][$priority])) {
45
+		if (!isset($this->hooks[$hook][$priority]))
46
+		{
42 47
 			$this->hooks[$hook][$priority] = array();
43 48
 		}
44 49
 
@@ -52,13 +57,17 @@  discard block
 block discarded – undo
52 57
 	 * @param array $parameters Parameters to pass to callbacks
53 58
 	 * @return boolean Successfulness
54 59
 	 */
55
-	public function dispatch($hook, $parameters = array()) {
56
-		if (empty($this->hooks[$hook])) {
60
+	public function dispatch($hook, $parameters = array())
61
+	{
62
+		if (empty($this->hooks[$hook]))
63
+		{
57 64
 			return false;
58 65
 		}
59 66
 
60
-		foreach ($this->hooks[$hook] as $priority => $hooked) {
61
-			foreach ($hooked as $callback) {
67
+		foreach ($this->hooks[$hook] as $priority => $hooked)
68
+		{
69
+			foreach ($hooked as $callback)
70
+			{
62 71
 				call_user_func_array($callback, $parameters);
63 72
 			}
64 73
 		}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/SSL.php 1 patch
Braces   +40 added lines, -20 removed lines patch added patch discarded remove patch
@@ -14,7 +14,8 @@  discard block
 block discarded – undo
14 14
  * @package Requests
15 15
  * @subpackage Utilities
16 16
  */
17
-class Requests_SSL {
17
+class Requests_SSL
18
+{
18 19
 	/**
19 20
 	 * Verify the certificate against common name and subject alternative names
20 21
 	 *
@@ -29,10 +30,12 @@  discard block
 block discarded – undo
29 30
 	 * @param array $cert Certificate data from openssl_x509_parse()
30 31
 	 * @return bool
31 32
 	 */
32
-	public static function verify_certificate($host, $cert) {
33
+	public static function verify_certificate($host, $cert)
34
+	{
33 35
 		// Calculate the valid wildcard match if the host is not an IP address
34 36
 		$parts = explode('.', $host);
35
-		if (ip2long($host) === false) {
37
+		if (ip2long($host) === false)
38
+		{
36 39
 			$parts[0] = '*';
37 40
 		}
38 41
 		$wildcard = implode('.', $parts);
@@ -40,11 +43,14 @@  discard block
 block discarded – undo
40 43
 		$has_dns_alt = false;
41 44
 
42 45
 		// Check the subjectAltName
43
-		if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName'])) {
46
+		if (!empty($cert['extensions']) && !empty($cert['extensions']['subjectAltName']))
47
+		{
44 48
 			$altnames = explode(',', $cert['extensions']['subjectAltName']);
45
-			foreach ($altnames as $altname) {
49
+			foreach ($altnames as $altname)
50
+			{
46 51
 				$altname = trim($altname);
47
-				if (strpos($altname, 'DNS:') !== 0) {
52
+				if (strpos($altname, 'DNS:') !== 0)
53
+				{
48 54
 					continue;
49 55
 				}
50 56
 
@@ -54,7 +60,8 @@  discard block
 block discarded – undo
54 60
 				$altname = trim(substr($altname, 4));
55 61
 
56 62
 				// Check for a match
57
-				if (self::match_domain($host, $altname) === true) {
63
+				if (self::match_domain($host, $altname) === true)
64
+				{
58 65
 					return true;
59 66
 				}
60 67
 			}
@@ -62,9 +69,11 @@  discard block
 block discarded – undo
62 69
 
63 70
 		// Fall back to checking the common name if we didn't get any dNSName
64 71
 		// alt names, as per RFC2818
65
-		if (!$has_dns_alt && !empty($cert['subject']['CN'])) {
72
+		if (!$has_dns_alt && !empty($cert['subject']['CN']))
73
+		{
66 74
 			// Check for a match
67
-			if (self::match_domain($host, $cert['subject']['CN']) === true) {
75
+			if (self::match_domain($host, $cert['subject']['CN']) === true)
76
+			{
68 77
 				return true;
69 78
 			}
70 79
 		}
@@ -88,27 +97,33 @@  discard block
 block discarded – undo
88 97
 	 * @param string $reference Reference dNSName
89 98
 	 * @return boolean Is the name valid?
90 99
 	 */
91
-	public static function verify_reference_name($reference) {
100
+	public static function verify_reference_name($reference)
101
+	{
92 102
 		$parts = explode('.', $reference);
93 103
 
94 104
 		// Check the first part of the name
95 105
 		$first = array_shift($parts);
96 106
 
97
-		if (strpos($first, '*') !== false) {
107
+		if (strpos($first, '*') !== false)
108
+		{
98 109
 			// Check that the wildcard is the full part
99
-			if ($first !== '*') {
110
+			if ($first !== '*')
111
+			{
100 112
 				return false;
101 113
 			}
102 114
 
103 115
 			// Check that we have at least 3 components (including first)
104
-			if (count($parts) < 2) {
116
+			if (count($parts) < 2)
117
+			{
105 118
 				return false;
106 119
 			}
107 120
 		}
108 121
 
109 122
 		// Check the remaining parts
110
-		foreach ($parts as $part) {
111
-			if (strpos($part, '*') !== false) {
123
+		foreach ($parts as $part)
124
+		{
125
+			if (strpos($part, '*') !== false)
126
+			{
112 127
 				return false;
113 128
 			}
114 129
 		}
@@ -124,25 +139,30 @@  discard block
 block discarded – undo
124 139
 	 * @param string $reference dNSName to match against
125 140
 	 * @return boolean Does the domain match?
126 141
 	 */
127
-	public static function match_domain($host, $reference) {
142
+	public static function match_domain($host, $reference)
143
+	{
128 144
 		// Check if the reference is blacklisted first
129
-		if (self::verify_reference_name($reference) !== true) {
145
+		if (self::verify_reference_name($reference) !== true)
146
+		{
130 147
 			return false;
131 148
 		}
132 149
 
133 150
 		// Check for a direct match
134
-		if ($host === $reference) {
151
+		if ($host === $reference)
152
+		{
135 153
 			return true;
136 154
 		}
137 155
 
138 156
 		// Calculate the valid wildcard match if the host is not an IP address
139 157
 		// Also validates that the host has 3 parts or more, as per Firefox's
140 158
 		// ruleset.
141
-		if (ip2long($host) === false) {
159
+		if (ip2long($host) === false)
160
+		{
142 161
 			$parts = explode('.', $host);
143 162
 			$parts[0] = '*';
144 163
 			$wildcard = implode('.', $parts);
145
-			if ($wildcard === $reference) {
164
+			if ($wildcard === $reference)
165
+			{
146 166
 				return true;
147 167
 			}
148 168
 		}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/IPv6.php 1 patch
Braces   +56 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,7 +15,8 @@  discard block
 block discarded – undo
15 15
  * @package Requests
16 16
  * @subpackage Utilities
17 17
  */
18
-class Requests_IPv6 {
18
+class Requests_IPv6
19
+{
19 20
 	/**
20 21
 	 * Uncompresses an IPv6 address
21 22
 	 *
@@ -34,8 +35,10 @@  discard block
 block discarded – undo
34 35
 	 * @param string $ip An IPv6 address
35 36
 	 * @return string The uncompressed IPv6 address
36 37
 	 */
37
-	public static function uncompress($ip) {
38
-		if (substr_count($ip, '::') !== 1) {
38
+	public static function uncompress($ip)
39
+	{
40
+		if (substr_count($ip, '::') !== 1)
41
+		{
39 42
 			return $ip;
40 43
 		}
41 44
 
@@ -43,25 +46,30 @@  discard block
 block discarded – undo
43 46
 		$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
44 47
 		$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
45 48
 
46
-		if (strpos($ip2, '.') !== false) {
49
+		if (strpos($ip2, '.') !== false)
50
+		{
47 51
 			$c2++;
48 52
 		}
49 53
 		// ::
50
-		if ($c1 === -1 && $c2 === -1) {
54
+		if ($c1 === -1 && $c2 === -1)
55
+		{
51 56
 			$ip = '0:0:0:0:0:0:0:0';
52 57
 		}
53 58
 		// ::xxx
54
-		else if ($c1 === -1) {
59
+		else if ($c1 === -1)
60
+		{
55 61
 			$fill = str_repeat('0:', 7 - $c2);
56 62
 			$ip = str_replace('::', $fill, $ip);
57 63
 		}
58 64
 		// xxx::
59
-		else if ($c2 === -1) {
65
+		else if ($c2 === -1)
66
+		{
60 67
 			$fill = str_repeat(':0', 7 - $c1);
61 68
 			$ip = str_replace('::', $fill, $ip);
62 69
 		}
63 70
 		// xxx::xxx
64
-		else {
71
+		else
72
+		{
65 73
 			$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
66 74
 			$ip = str_replace('::', $fill, $ip);
67 75
 		}
@@ -82,7 +90,8 @@  discard block
 block discarded – undo
82 90
 	 * @param string $ip An IPv6 address
83 91
 	 * @return string The compressed IPv6 address
84 92
 	 */
85
-	public static function compress($ip) {
93
+	public static function compress($ip)
94
+	{
86 95
 		// Prepare the IP to be compressed
87 96
 		$ip = self::uncompress($ip);
88 97
 		$ip_parts = self::split_v6_v4($ip);
@@ -91,11 +100,14 @@  discard block
 block discarded – undo
91 100
 		$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
92 101
 
93 102
 		// Find bunches of zeros
94
-		if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
103
+		if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
104
+		{
95 105
 			$max = 0;
96 106
 			$pos = null;
97
-			foreach ($matches[0] as $match) {
98
-				if (strlen($match[0]) > $max) {
107
+			foreach ($matches[0] as $match)
108
+			{
109
+				if (strlen($match[0]) > $max)
110
+				{
99 111
 					$max = strlen($match[0]);
100 112
 					$pos = $match[1];
101 113
 				}
@@ -104,10 +116,12 @@  discard block
 block discarded – undo
104 116
 			$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
105 117
 		}
106 118
 
107
-		if ($ip_parts[1] !== '') {
119
+		if ($ip_parts[1] !== '')
120
+		{
108 121
 			return implode(':', $ip_parts);
109 122
 		}
110
-		else {
123
+		else
124
+		{
111 125
 			return $ip_parts[0];
112 126
 		}
113 127
 	}
@@ -124,14 +138,17 @@  discard block
 block discarded – undo
124 138
 	 * @param string $ip An IPv6 address
125 139
 	 * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
126 140
 	 */
127
-	protected static function split_v6_v4($ip) {
128
-		if (strpos($ip, '.') !== false) {
141
+	protected static function split_v6_v4($ip)
142
+	{
143
+		if (strpos($ip, '.') !== false)
144
+		{
129 145
 			$pos = strrpos($ip, ':');
130 146
 			$ipv6_part = substr($ip, 0, $pos);
131 147
 			$ipv4_part = substr($ip, $pos + 1);
132 148
 			return array($ipv6_part, $ipv4_part);
133 149
 		}
134
-		else {
150
+		else
151
+		{
135 152
 			return array($ip, '');
136 153
 		}
137 154
 	}
@@ -144,46 +161,57 @@  discard block
 block discarded – undo
144 161
 	 * @param string $ip An IPv6 address
145 162
 	 * @return bool true if $ip is a valid IPv6 address
146 163
 	 */
147
-	public static function check_ipv6($ip) {
164
+	public static function check_ipv6($ip)
165
+	{
148 166
 		$ip = self::uncompress($ip);
149 167
 		list($ipv6, $ipv4) = self::split_v6_v4($ip);
150 168
 		$ipv6 = explode(':', $ipv6);
151 169
 		$ipv4 = explode('.', $ipv4);
152
-		if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
153
-			foreach ($ipv6 as $ipv6_part) {
170
+		if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
171
+		{
172
+			foreach ($ipv6 as $ipv6_part)
173
+			{
154 174
 				// The section can't be empty
155
-				if ($ipv6_part === '') {
175
+				if ($ipv6_part === '')
176
+				{
156 177
 					return false;
157 178
 				}
158 179
 
159 180
 				// Nor can it be over four characters
160
-				if (strlen($ipv6_part) > 4) {
181
+				if (strlen($ipv6_part) > 4)
182
+				{
161 183
 					return false;
162 184
 				}
163 185
 
164 186
 				// Remove leading zeros (this is safe because of the above)
165 187
 				$ipv6_part = ltrim($ipv6_part, '0');
166
-				if ($ipv6_part === '') {
188
+				if ($ipv6_part === '')
189
+				{
167 190
 					$ipv6_part = '0';
168 191
 				}
169 192
 
170 193
 				// Check the value is valid
171 194
 				$value = hexdec($ipv6_part);
172
-				if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) {
195
+				if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
196
+				{
173 197
 					return false;
174 198
 				}
175 199
 			}
176
-			if (count($ipv4) === 4) {
177
-				foreach ($ipv4 as $ipv4_part) {
200
+			if (count($ipv4) === 4)
201
+			{
202
+				foreach ($ipv4 as $ipv4_part)
203
+				{
178 204
 					$value = (int) $ipv4_part;
179
-					if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) {
205
+					if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
206
+					{
180 207
 						return false;
181 208
 					}
182 209
 				}
183 210
 			}
184 211
 			return true;
185 212
 		}
186
-		else {
213
+		else
214
+		{
187 215
 			return false;
188 216
 		}
189 217
 	}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Response/Headers.php 1 patch
Braces   +22 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,7 +10,8 @@  discard block
 block discarded – undo
10 10
  *
11 11
  * @package Requests
12 12
  */
13
-class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary {
13
+class Requests_Response_Headers extends Requests_Utility_CaseInsensitiveDictionary
14
+{
14 15
 	/**
15 16
 	 * Get the given header
16 17
 	 *
@@ -23,9 +24,11 @@  discard block
 block discarded – undo
23 24
 	 * @param string $key
24 25
 	 * @return string Header value
25 26
 	 */
26
-	public function offsetGet($key) {
27
+	public function offsetGet($key)
28
+	{
27 29
 		$key = strtolower($key);
28
-		if (!isset($this->data[$key])) {
30
+		if (!isset($this->data[$key]))
31
+		{
29 32
 			return null;
30 33
 		}
31 34
 
@@ -40,14 +43,17 @@  discard block
 block discarded – undo
40 43
 	 * @param string $key Item name
41 44
 	 * @param string $value Item value
42 45
 	 */
43
-	public function offsetSet($key, $value) {
44
-		if ($key === null) {
46
+	public function offsetSet($key, $value)
47
+	{
48
+		if ($key === null)
49
+		{
45 50
 			throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset');
46 51
 		}
47 52
 
48 53
 		$key = strtolower($key);
49 54
 
50
-		if (!isset($this->data[$key])) {
55
+		if (!isset($this->data[$key]))
56
+		{
51 57
 			$this->data[$key] = array();
52 58
 		}
53 59
 
@@ -60,9 +66,11 @@  discard block
 block discarded – undo
60 66
 	 * @param string $key
61 67
 	 * @return array Header values
62 68
 	 */
63
-	public function getValues($key) {
69
+	public function getValues($key)
70
+	{
64 71
 		$key = strtolower($key);
65
-		if (!isset($this->data[$key])) {
72
+		if (!isset($this->data[$key]))
73
+		{
66 74
 			return null;
67 75
 		}
68 76
 
@@ -78,8 +86,10 @@  discard block
 block discarded – undo
78 86
 	 * @param string|array $value Value to flatten
79 87
 	 * @return string Flattened value
80 88
 	 */
81
-	public function flatten($value) {
82
-		if (is_array($value)) {
89
+	public function flatten($value)
90
+	{
91
+		if (is_array($value))
92
+		{
83 93
 			$value = implode(',', $value);
84 94
 		}
85 95
 
@@ -92,7 +102,8 @@  discard block
 block discarded – undo
92 102
 	 * Converts the internal
93 103
 	 * @return ArrayIterator
94 104
 	 */
95
-	public function getIterator() {
105
+	public function getIterator()
106
+	{
96 107
 		return new Requests_Utility_FilteredIterator($this->data, array($this, 'flatten'));
97 108
 	}
98 109
 }
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Response.php 1 patch
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,11 +12,13 @@  discard block
 block discarded – undo
12 12
  * Contains a response from Requests::request()
13 13
  * @package Requests
14 14
  */
15
-class Requests_Response {
15
+class Requests_Response
16
+{
16 17
 	/**
17 18
 	 * Constructor
18 19
 	 */
19
-	public function __construct() {
20
+	public function __construct()
21
+	{
20 22
 		$this->headers = new Requests_Response_Headers();
21 23
 		$this->cookies = new Requests_Cookie_Jar();
22 24
 	}
@@ -95,7 +97,8 @@  discard block
 block discarded – undo
95 97
 	 *
96 98
 	 * @return boolean True if redirect (3xx status), false if not.
97 99
 	 */
98
-	public function is_redirect() {
100
+	public function is_redirect()
101
+	{
99 102
 		$code = $this->status_code;
100 103
 		return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400;
101 104
 	}
@@ -107,13 +110,17 @@  discard block
 block discarded – undo
107 110
 	 * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404})
108 111
 	 * @param boolean $allow_redirects Set to false to throw on a 3xx as well
109 112
 	 */
110
-	public function throw_for_status($allow_redirects = true) {
111
-		if ($this->is_redirect()) {
112
-			if (!$allow_redirects) {
113
+	public function throw_for_status($allow_redirects = true)
114
+	{
115
+		if ($this->is_redirect())
116
+		{
117
+			if (!$allow_redirects)
118
+			{
113 119
 				throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
114 120
 			}
115 121
 		}
116
-		elseif (!$this->success) {
122
+		elseif (!$this->success)
123
+		{
117 124
 			$exception = Requests_Exception_HTTP::get_class($this->status_code);
118 125
 			throw new $exception(null, $this);
119 126
 		}
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Proxy.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,8 @@
 block discarded – undo
20 20
  * @subpackage Proxy
21 21
  * @since 1.6
22 22
  */
23
-interface Requests_Proxy {
23
+interface Requests_Proxy
24
+{
24 25
 	/**
25 26
 	 * Register hooks as needed
26 27
 	 *
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Exception.php 1 patch
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,7 +10,8 @@  discard block
 block discarded – undo
10 10
  *
11 11
  * @package Requests
12 12
  */
13
-class Requests_Exception extends Exception {
13
+class Requests_Exception extends Exception
14
+{
14 15
 	/**
15 16
 	 * Type of exception
16 17
 	 *
@@ -33,7 +34,8 @@  discard block
 block discarded – undo
33 34
 	 * @param mixed $data Associated data
34 35
 	 * @param integer $code Exception numerical code, if applicable
35 36
 	 */
36
-	public function __construct($message, $type, $data = null, $code = 0) {
37
+	public function __construct($message, $type, $data = null, $code = 0)
38
+	{
37 39
 		parent::__construct($message, $code);
38 40
 
39 41
 		$this->type = $type;
@@ -46,7 +48,8 @@  discard block
 block discarded – undo
46 48
 	 * @codeCoverageIgnore
47 49
 	 * @return string
48 50
 	 */
49
-	public function getType() {
51
+	public function getType()
52
+	{
50 53
 		return $this->type;
51 54
 	}
52 55
 
@@ -56,7 +59,8 @@  discard block
 block discarded – undo
56 59
 	 * @codeCoverageIgnore
57 60
 	 * @return mixed
58 61
 	 */
59
-	public function getData() {
62
+	public function getData()
63
+	{
60 64
 		return $this->data;
61 65
 	}
62 66
 }
63 67
\ No newline at end of file
Please login to merge, or discard this patch.
php/Requests/libary/Requests/IDNAEncoder.php 1 patch
Braces   +88 added lines, -44 removed lines patch added patch discarded remove patch
@@ -10,7 +10,8 @@  discard block
 block discarded – undo
10 10
  * @see https://tools.ietf.org/html/rfc3490 IDNA specification
11 11
  * @see https://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
12 12
  */
13
-class Requests_IDNAEncoder {
13
+class Requests_IDNAEncoder
14
+{
14 15
 	/**
15 16
 	 * ACE prefix used for IDNA
16 17
 	 *
@@ -40,9 +41,11 @@  discard block
 block discarded – undo
40 41
 	 * @param string $string Hostname
41 42
 	 * @return string Punycode-encoded hostname
42 43
 	 */
43
-	public static function encode($string) {
44
+	public static function encode($string)
45
+	{
44 46
 		$parts = explode('.', $string);
45
-		foreach ($parts as &$part) {
47
+		foreach ($parts as &$part)
48
+		{
46 49
 			$part = self::to_ascii($part);
47 50
 		}
48 51
 		return implode('.', $parts);
@@ -59,11 +62,14 @@  discard block
 block discarded – undo
59 62
 	 * @param string $string ASCII or UTF-8 string (max length 64 characters)
60 63
 	 * @return string ASCII string
61 64
 	 */
62
-	public static function to_ascii($string) {
65
+	public static function to_ascii($string)
66
+	{
63 67
 		// Step 1: Check if the string is already ASCII
64
-		if (self::is_ascii($string)) {
68
+		if (self::is_ascii($string))
69
+		{
65 70
 			// Skip to step 7
66
-			if (strlen($string) < 64) {
71
+			if (strlen($string) < 64)
72
+			{
67 73
 				return $string;
68 74
 			}
69 75
 
@@ -75,9 +81,11 @@  discard block
 block discarded – undo
75 81
 
76 82
 		// Step 3: UseSTD3ASCIIRules is false, continue
77 83
 		// Step 4: Check if it's ASCII now
78
-		if (self::is_ascii($string)) {
84
+		if (self::is_ascii($string))
85
+		{
79 86
 			// Skip to step 7
80
-			if (strlen($string) < 64) {
87
+			if (strlen($string) < 64)
88
+			{
81 89
 				return $string;
82 90
 			}
83 91
 
@@ -85,7 +93,8 @@  discard block
 block discarded – undo
85 93
 		}
86 94
 
87 95
 		// Step 5: Check ACE prefix
88
-		if (strpos($string, self::ACE_PREFIX) === 0) {
96
+		if (strpos($string, self::ACE_PREFIX) === 0)
97
+		{
89 98
 			throw new Requests_Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $string);
90 99
 		}
91 100
 
@@ -96,7 +105,8 @@  discard block
 block discarded – undo
96 105
 		$string = self::ACE_PREFIX . $string;
97 106
 
98 107
 		// Step 8: Check size
99
-		if (strlen($string) < 64) {
108
+		if (strlen($string) < 64)
109
+		{
100 110
 			return $string;
101 111
 		}
102 112
 
@@ -111,7 +121,8 @@  discard block
 block discarded – undo
111 121
 	 * @param string $string
112 122
 	 * @return bool Is the string ASCII-only?
113 123
 	 */
114
-	protected static function is_ascii($string) {
124
+	protected static function is_ascii($string)
125
+	{
115 126
 		return (preg_match('/(?:[^\x00-\x7F])/', $string) !== 1);
116 127
 	}
117 128
 
@@ -122,7 +133,8 @@  discard block
 block discarded – undo
122 133
 	 * @param string $string
123 134
 	 * @return string Prepared string
124 135
 	 */
125
-	protected static function nameprep($string) {
136
+	protected static function nameprep($string)
137
+	{
126 138
 		return $string;
127 139
 	}
128 140
 
@@ -135,53 +147,64 @@  discard block
 block discarded – undo
135 147
 	 * @param string $input
136 148
 	 * @return array Unicode code points
137 149
 	 */
138
-	protected static function utf8_to_codepoints($input) {
150
+	protected static function utf8_to_codepoints($input)
151
+	{
139 152
 		$codepoints = array();
140 153
 
141 154
 		// Get number of bytes
142 155
 		$strlen = strlen($input);
143 156
 
144
-		for ($position = 0; $position < $strlen; $position++) {
157
+		for ($position = 0; $position < $strlen; $position++)
158
+		{
145 159
 			$value = ord($input[$position]);
146 160
 
147 161
 			// One byte sequence:
148
-			if ((~$value & 0x80) === 0x80) {
162
+			if ((~$value & 0x80) === 0x80)
163
+			{
149 164
 				$character = $value;
150 165
 				$length = 1;
151 166
 				$remaining = 0;
152 167
 			}
153 168
 			// Two byte sequence:
154
-			elseif (($value & 0xE0) === 0xC0) {
169
+			elseif (($value & 0xE0) === 0xC0)
170
+			{
155 171
 				$character = ($value & 0x1F) << 6;
156 172
 				$length = 2;
157 173
 				$remaining = 1;
158 174
 			}
159 175
 			// Three byte sequence:
160
-			elseif (($value & 0xF0) === 0xE0) {
176
+			elseif (($value & 0xF0) === 0xE0)
177
+			{
161 178
 				$character = ($value & 0x0F) << 12;
162 179
 				$length = 3;
163 180
 				$remaining = 2;
164 181
 			}
165 182
 			// Four byte sequence:
166
-			elseif (($value & 0xF8) === 0xF0) {
183
+			elseif (($value & 0xF8) === 0xF0)
184
+			{
167 185
 				$character = ($value & 0x07) << 18;
168 186
 				$length = 4;
169 187
 				$remaining = 3;
170 188
 			}
171 189
 			// Invalid byte:
172
-			else {
190
+			else
191
+			{
173 192
 				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
174 193
 			}
175 194
 
176
-			if ($remaining > 0) {
177
-				if ($position + $length > $strlen) {
195
+			if ($remaining > 0)
196
+			{
197
+				if ($position + $length > $strlen)
198
+				{
178 199
 					throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
179 200
 				}
180
-				for ($position++; $remaining > 0; $position++) {
201
+				for ($position++; $remaining > 0; $position++)
202
+				{
181 203
 					$value = ord($input[$position]);
182 204
 
183 205
 					// If it is invalid, count the sequence as invalid and reprocess the current byte:
184
-					if (($value & 0xC0) !== 0x80) {
206
+					if (($value & 0xC0) !== 0x80)
207
+					{
185 208
 						throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
186 209
 					}
187 210
 
@@ -225,7 +248,8 @@  discard block
 block discarded – undo
225 248
 	 * @param string $input UTF-8 encoded string to encode
226 249
 	 * @return string Punycode-encoded string
227 250
 	 */
228
-	public static function punycode_encode($input) {
251
+	public static function punycode_encode($input)
252
+	{
229 253
 		$output = '';
230 254
 #		let n = initial_n
231 255
 		$n = self::BOOTSTRAP_INITIAL_N;
@@ -239,8 +263,10 @@  discard block
 block discarded – undo
239 263
 		$codepoints = self::utf8_to_codepoints($input);
240 264
 		$extended = array();
241 265
 
242
-		foreach ($codepoints as $char) {
243
-			if ($char < 128) {
266
+		foreach ($codepoints as $char)
267
+		{
268
+			if ($char < 128)
269
+			{
244 270
 				// Character is valid ASCII
245 271
 				// TODO: this should also check if it's valid for a URL
246 272
 				$output .= chr($char);
@@ -249,11 +275,13 @@  discard block
 block discarded – undo
249 275
 			// Check if the character is non-ASCII, but below initial n
250 276
 			// This never occurs for Punycode, so ignore in coverage
251 277
 			// @codeCoverageIgnoreStart
252
-			elseif ($char < $n) {
278
+			elseif ($char < $n)
279
+			{
253 280
 				throw new Requests_Exception('Invalid character', 'idna.character_outside_domain', $char);
254 281
 			}
255 282
 			// @codeCoverageIgnoreEnd
256
-			else {
283
+			else
284
+			{
257 285
 				$extended[$char] = true;
258 286
 			}
259 287
 		}
@@ -261,12 +289,14 @@  discard block
 block discarded – undo
261 289
 		sort($extended);
262 290
 		$b = $h;
263 291
 #		[copy them] followed by a delimiter if b > 0
264
-		if (strlen($output) > 0) {
292
+		if (strlen($output) > 0)
293
+		{
265 294
 			$output .= '-';
266 295
 		}
267 296
 #		{if the input contains a non-basic code point < n then fail}
268 297
 #		while h < length(input) do begin
269
-		while ($h < count($codepoints)) {
298
+		while ($h < count($codepoints))
299
+		{
270 300
 #			let m = the minimum code point >= n in the input
271 301
 			$m = array_shift($extended);
272 302
 			//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
@@ -275,31 +305,39 @@  discard block
 block discarded – undo
275 305
 #			let n = m
276 306
 			$n = $m;
277 307
 #			for each code point c in the input (in order) do begin
278
-			for ($num = 0; $num < count($codepoints); $num++) {
308
+			for ($num = 0; $num < count($codepoints); $num++)
309
+			{
279 310
 				$c = $codepoints[$num];
280 311
 #				if c < n then increment delta, fail on overflow
281
-				if ($c < $n) {
312
+				if ($c < $n)
313
+				{
282 314
 					$delta++;
283 315
 				}
284 316
 #				if c == n then begin
285
-				elseif ($c === $n) {
317
+				elseif ($c === $n)
318
+				{
286 319
 #					let q = delta
287 320
 					$q = $delta;
288 321
 #					for k = base to infinity in steps of base do begin
289
-					for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
322
+					for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE)
323
+					{
290 324
 #						let t = tmin if k <= bias {+ tmin}, or
291 325
 #								tmax if k >= bias + tmax, or k - bias otherwise
292
-						if ($k <= ($bias + self::BOOTSTRAP_TMIN)) {
326
+						if ($k <= ($bias + self::BOOTSTRAP_TMIN))
327
+						{
293 328
 							$t = self::BOOTSTRAP_TMIN;
294 329
 						}
295
-						elseif ($k >= ($bias + self::BOOTSTRAP_TMAX)) {
330
+						elseif ($k >= ($bias + self::BOOTSTRAP_TMAX))
331
+						{
296 332
 							$t = self::BOOTSTRAP_TMAX;
297 333
 						}
298
-						else {
334
+						else
335
+						{
299 336
 							$t = $k - $bias;
300 337
 						}
301 338
 #						if q < t then break
302
-						if ($q < $t) {
339
+						if ($q < $t)
340
+						{
303 341
 							break;
304 342
 						}
305 343
 #						output the code point for digit t + ((q - t) mod (base - t))
@@ -339,10 +377,12 @@  discard block
 block discarded – undo
339 377
 	 * @param int $digit Digit in the range 0-35
340 378
 	 * @return string Single character corresponding to digit
341 379
 	 */
342
-	protected static function digit_to_char($digit) {
380
+	protected static function digit_to_char($digit)
381
+	{
343 382
 		// @codeCoverageIgnoreStart
344 383
 		// As far as I know, this never happens, but still good to be sure.
345
-		if ($digit < 0 || $digit > 35) {
384
+		if ($digit < 0 || $digit > 35)
385
+		{
346 386
 			throw new Requests_Exception(sprintf('Invalid digit %d', $digit), 'idna.invalid_digit', $digit);
347 387
 		}
348 388
 		// @codeCoverageIgnoreEnd
@@ -359,14 +399,17 @@  discard block
 block discarded – undo
359 399
 	 * @param bool $firsttime
360 400
 	 * @return int New bias
361 401
 	 */
362
-	protected static function adapt($delta, $numpoints, $firsttime) {
402
+	protected static function adapt($delta, $numpoints, $firsttime)
403
+	{
363 404
 #	function adapt(delta,numpoints,firsttime):
364 405
 #		if firsttime then let delta = delta div damp
365
-		if ($firsttime) {
406
+		if ($firsttime)
407
+		{
366 408
 			$delta = floor($delta / self::BOOTSTRAP_DAMP);
367 409
 		}
368 410
 #		else let delta = delta div 2
369
-		else {
411
+		else
412
+		{
370 413
 			$delta = floor($delta / 2);
371 414
 		}
372 415
 #		let delta = delta + (delta div numpoints)
@@ -375,7 +418,8 @@  discard block
 block discarded – undo
375 418
 		$k = 0;
376 419
 #		while delta > ((base - tmin) * tmax) div 2 do begin
377 420
 		$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
378
-		while ($delta > $max) {
421
+		while ($delta > $max)
422
+		{
379 423
 #			let delta = delta div (base - tmin)
380 424
 			$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
381 425
 #			let k = k + base
Please login to merge, or discard this patch.