Completed
Push — master ( c16962...925f8b )
by mains
03:47 queued 25s
created
php/Requests/libary/Requests.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -226,6 +226,7 @@  discard block
 block discarded – undo
226 226
 	 */
227 227
 	/**
228 228
 	 * Send a GET request
229
+	 * @param string $url
229 230
 	 */
230 231
 	public static function get($url, $headers = array(), $options = array()) {
231 232
 		return self::request($url, $headers, null, self::GET, $options);
@@ -263,12 +264,14 @@  discard block
 block discarded – undo
263 264
 	 */
264 265
 	/**
265 266
 	 * Send a POST request
267
+	 * @param string $url
266 268
 	 */
267 269
 	public static function post($url, $headers = array(), $data = array(), $options = array()) {
268 270
 		return self::request($url, $headers, $data, self::POST, $options);
269 271
 	}
270 272
 	/**
271 273
 	 * Send a PUT request
274
+	 * @param string $url
272 275
 	 */
273 276
 	public static function put($url, $headers = array(), $data = array(), $options = array()) {
274 277
 		return self::request($url, $headers, $data, self::PUT, $options);
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public static function autoloader($class) {
139 139
 		// Check that the class starts with "Requests"
140
-		if (strpos($class, 'Requests') !== 0) {
140
+		if(strpos($class, 'Requests') !== 0) {
141 141
 			return;
142 142
 		}
143 143
 
144 144
 		$file = str_replace('_', '/', $class);
145
-		if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
145
+		if(file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
146 146
 			require_once(dirname(__FILE__) . '/' . $file . '.php');
147 147
 		}
148 148
 	}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param string $transport Transport class to add, must support the Requests_Transport interface
163 163
 	 */
164 164
 	public static function add_transport($transport) {
165
-		if (empty(self::$transports)) {
165
+		if(empty(self::$transports)) {
166 166
 			self::$transports = array(
167 167
 				'Requests_Transport_cURL',
168 168
 				'Requests_Transport_fsockopen',
@@ -186,12 +186,12 @@  discard block
 block discarded – undo
186 186
 		$cap_string = serialize($capabilities);
187 187
 
188 188
 		// Don't search for a transport if it's already been done for these $capabilities
189
-		if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
189
+		if(isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
190 190
 			return new self::$transport[$cap_string]();
191 191
 		}
192 192
 		// @codeCoverageIgnoreEnd
193 193
 
194
-		if (empty(self::$transports)) {
194
+		if(empty(self::$transports)) {
195 195
 			self::$transports = array(
196 196
 				'Requests_Transport_cURL',
197 197
 				'Requests_Transport_fsockopen',
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
 		}
200 200
 
201 201
 		// Find us a working transport
202
-		foreach (self::$transports as $class) {
203
-			if (!class_exists($class)) {
202
+		foreach(self::$transports as $class) {
203
+			if(!class_exists($class)) {
204 204
 				continue;
205 205
 			}
206 206
 
207 207
 			$result = call_user_func(array($class, 'test'), $capabilities);
208
-			if ($result) {
208
+			if($result) {
209 209
 				self::$transport[$cap_string] = $class;
210 210
 				break;
211 211
 			}
212 212
 		}
213
-		if (self::$transport[$cap_string] === null) {
213
+		if(self::$transport[$cap_string] === null) {
214 214
 			throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
215 215
 		}
216 216
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @return Requests_Response
356 356
 	 */
357 357
 	public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) {
358
-		if (empty($options['type'])) {
358
+		if(empty($options['type'])) {
359 359
 			$options['type'] = $type;
360 360
 		}
361 361
 		$options = array_merge(self::get_default_options(), $options);
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
 
365 365
 		$options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options));
366 366
 
367
-		if (!empty($options['transport'])) {
367
+		if(!empty($options['transport'])) {
368 368
 			$transport = $options['transport'];
369 369
 
370
-			if (is_string($options['transport'])) {
370
+			if(is_string($options['transport'])) {
371 371
 				$transport = new $transport();
372 372
 			}
373 373
 		}
@@ -427,29 +427,29 @@  discard block
 block discarded – undo
427 427
 	public static function request_multiple($requests, $options = array()) {
428 428
 		$options = array_merge(self::get_default_options(true), $options);
429 429
 
430
-		if (!empty($options['hooks'])) {
430
+		if(!empty($options['hooks'])) {
431 431
 			$options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple'));
432
-			if (!empty($options['complete'])) {
432
+			if(!empty($options['complete'])) {
433 433
 				$options['hooks']->register('multiple.request.complete', $options['complete']);
434 434
 			}
435 435
 		}
436 436
 
437
-		foreach ($requests as $id => &$request) {
438
-			if (!isset($request['headers'])) {
437
+		foreach($requests as $id => &$request) {
438
+			if(!isset($request['headers'])) {
439 439
 				$request['headers'] = array();
440 440
 			}
441
-			if (!isset($request['data'])) {
441
+			if(!isset($request['data'])) {
442 442
 				$request['data'] = array();
443 443
 			}
444
-			if (!isset($request['type'])) {
444
+			if(!isset($request['type'])) {
445 445
 				$request['type'] = self::GET;
446 446
 			}
447
-			if (!isset($request['options'])) {
447
+			if(!isset($request['options'])) {
448 448
 				$request['options'] = $options;
449 449
 				$request['options']['type'] = $request['type'];
450 450
 			}
451 451
 			else {
452
-				if (empty($request['options']['type'])) {
452
+				if(empty($request['options']['type'])) {
453 453
 					$request['options']['type'] = $request['type'];
454 454
 				}
455 455
 				$request['options'] = array_merge($options, $request['options']);
@@ -458,19 +458,19 @@  discard block
 block discarded – undo
458 458
 			self::set_defaults($request['url'], $request['headers'], $request['data'], $request['type'], $request['options']);
459 459
 
460 460
 			// Ensure we only hook in once
461
-			if ($request['options']['hooks'] !== $options['hooks']) {
461
+			if($request['options']['hooks'] !== $options['hooks']) {
462 462
 				$request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple'));
463
-				if (!empty($request['options']['complete'])) {
463
+				if(!empty($request['options']['complete'])) {
464 464
 					$request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']);
465 465
 				}
466 466
 			}
467 467
 		}
468 468
 		unset($request);
469 469
 
470
-		if (!empty($options['transport'])) {
470
+		if(!empty($options['transport'])) {
471 471
 			$transport = $options['transport'];
472 472
 
473
-			if (is_string($options['transport'])) {
473
+			if(is_string($options['transport'])) {
474 474
 				$transport = new $transport();
475 475
 			}
476 476
 		}
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
 		}
480 480
 		$responses = $transport->request_multiple($requests, $options);
481 481
 
482
-		foreach ($responses as $id => &$response) {
482
+		foreach($responses as $id => &$response) {
483 483
 			// If our hook got messed with somehow, ensure we end up with the
484 484
 			// correct response
485
-			if (is_string($response)) {
485
+			if(is_string($response)) {
486 486
 				$request = $requests[$id];
487 487
 				self::parse_multiple($response, $request);
488 488
 				$request['options']['hooks']->dispatch('multiple.request.complete', array(&$response, $id));
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 			'verify' => Requests::get_certificate_path(),
522 522
 			'verifyname' => true,
523 523
 		);
524
-		if ($multirequest !== false) {
524
+		if($multirequest !== false) {
525 525
 			$defaults['complete'] = null;
526 526
 		}
527 527
 		return $defaults;
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 	 * @return string Default certificate path.
534 534
 	 */
535 535
 	public static function get_certificate_path() {
536
-		if ( ! empty( Requests::$certificate_path ) ) {
536
+		if(!empty(Requests::$certificate_path)) {
537 537
 			return Requests::$certificate_path;
538 538
 		}
539 539
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 	 *
546 546
 	 * @param string $path Certificate path, pointing to a PEM file.
547 547
 	 */
548
-	public static function set_certificate_path( $path ) {
548
+	public static function set_certificate_path($path) {
549 549
 		Requests::$certificate_path = $path;
550 550
 	}
551 551
 
@@ -560,39 +560,39 @@  discard block
 block discarded – undo
560 560
 	 * @return array $options
561 561
 	 */
562 562
 	protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
563
-		if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
563
+		if(!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
564 564
 			throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
565 565
 		}
566 566
 
567
-		if (empty($options['hooks'])) {
567
+		if(empty($options['hooks'])) {
568 568
 			$options['hooks'] = new Requests_Hooks();
569 569
 		}
570 570
 
571
-		if (is_array($options['auth'])) {
571
+		if(is_array($options['auth'])) {
572 572
 			$options['auth'] = new Requests_Auth_Basic($options['auth']);
573 573
 		}
574
-		if ($options['auth'] !== false) {
574
+		if($options['auth'] !== false) {
575 575
 			$options['auth']->register($options['hooks']);
576 576
 		}
577 577
 
578
-		if (is_string($options['proxy']) || is_array($options['proxy'])) {
578
+		if(is_string($options['proxy']) || is_array($options['proxy'])) {
579 579
 			$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
580 580
 		}
581
-		if ($options['proxy'] !== false) {
581
+		if($options['proxy'] !== false) {
582 582
 			$options['proxy']->register($options['hooks']);
583 583
 		}
584 584
 
585
-		if (is_array($options['cookies'])) {
585
+		if(is_array($options['cookies'])) {
586 586
 			$options['cookies'] = new Requests_Cookie_Jar($options['cookies']);
587 587
 		}
588
-		elseif (empty($options['cookies'])) {
588
+		elseif(empty($options['cookies'])) {
589 589
 			$options['cookies'] = new Requests_Cookie_Jar();
590 590
 		}
591
-		if ($options['cookies'] !== false) {
591
+		if($options['cookies'] !== false) {
592 592
 			$options['cookies']->register($options['hooks']);
593 593
 		}
594 594
 
595
-		if ($options['idn'] !== false) {
595
+		if($options['idn'] !== false) {
596 596
 			$iri = new Requests_IRI($url);
597 597
 			$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
598 598
 			$url = $iri->uri;
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
 		// Massage the type to ensure we support it.
602 602
 		$type = strtoupper($type);
603 603
 
604
-		if (!isset($options['data_format'])) {
605
-			if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) {
604
+		if(!isset($options['data_format'])) {
605
+			if(in_array($type, array(self::HEAD, self::GET, self::DELETE))) {
606 606
 				$options['data_format'] = 'query';
607 607
 			}
608 608
 			else {
@@ -627,15 +627,15 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	protected static function parse_response($headers, $url, $req_headers, $req_data, $options) {
629 629
 		$return = new Requests_Response();
630
-		if (!$options['blocking']) {
630
+		if(!$options['blocking']) {
631 631
 			return $return;
632 632
 		}
633 633
 
634 634
 		$return->raw = $headers;
635 635
 		$return->url = $url;
636 636
 
637
-		if (!$options['filename']) {
638
-			if (($pos = strpos($headers, "\r\n\r\n")) === false) {
637
+		if(!$options['filename']) {
638
+			if(($pos = strpos($headers, "\r\n\r\n")) === false) {
639 639
 				// Crap!
640 640
 				throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator');
641 641
 			}
@@ -652,44 +652,44 @@  discard block
 block discarded – undo
652 652
 		$headers = preg_replace('/\n[ \t]/', ' ', $headers);
653 653
 		$headers = explode("\n", $headers);
654 654
 		preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches);
655
-		if (empty($matches)) {
655
+		if(empty($matches)) {
656 656
 			throw new Requests_Exception('Response could not be parsed', 'noversion', $headers);
657 657
 		}
658
-		$return->protocol_version = (float) $matches[1];
659
-		$return->status_code = (int) $matches[2];
660
-		if ($return->status_code >= 200 && $return->status_code < 300) {
658
+		$return->protocol_version = (float)$matches[1];
659
+		$return->status_code = (int)$matches[2];
660
+		if($return->status_code >= 200 && $return->status_code < 300) {
661 661
 			$return->success = true;
662 662
 		}
663 663
 
664
-		foreach ($headers as $header) {
664
+		foreach($headers as $header) {
665 665
 			list($key, $value) = explode(':', $header, 2);
666 666
 			$value = trim($value);
667 667
 			preg_replace('#(\s+)#i', ' ', $value);
668 668
 			$return->headers[$key] = $value;
669 669
 		}
670
-		if (isset($return->headers['transfer-encoding'])) {
670
+		if(isset($return->headers['transfer-encoding'])) {
671 671
 			$return->body = self::decode_chunked($return->body);
672 672
 			unset($return->headers['transfer-encoding']);
673 673
 		}
674
-		if (isset($return->headers['content-encoding'])) {
674
+		if(isset($return->headers['content-encoding'])) {
675 675
 			$return->body = self::decompress($return->body);
676 676
 		}
677 677
 
678 678
 		//fsockopen and cURL compatibility
679
-		if (isset($return->headers['connection'])) {
679
+		if(isset($return->headers['connection'])) {
680 680
 			unset($return->headers['connection']);
681 681
 		}
682 682
 
683 683
 		$options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options));
684 684
 
685
-		if ($return->is_redirect() && $options['follow_redirects'] === true) {
686
-			if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
687
-				if ($return->status_code === 303) {
685
+		if($return->is_redirect() && $options['follow_redirects'] === true) {
686
+			if(isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
687
+				if($return->status_code === 303) {
688 688
 					$options['type'] = self::GET;
689 689
 				}
690 690
 				$options['redirected']++;
691 691
 				$location = $return->headers['location'];
692
-				if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
692
+				if(strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
693 693
 					// relative redirect, for compatibility make it absolute
694 694
 					$location = Requests_IRI::absolutize($url, $location);
695 695
 					$location = $location->uri;
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 				$redirected->history[] = $return;
708 708
 				return $redirected;
709 709
 			}
710
-			elseif ($options['redirected'] >= $options['redirects']) {
710
+			elseif($options['redirected'] >= $options['redirects']) {
711 711
 				throw new Requests_Exception('Too many redirects', 'toomanyredirects', $return);
712 712
 			}
713 713
 		}
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
 			$options = $request['options'];
737 737
 			$response = self::parse_response($response, $url, $headers, $data, $options);
738 738
 		}
739
-		catch (Requests_Exception $e) {
739
+		catch(Requests_Exception $e) {
740 740
 			$response = $e;
741 741
 		}
742 742
 	}
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	 * @return string Decoded body
750 750
 	 */
751 751
 	protected static function decode_chunked($data) {
752
-		if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
752
+		if(!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
753 753
 			return $data;
754 754
 		}
755 755
 
@@ -758,15 +758,15 @@  discard block
 block discarded – undo
758 758
 		$decoded = '';
759 759
 		$encoded = $data;
760 760
 
761
-		while (true) {
762
-			$is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
763
-			if (!$is_chunked) {
761
+		while(true) {
762
+			$is_chunked = (bool)preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
763
+			if(!$is_chunked) {
764 764
 				// Looks like it's not chunked after all
765 765
 				return $data;
766 766
 			}
767 767
 
768 768
 			$length = hexdec(trim($matches[1]));
769
-			if ($length === 0) {
769
+			if($length === 0) {
770 770
 				// Ignore trailer headers
771 771
 				return $decoded;
772 772
 			}
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 			$decoded .= substr($encoded, $chunk_length, $length);
776 776
 			$encoded = substr($encoded, $chunk_length + $length + 2);
777 777
 
778
-			if (trim($encoded) === '0' || empty($encoded)) {
778
+			if(trim($encoded) === '0' || empty($encoded)) {
779 779
 				return $decoded;
780 780
 			}
781 781
 		}
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 	 */
794 794
 	public static function flatten($array) {
795 795
 		$return = array();
796
-		foreach ($array as $key => $value) {
796
+		foreach($array as $key => $value) {
797 797
 			$return[] = sprintf('%s: %s', $key, $value);
798 798
 		}
799 799
 		return $return;
@@ -821,21 +821,21 @@  discard block
 block discarded – undo
821 821
 	 * @return string Decompressed string
822 822
 	 */
823 823
 	public static function decompress($data) {
824
-		if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") {
824
+		if(substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") {
825 825
 			// Not actually compressed. Probably cURL ruining this for us.
826 826
 			return $data;
827 827
 		}
828 828
 
829
-		if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) {
829
+		if(function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) {
830 830
 			return $decoded;
831 831
 		}
832
-		elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) {
832
+		elseif(function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) {
833 833
 			return $decoded;
834 834
 		}
835
-		elseif (($decoded = self::compatible_gzinflate($data)) !== false) {
835
+		elseif(($decoded = self::compatible_gzinflate($data)) !== false) {
836 836
 			return $decoded;
837 837
 		}
838
-		elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) {
838
+		elseif(function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) {
839 839
 			return $decoded;
840 840
 		}
841 841
 
@@ -865,26 +865,26 @@  discard block
 block discarded – undo
865 865
 	public static function compatible_gzinflate($gzData) {
866 866
 		// Compressed data might contain a full zlib header, if so strip it for
867 867
 		// gzinflate()
868
-		if (substr($gzData, 0, 3) == "\x1f\x8b\x08") {
868
+		if(substr($gzData, 0, 3) == "\x1f\x8b\x08") {
869 869
 			$i = 10;
870 870
 			$flg = ord(substr($gzData, 3, 1));
871
-			if ($flg > 0) {
872
-				if ($flg & 4) {
871
+			if($flg > 0) {
872
+				if($flg&4) {
873 873
 					list($xlen) = unpack('v', substr($gzData, $i, 2));
874 874
 					$i = $i + 2 + $xlen;
875 875
 				}
876
-				if ($flg & 8) {
876
+				if($flg&8) {
877 877
 					$i = strpos($gzData, "\0", $i) + 1;
878 878
 				}
879
-				if ($flg & 16) {
879
+				if($flg&16) {
880 880
 					$i = strpos($gzData, "\0", $i) + 1;
881 881
 				}
882
-				if ($flg & 2) {
882
+				if($flg&2) {
883 883
 					$i = $i + 2;
884 884
 				}
885 885
 			}
886 886
 			$decompressed = self::compatible_gzinflate(substr($gzData, $i));
887
-			if (false !== $decompressed) {
887
+			if(false !== $decompressed) {
888 888
 				return $decompressed;
889 889
 			}
890 890
 		}
@@ -905,17 +905,17 @@  discard block
 block discarded – undo
905 905
 		// First 2 bytes should be divisible by 0x1F
906 906
 		list(, $first_two_bytes) = unpack('n', $gzData);
907 907
 
908
-		if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
908
+		if(0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
909 909
 			$huffman_encoded = true;
910 910
 		}
911 911
 
912
-		if ($huffman_encoded) {
913
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
912
+		if($huffman_encoded) {
913
+			if(false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
914 914
 				return $decompressed;
915 915
 			}
916 916
 		}
917 917
 
918
-		if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {
918
+		if("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {
919 919
 			// ZIP file format header
920 920
 			// Offset 6: 2 bytes, General-purpose field
921 921
 			// Offset 26: 2 bytes, filename length
@@ -927,9 +927,9 @@  discard block
 block discarded – undo
927 927
 			// If the file has been compressed on the fly, 0x08 bit is set of
928 928
 			// the general purpose field. We can use this to differentiate
929 929
 			// between a compressed document, and a ZIP file
930
-			$zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag));
930
+			$zip_compressed_on_the_fly = (0x08 == (0x08&$general_purpose_flag));
931 931
 
932
-			if (!$zip_compressed_on_the_fly) {
932
+			if(!$zip_compressed_on_the_fly) {
933 933
 				// Don't attempt to decode a compressed zip file
934 934
 				return $gzData;
935 935
 			}
@@ -937,20 +937,20 @@  discard block
 block discarded – undo
937 937
 			// Determine the first byte of data, based on the above ZIP header
938 938
 			// offsets:
939 939
 			$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
940
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
940
+			if(false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
941 941
 				return $decompressed;
942 942
 			}
943 943
 			return false;
944 944
 		}
945 945
 
946 946
 		// Finally fall back to straight gzinflate
947
-		if (false !== ($decompressed = @gzinflate($gzData))) {
947
+		if(false !== ($decompressed = @gzinflate($gzData))) {
948 948
 			return $decompressed;
949 949
 		}
950 950
 
951 951
 		// Fallback for all above failing, not expected, but included for
952 952
 		// debugging and preventing regressions and to track stats
953
-		if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
953
+		if(false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
954 954
 			return $decompressed;
955 955
 		}
956 956
 
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
 
960 960
 	public static function match_domain($host, $reference) {
961 961
 		// Check for a direct match
962
-		if ($host === $reference) {
962
+		if($host === $reference) {
963 963
 			return true;
964 964
 		}
965 965
 
@@ -967,10 +967,10 @@  discard block
 block discarded – undo
967 967
 		// Also validates that the host has 3 parts or more, as per Firefox's
968 968
 		// ruleset.
969 969
 		$parts = explode('.', $host);
970
-		if (ip2long($host) === false && count($parts) >= 3) {
970
+		if(ip2long($host) === false && count($parts) >= 3) {
971 971
 			$parts[0] = '*';
972 972
 			$wildcard = implode('.', $parts);
973
-			if ($wildcard === $reference) {
973
+			if($wildcard === $reference) {
974 974
 				return true;
975 975
 			}
976 976
 		}
Please login to merge, or discard this patch.
Braces   +237 added lines, -118 removed lines patch added patch discarded remove patch
@@ -18,7 +18,8 @@  discard block
 block discarded – undo
18 18
  *
19 19
  * @package Requests
20 20
  */
21
-class Requests {
21
+class Requests
22
+{
22 23
 	/**
23 24
 	 * POST method
24 25
 	 *
@@ -121,7 +122,9 @@  discard block
 block discarded – undo
121 122
 	 *
122 123
 	 * @codeCoverageIgnore
123 124
 	 */
124
-	private function __construct() {}
125
+	private function __construct()
126
+	{
127
+}
125 128
 
126 129
 	/**
127 130
 	 * Autoloader for Requests
@@ -135,14 +138,17 @@  discard block
 block discarded – undo
135 138
 	 *
136 139
 	 * @param string $class Class name to load
137 140
 	 */
138
-	public static function autoloader($class) {
141
+	public static function autoloader($class)
142
+	{
139 143
 		// Check that the class starts with "Requests"
140
-		if (strpos($class, 'Requests') !== 0) {
144
+		if (strpos($class, 'Requests') !== 0)
145
+		{
141 146
 			return;
142 147
 		}
143 148
 
144 149
 		$file = str_replace('_', '/', $class);
145
-		if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
150
+		if (file_exists(dirname(__FILE__) . '/' . $file . '.php'))
151
+		{
146 152
 			require_once(dirname(__FILE__) . '/' . $file . '.php');
147 153
 		}
148 154
 	}
@@ -152,7 +158,8 @@  discard block
 block discarded – undo
152 158
 	 *
153 159
 	 * @codeCoverageIgnore
154 160
 	 */
155
-	public static function register_autoloader() {
161
+	public static function register_autoloader()
162
+	{
156 163
 		spl_autoload_register(array('Requests', 'autoloader'));
157 164
 	}
158 165
 
@@ -161,8 +168,10 @@  discard block
 block discarded – undo
161 168
 	 *
162 169
 	 * @param string $transport Transport class to add, must support the Requests_Transport interface
163 170
 	 */
164
-	public static function add_transport($transport) {
165
-		if (empty(self::$transports)) {
171
+	public static function add_transport($transport)
172
+	{
173
+		if (empty(self::$transports))
174
+		{
166 175
 			self::$transports = array(
167 176
 				'Requests_Transport_cURL',
168 177
 				'Requests_Transport_fsockopen',
@@ -178,7 +187,8 @@  discard block
 block discarded – undo
178 187
 	 * @throws Requests_Exception If no valid transport is found (`notransport`)
179 188
 	 * @return Requests_Transport
180 189
 	 */
181
-	protected static function get_transport($capabilities = array()) {
190
+	protected static function get_transport($capabilities = array())
191
+	{
182 192
 		// Caching code, don't bother testing coverage
183 193
 		// @codeCoverageIgnoreStart
184 194
 		// array of capabilities as a string to be used as an array key
@@ -186,12 +196,14 @@  discard block
 block discarded – undo
186 196
 		$cap_string = serialize($capabilities);
187 197
 
188 198
 		// Don't search for a transport if it's already been done for these $capabilities
189
-		if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
199
+		if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null)
200
+		{
190 201
 			return new self::$transport[$cap_string]();
191 202
 		}
192 203
 		// @codeCoverageIgnoreEnd
193 204
 
194
-		if (empty(self::$transports)) {
205
+		if (empty(self::$transports))
206
+		{
195 207
 			self::$transports = array(
196 208
 				'Requests_Transport_cURL',
197 209
 				'Requests_Transport_fsockopen',
@@ -199,18 +211,22 @@  discard block
 block discarded – undo
199 211
 		}
200 212
 
201 213
 		// Find us a working transport
202
-		foreach (self::$transports as $class) {
203
-			if (!class_exists($class)) {
214
+		foreach (self::$transports as $class)
215
+		{
216
+			if (!class_exists($class))
217
+			{
204 218
 				continue;
205 219
 			}
206 220
 
207 221
 			$result = call_user_func(array($class, 'test'), $capabilities);
208
-			if ($result) {
222
+			if ($result)
223
+			{
209 224
 				self::$transport[$cap_string] = $class;
210 225
 				break;
211 226
 			}
212 227
 		}
213
-		if (self::$transport[$cap_string] === null) {
228
+		if (self::$transport[$cap_string] === null)
229
+		{
214 230
 			throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
215 231
 		}
216 232
 
@@ -227,28 +243,32 @@  discard block
 block discarded – undo
227 243
 	/**
228 244
 	 * Send a GET request
229 245
 	 */
230
-	public static function get($url, $headers = array(), $options = array()) {
246
+	public static function get($url, $headers = array(), $options = array())
247
+	{
231 248
 		return self::request($url, $headers, null, self::GET, $options);
232 249
 	}
233 250
 
234 251
 	/**
235 252
 	 * Send a HEAD request
236 253
 	 */
237
-	public static function head($url, $headers = array(), $options = array()) {
254
+	public static function head($url, $headers = array(), $options = array())
255
+	{
238 256
 		return self::request($url, $headers, null, self::HEAD, $options);
239 257
 	}
240 258
 
241 259
 	/**
242 260
 	 * Send a DELETE request
243 261
 	 */
244
-	public static function delete($url, $headers = array(), $options = array()) {
262
+	public static function delete($url, $headers = array(), $options = array())
263
+	{
245 264
 		return self::request($url, $headers, null, self::DELETE, $options);
246 265
 	}
247 266
 
248 267
 	/**
249 268
 	 * Send a TRACE request
250 269
 	 */
251
-	public static function trace($url, $headers = array(), $options = array()) {
270
+	public static function trace($url, $headers = array(), $options = array())
271
+	{
252 272
 		return self::request($url, $headers, null, self::TRACE, $options);
253 273
 	}
254 274
 	/**#@-*/
@@ -264,20 +284,23 @@  discard block
 block discarded – undo
264 284
 	/**
265 285
 	 * Send a POST request
266 286
 	 */
267
-	public static function post($url, $headers = array(), $data = array(), $options = array()) {
287
+	public static function post($url, $headers = array(), $data = array(), $options = array())
288
+	{
268 289
 		return self::request($url, $headers, $data, self::POST, $options);
269 290
 	}
270 291
 	/**
271 292
 	 * Send a PUT request
272 293
 	 */
273
-	public static function put($url, $headers = array(), $data = array(), $options = array()) {
294
+	public static function put($url, $headers = array(), $data = array(), $options = array())
295
+	{
274 296
 		return self::request($url, $headers, $data, self::PUT, $options);
275 297
 	}
276 298
 
277 299
 	/**
278 300
 	 * Send an OPTIONS request
279 301
 	 */
280
-	public static function options($url, $headers = array(), $data = array(), $options = array()) {
302
+	public static function options($url, $headers = array(), $data = array(), $options = array())
303
+	{
281 304
 		return self::request($url, $headers, $data, self::OPTIONS, $options);
282 305
 	}
283 306
 
@@ -289,7 +312,8 @@  discard block
 block discarded – undo
289 312
 	 *
290 313
 	 * @link https://tools.ietf.org/html/rfc5789
291 314
 	 */
292
-	public static function patch($url, $headers, $data = array(), $options = array()) {
315
+	public static function patch($url, $headers, $data = array(), $options = array())
316
+	{
293 317
 		return self::request($url, $headers, $data, self::PATCH, $options);
294 318
 	}
295 319
 	/**#@-*/
@@ -354,8 +378,10 @@  discard block
 block discarded – undo
354 378
 	 * @param array $options Options for the request (see description for more information)
355 379
 	 * @return Requests_Response
356 380
 	 */
357
-	public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) {
358
-		if (empty($options['type'])) {
381
+	public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array())
382
+	{
383
+		if (empty($options['type']))
384
+		{
359 385
 			$options['type'] = $type;
360 386
 		}
361 387
 		$options = array_merge(self::get_default_options(), $options);
@@ -364,14 +390,17 @@  discard block
 block discarded – undo
364 390
 
365 391
 		$options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options));
366 392
 
367
-		if (!empty($options['transport'])) {
393
+		if (!empty($options['transport']))
394
+		{
368 395
 			$transport = $options['transport'];
369 396
 
370
-			if (is_string($options['transport'])) {
397
+			if (is_string($options['transport']))
398
+			{
371 399
 				$transport = new $transport();
372 400
 			}
373 401
 		}
374
-		else {
402
+		else
403
+		{
375 404
 			$need_ssl = (0 === stripos($url, 'https://'));
376 405
 			$capabilities = array('ssl' => $need_ssl);
377 406
 			$transport = self::get_transport($capabilities);
@@ -424,32 +453,42 @@  discard block
 block discarded – undo
424 453
 	 * @param array $options Global and default options (see {@see Requests::request})
425 454
 	 * @return array Responses (either Requests_Response or a Requests_Exception object)
426 455
 	 */
427
-	public static function request_multiple($requests, $options = array()) {
456
+	public static function request_multiple($requests, $options = array())
457
+	{
428 458
 		$options = array_merge(self::get_default_options(true), $options);
429 459
 
430
-		if (!empty($options['hooks'])) {
460
+		if (!empty($options['hooks']))
461
+		{
431 462
 			$options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple'));
432
-			if (!empty($options['complete'])) {
463
+			if (!empty($options['complete']))
464
+			{
433 465
 				$options['hooks']->register('multiple.request.complete', $options['complete']);
434 466
 			}
435 467
 		}
436 468
 
437
-		foreach ($requests as $id => &$request) {
438
-			if (!isset($request['headers'])) {
469
+		foreach ($requests as $id => &$request)
470
+		{
471
+			if (!isset($request['headers']))
472
+			{
439 473
 				$request['headers'] = array();
440 474
 			}
441
-			if (!isset($request['data'])) {
475
+			if (!isset($request['data']))
476
+			{
442 477
 				$request['data'] = array();
443 478
 			}
444
-			if (!isset($request['type'])) {
479
+			if (!isset($request['type']))
480
+			{
445 481
 				$request['type'] = self::GET;
446 482
 			}
447
-			if (!isset($request['options'])) {
483
+			if (!isset($request['options']))
484
+			{
448 485
 				$request['options'] = $options;
449 486
 				$request['options']['type'] = $request['type'];
450 487
 			}
451
-			else {
452
-				if (empty($request['options']['type'])) {
488
+			else
489
+			{
490
+				if (empty($request['options']['type']))
491
+				{
453 492
 					$request['options']['type'] = $request['type'];
454 493
 				}
455 494
 				$request['options'] = array_merge($options, $request['options']);
@@ -458,31 +497,38 @@  discard block
 block discarded – undo
458 497
 			self::set_defaults($request['url'], $request['headers'], $request['data'], $request['type'], $request['options']);
459 498
 
460 499
 			// Ensure we only hook in once
461
-			if ($request['options']['hooks'] !== $options['hooks']) {
500
+			if ($request['options']['hooks'] !== $options['hooks'])
501
+			{
462 502
 				$request['options']['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple'));
463
-				if (!empty($request['options']['complete'])) {
503
+				if (!empty($request['options']['complete']))
504
+				{
464 505
 					$request['options']['hooks']->register('multiple.request.complete', $request['options']['complete']);
465 506
 				}
466 507
 			}
467 508
 		}
468 509
 		unset($request);
469 510
 
470
-		if (!empty($options['transport'])) {
511
+		if (!empty($options['transport']))
512
+		{
471 513
 			$transport = $options['transport'];
472 514
 
473
-			if (is_string($options['transport'])) {
515
+			if (is_string($options['transport']))
516
+			{
474 517
 				$transport = new $transport();
475 518
 			}
476 519
 		}
477
-		else {
520
+		else
521
+		{
478 522
 			$transport = self::get_transport();
479 523
 		}
480 524
 		$responses = $transport->request_multiple($requests, $options);
481 525
 
482
-		foreach ($responses as $id => &$response) {
526
+		foreach ($responses as $id => &$response)
527
+		{
483 528
 			// If our hook got messed with somehow, ensure we end up with the
484 529
 			// correct response
485
-			if (is_string($response)) {
530
+			if (is_string($response))
531
+			{
486 532
 				$request = $requests[$id];
487 533
 				self::parse_multiple($response, $request);
488 534
 				$request['options']['hooks']->dispatch('multiple.request.complete', array(&$response, $id));
@@ -499,7 +545,8 @@  discard block
 block discarded – undo
499 545
 	 * @param boolean $multirequest Is this a multirequest?
500 546
 	 * @return array Default option values
501 547
 	 */
502
-	protected static function get_default_options($multirequest = false) {
548
+	protected static function get_default_options($multirequest = false)
549
+	{
503 550
 		$defaults = array(
504 551
 			'timeout' => 10,
505 552
 			'connect_timeout' => 10,
@@ -521,7 +568,8 @@  discard block
 block discarded – undo
521 568
 			'verify' => Requests::get_certificate_path(),
522 569
 			'verifyname' => true,
523 570
 		);
524
-		if ($multirequest !== false) {
571
+		if ($multirequest !== false)
572
+		{
525 573
 			$defaults['complete'] = null;
526 574
 		}
527 575
 		return $defaults;
@@ -532,8 +580,10 @@  discard block
 block discarded – undo
532 580
 	 *
533 581
 	 * @return string Default certificate path.
534 582
 	 */
535
-	public static function get_certificate_path() {
536
-		if ( ! empty( Requests::$certificate_path ) ) {
583
+	public static function get_certificate_path()
584
+	{
585
+		if ( ! empty( Requests::$certificate_path ) )
586
+		{
537 587
 			return Requests::$certificate_path;
538 588
 		}
539 589
 
@@ -545,7 +595,8 @@  discard block
 block discarded – undo
545 595
 	 *
546 596
 	 * @param string $path Certificate path, pointing to a PEM file.
547 597
 	 */
548
-	public static function set_certificate_path( $path ) {
598
+	public static function set_certificate_path( $path )
599
+	{
549 600
 		Requests::$certificate_path = $path;
550 601
 	}
551 602
 
@@ -559,40 +610,51 @@  discard block
 block discarded – undo
559 610
 	 * @param array $options Options for the request
560 611
 	 * @return array $options
561 612
 	 */
562
-	protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
563
-		if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
613
+	protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options)
614
+	{
615
+		if (!preg_match('/^http(s)?:\/\//i', $url, $matches))
616
+		{
564 617
 			throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
565 618
 		}
566 619
 
567
-		if (empty($options['hooks'])) {
620
+		if (empty($options['hooks']))
621
+		{
568 622
 			$options['hooks'] = new Requests_Hooks();
569 623
 		}
570 624
 
571
-		if (is_array($options['auth'])) {
625
+		if (is_array($options['auth']))
626
+		{
572 627
 			$options['auth'] = new Requests_Auth_Basic($options['auth']);
573 628
 		}
574
-		if ($options['auth'] !== false) {
629
+		if ($options['auth'] !== false)
630
+		{
575 631
 			$options['auth']->register($options['hooks']);
576 632
 		}
577 633
 
578
-		if (is_string($options['proxy']) || is_array($options['proxy'])) {
634
+		if (is_string($options['proxy']) || is_array($options['proxy']))
635
+		{
579 636
 			$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
580 637
 		}
581
-		if ($options['proxy'] !== false) {
638
+		if ($options['proxy'] !== false)
639
+		{
582 640
 			$options['proxy']->register($options['hooks']);
583 641
 		}
584 642
 
585
-		if (is_array($options['cookies'])) {
643
+		if (is_array($options['cookies']))
644
+		{
586 645
 			$options['cookies'] = new Requests_Cookie_Jar($options['cookies']);
587 646
 		}
588
-		elseif (empty($options['cookies'])) {
647
+		elseif (empty($options['cookies']))
648
+		{
589 649
 			$options['cookies'] = new Requests_Cookie_Jar();
590 650
 		}
591
-		if ($options['cookies'] !== false) {
651
+		if ($options['cookies'] !== false)
652
+		{
592 653
 			$options['cookies']->register($options['hooks']);
593 654
 		}
594 655
 
595
-		if ($options['idn'] !== false) {
656
+		if ($options['idn'] !== false)
657
+		{
596 658
 			$iri = new Requests_IRI($url);
597 659
 			$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
598 660
 			$url = $iri->uri;
@@ -601,11 +663,14 @@  discard block
 block discarded – undo
601 663
 		// Massage the type to ensure we support it.
602 664
 		$type = strtoupper($type);
603 665
 
604
-		if (!isset($options['data_format'])) {
605
-			if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) {
666
+		if (!isset($options['data_format']))
667
+		{
668
+			if (in_array($type, array(self::HEAD, self::GET, self::DELETE)))
669
+			{
606 670
 				$options['data_format'] = 'query';
607 671
 			}
608
-			else {
672
+			else
673
+			{
609 674
 				$options['data_format'] = 'body';
610 675
 			}
611 676
 		}
@@ -625,17 +690,21 @@  discard block
 block discarded – undo
625 690
 	 * @param array $options Original $options array passed to {@link request()}, in case we need to follow redirects
626 691
 	 * @return Requests_Response
627 692
 	 */
628
-	protected static function parse_response($headers, $url, $req_headers, $req_data, $options) {
693
+	protected static function parse_response($headers, $url, $req_headers, $req_data, $options)
694
+	{
629 695
 		$return = new Requests_Response();
630
-		if (!$options['blocking']) {
696
+		if (!$options['blocking'])
697
+		{
631 698
 			return $return;
632 699
 		}
633 700
 
634 701
 		$return->raw = $headers;
635 702
 		$return->url = $url;
636 703
 
637
-		if (!$options['filename']) {
638
-			if (($pos = strpos($headers, "\r\n\r\n")) === false) {
704
+		if (!$options['filename'])
705
+		{
706
+			if (($pos = strpos($headers, "\r\n\r\n")) === false)
707
+			{
639 708
 				// Crap!
640 709
 				throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator');
641 710
 			}
@@ -643,7 +712,8 @@  discard block
 block discarded – undo
643 712
 			$headers = substr($return->raw, 0, $pos);
644 713
 			$return->body = substr($return->raw, $pos + strlen("\n\r\n\r"));
645 714
 		}
646
-		else {
715
+		else
716
+		{
647 717
 			$return->body = '';
648 718
 		}
649 719
 		// Pretend CRLF = LF for compatibility (RFC 2616, section 19.3)
@@ -652,44 +722,54 @@  discard block
 block discarded – undo
652 722
 		$headers = preg_replace('/\n[ \t]/', ' ', $headers);
653 723
 		$headers = explode("\n", $headers);
654 724
 		preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches);
655
-		if (empty($matches)) {
725
+		if (empty($matches))
726
+		{
656 727
 			throw new Requests_Exception('Response could not be parsed', 'noversion', $headers);
657 728
 		}
658 729
 		$return->protocol_version = (float) $matches[1];
659 730
 		$return->status_code = (int) $matches[2];
660
-		if ($return->status_code >= 200 && $return->status_code < 300) {
731
+		if ($return->status_code >= 200 && $return->status_code < 300)
732
+		{
661 733
 			$return->success = true;
662 734
 		}
663 735
 
664
-		foreach ($headers as $header) {
736
+		foreach ($headers as $header)
737
+		{
665 738
 			list($key, $value) = explode(':', $header, 2);
666 739
 			$value = trim($value);
667 740
 			preg_replace('#(\s+)#i', ' ', $value);
668 741
 			$return->headers[$key] = $value;
669 742
 		}
670
-		if (isset($return->headers['transfer-encoding'])) {
743
+		if (isset($return->headers['transfer-encoding']))
744
+		{
671 745
 			$return->body = self::decode_chunked($return->body);
672 746
 			unset($return->headers['transfer-encoding']);
673 747
 		}
674
-		if (isset($return->headers['content-encoding'])) {
748
+		if (isset($return->headers['content-encoding']))
749
+		{
675 750
 			$return->body = self::decompress($return->body);
676 751
 		}
677 752
 
678 753
 		//fsockopen and cURL compatibility
679
-		if (isset($return->headers['connection'])) {
754
+		if (isset($return->headers['connection']))
755
+		{
680 756
 			unset($return->headers['connection']);
681 757
 		}
682 758
 
683 759
 		$options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options));
684 760
 
685
-		if ($return->is_redirect() && $options['follow_redirects'] === true) {
686
-			if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
687
-				if ($return->status_code === 303) {
761
+		if ($return->is_redirect() && $options['follow_redirects'] === true)
762
+		{
763
+			if (isset($return->headers['location']) && $options['redirected'] < $options['redirects'])
764
+			{
765
+				if ($return->status_code === 303)
766
+				{
688 767
 					$options['type'] = self::GET;
689 768
 				}
690 769
 				$options['redirected']++;
691 770
 				$location = $return->headers['location'];
692
-				if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
771
+				if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0)
772
+				{
693 773
 					// relative redirect, for compatibility make it absolute
694 774
 					$location = Requests_IRI::absolutize($url, $location);
695 775
 					$location = $location->uri;
@@ -707,7 +787,8 @@  discard block
 block discarded – undo
707 787
 				$redirected->history[] = $return;
708 788
 				return $redirected;
709 789
 			}
710
-			elseif ($options['redirected'] >= $options['redirects']) {
790
+			elseif ($options['redirected'] >= $options['redirects'])
791
+			{
711 792
 				throw new Requests_Exception('Too many redirects', 'toomanyredirects', $return);
712 793
 			}
713 794
 		}
@@ -728,15 +809,18 @@  discard block
 block discarded – undo
728 809
 	 * @param array $request Request data as passed into {@see Requests::request_multiple()}
729 810
 	 * @return null `$response` is either set to a Requests_Response instance, or a Requests_Exception object
730 811
 	 */
731
-	public static function parse_multiple(&$response, $request) {
732
-		try {
812
+	public static function parse_multiple(&$response, $request)
813
+	{
814
+		try
815
+		{
733 816
 			$url = $request['url'];
734 817
 			$headers = $request['headers'];
735 818
 			$data = $request['data'];
736 819
 			$options = $request['options'];
737 820
 			$response = self::parse_response($response, $url, $headers, $data, $options);
738 821
 		}
739
-		catch (Requests_Exception $e) {
822
+		catch (Requests_Exception $e)
823
+		{
740 824
 			$response = $e;
741 825
 		}
742 826
 	}
@@ -748,8 +832,10 @@  discard block
 block discarded – undo
748 832
 	 * @param string $data Chunked body
749 833
 	 * @return string Decoded body
750 834
 	 */
751
-	protected static function decode_chunked($data) {
752
-		if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
835
+	protected static function decode_chunked($data)
836
+	{
837
+		if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data)))
838
+		{
753 839
 			return $data;
754 840
 		}
755 841
 
@@ -758,15 +844,18 @@  discard block
 block discarded – undo
758 844
 		$decoded = '';
759 845
 		$encoded = $data;
760 846
 
761
-		while (true) {
847
+		while (true)
848
+		{
762 849
 			$is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
763
-			if (!$is_chunked) {
850
+			if (!$is_chunked)
851
+			{
764 852
 				// Looks like it's not chunked after all
765 853
 				return $data;
766 854
 			}
767 855
 
768 856
 			$length = hexdec(trim($matches[1]));
769
-			if ($length === 0) {
857
+			if ($length === 0)
858
+			{
770 859
 				// Ignore trailer headers
771 860
 				return $decoded;
772 861
 			}
@@ -775,7 +864,8 @@  discard block
 block discarded – undo
775 864
 			$decoded .= substr($encoded, $chunk_length, $length);
776 865
 			$encoded = substr($encoded, $chunk_length + $length + 2);
777 866
 
778
-			if (trim($encoded) === '0' || empty($encoded)) {
867
+			if (trim($encoded) === '0' || empty($encoded))
868
+			{
779 869
 				return $decoded;
780 870
 			}
781 871
 		}
@@ -791,9 +881,11 @@  discard block
 block discarded – undo
791 881
 	 * @param array $array Dictionary of header values
792 882
 	 * @return array List of headers
793 883
 	 */
794
-	public static function flatten($array) {
884
+	public static function flatten($array)
885
+	{
795 886
 		$return = array();
796
-		foreach ($array as $key => $value) {
887
+		foreach ($array as $key => $value)
888
+		{
797 889
 			$return[] = sprintf('%s: %s', $key, $value);
798 890
 		}
799 891
 		return $return;
@@ -807,7 +899,8 @@  discard block
 block discarded – undo
807 899
 	 * @param array $array Dictionary of header values
808 900
 	 * @return array List of headers
809 901
 	 */
810
-	public static function flattern($array) {
902
+	public static function flattern($array)
903
+	{
811 904
 		return self::flatten($array);
812 905
 	}
813 906
 
@@ -820,22 +913,28 @@  discard block
 block discarded – undo
820 913
 	 * @param string $data Compressed data in one of the above formats
821 914
 	 * @return string Decompressed string
822 915
 	 */
823
-	public static function decompress($data) {
824
-		if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") {
916
+	public static function decompress($data)
917
+	{
918
+		if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c")
919
+		{
825 920
 			// Not actually compressed. Probably cURL ruining this for us.
826 921
 			return $data;
827 922
 		}
828 923
 
829
-		if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) {
924
+		if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false)
925
+		{
830 926
 			return $decoded;
831 927
 		}
832
-		elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) {
928
+		elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false)
929
+		{
833 930
 			return $decoded;
834 931
 		}
835
-		elseif (($decoded = self::compatible_gzinflate($data)) !== false) {
932
+		elseif (($decoded = self::compatible_gzinflate($data)) !== false)
933
+		{
836 934
 			return $decoded;
837 935
 		}
838
-		elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) {
936
+		elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false)
937
+		{
839 938
 			return $decoded;
840 939
 		}
841 940
 
@@ -862,29 +961,37 @@  discard block
 block discarded – undo
862 961
 	 * @param string $gzData String to decompress.
863 962
 	 * @return string|bool False on failure.
864 963
 	 */
865
-	public static function compatible_gzinflate($gzData) {
964
+	public static function compatible_gzinflate($gzData)
965
+	{
866 966
 		// Compressed data might contain a full zlib header, if so strip it for
867 967
 		// gzinflate()
868
-		if (substr($gzData, 0, 3) == "\x1f\x8b\x08") {
968
+		if (substr($gzData, 0, 3) == "\x1f\x8b\x08")
969
+		{
869 970
 			$i = 10;
870 971
 			$flg = ord(substr($gzData, 3, 1));
871
-			if ($flg > 0) {
872
-				if ($flg & 4) {
972
+			if ($flg > 0)
973
+			{
974
+				if ($flg & 4)
975
+				{
873 976
 					list($xlen) = unpack('v', substr($gzData, $i, 2));
874 977
 					$i = $i + 2 + $xlen;
875 978
 				}
876
-				if ($flg & 8) {
979
+				if ($flg & 8)
980
+				{
877 981
 					$i = strpos($gzData, "\0", $i) + 1;
878 982
 				}
879
-				if ($flg & 16) {
983
+				if ($flg & 16)
984
+				{
880 985
 					$i = strpos($gzData, "\0", $i) + 1;
881 986
 				}
882
-				if ($flg & 2) {
987
+				if ($flg & 2)
988
+				{
883 989
 					$i = $i + 2;
884 990
 				}
885 991
 			}
886 992
 			$decompressed = self::compatible_gzinflate(substr($gzData, $i));
887
-			if (false !== $decompressed) {
993
+			if (false !== $decompressed)
994
+			{
888 995
 				return $decompressed;
889 996
 			}
890 997
 		}
@@ -905,17 +1012,21 @@  discard block
 block discarded – undo
905 1012
 		// First 2 bytes should be divisible by 0x1F
906 1013
 		list(, $first_two_bytes) = unpack('n', $gzData);
907 1014
 
908
-		if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
1015
+		if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F))
1016
+		{
909 1017
 			$huffman_encoded = true;
910 1018
 		}
911 1019
 
912
-		if ($huffman_encoded) {
913
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
1020
+		if ($huffman_encoded)
1021
+		{
1022
+			if (false !== ($decompressed = @gzinflate(substr($gzData, 2))))
1023
+			{
914 1024
 				return $decompressed;
915 1025
 			}
916 1026
 		}
917 1027
 
918
-		if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {
1028
+		if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4))
1029
+		{
919 1030
 			// ZIP file format header
920 1031
 			// Offset 6: 2 bytes, General-purpose field
921 1032
 			// Offset 26: 2 bytes, filename length
@@ -929,7 +1040,8 @@  discard block
 block discarded – undo
929 1040
 			// between a compressed document, and a ZIP file
930 1041
 			$zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag));
931 1042
 
932
-			if (!$zip_compressed_on_the_fly) {
1043
+			if (!$zip_compressed_on_the_fly)
1044
+			{
933 1045
 				// Don't attempt to decode a compressed zip file
934 1046
 				return $gzData;
935 1047
 			}
@@ -937,29 +1049,34 @@  discard block
 block discarded – undo
937 1049
 			// Determine the first byte of data, based on the above ZIP header
938 1050
 			// offsets:
939 1051
 			$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
940
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
1052
+			if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start))))
1053
+			{
941 1054
 				return $decompressed;
942 1055
 			}
943 1056
 			return false;
944 1057
 		}
945 1058
 
946 1059
 		// Finally fall back to straight gzinflate
947
-		if (false !== ($decompressed = @gzinflate($gzData))) {
1060
+		if (false !== ($decompressed = @gzinflate($gzData)))
1061
+		{
948 1062
 			return $decompressed;
949 1063
 		}
950 1064
 
951 1065
 		// Fallback for all above failing, not expected, but included for
952 1066
 		// debugging and preventing regressions and to track stats
953
-		if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
1067
+		if (false !== ($decompressed = @gzinflate(substr($gzData, 2))))
1068
+		{
954 1069
 			return $decompressed;
955 1070
 		}
956 1071
 
957 1072
 		return false;
958 1073
 	}
959 1074
 
960
-	public static function match_domain($host, $reference) {
1075
+	public static function match_domain($host, $reference)
1076
+	{
961 1077
 		// Check for a direct match
962
-		if ($host === $reference) {
1078
+		if ($host === $reference)
1079
+		{
963 1080
 			return true;
964 1081
 		}
965 1082
 
@@ -967,10 +1084,12 @@  discard block
 block discarded – undo
967 1084
 		// Also validates that the host has 3 parts or more, as per Firefox's
968 1085
 		// ruleset.
969 1086
 		$parts = explode('.', $host);
970
-		if (ip2long($host) === false && count($parts) >= 3) {
1087
+		if (ip2long($host) === false && count($parts) >= 3)
1088
+		{
971 1089
 			$parts[0] = '*';
972 1090
 			$wildcard = implode('.', $parts);
973
-			if ($wildcard === $reference) {
1091
+			if ($wildcard === $reference)
1092
+			{
974 1093
 				return true;
975 1094
 			}
976 1095
 		}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		$cap_string = serialize($capabilities);
187 187
 
188 188
 		// Don't search for a transport if it's already been done for these $capabilities
189
-		if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
189
+		if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== NULL) {
190 190
 			return new self::$transport[$cap_string]();
191 191
 		}
192 192
 		// @codeCoverageIgnoreEnd
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 				break;
211 211
 			}
212 212
 		}
213
-		if (self::$transport[$cap_string] === null) {
213
+		if (self::$transport[$cap_string] === NULL) {
214 214
 			throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
215 215
 		}
216 216
 
@@ -228,28 +228,28 @@  discard block
 block discarded – undo
228 228
 	 * Send a GET request
229 229
 	 */
230 230
 	public static function get($url, $headers = array(), $options = array()) {
231
-		return self::request($url, $headers, null, self::GET, $options);
231
+		return self::request($url, $headers, NULL, self::GET, $options);
232 232
 	}
233 233
 
234 234
 	/**
235 235
 	 * Send a HEAD request
236 236
 	 */
237 237
 	public static function head($url, $headers = array(), $options = array()) {
238
-		return self::request($url, $headers, null, self::HEAD, $options);
238
+		return self::request($url, $headers, NULL, self::HEAD, $options);
239 239
 	}
240 240
 
241 241
 	/**
242 242
 	 * Send a DELETE request
243 243
 	 */
244 244
 	public static function delete($url, $headers = array(), $options = array()) {
245
-		return self::request($url, $headers, null, self::DELETE, $options);
245
+		return self::request($url, $headers, NULL, self::DELETE, $options);
246 246
 	}
247 247
 
248 248
 	/**
249 249
 	 * Send a TRACE request
250 250
 	 */
251 251
 	public static function trace($url, $headers = array(), $options = array()) {
252
-		return self::request($url, $headers, null, self::TRACE, $options);
252
+		return self::request($url, $headers, NULL, self::TRACE, $options);
253 253
 	}
254 254
 	/**#@-*/
255 255
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 	 * @return array Responses (either Requests_Response or a Requests_Exception object)
426 426
 	 */
427 427
 	public static function request_multiple($requests, $options = array()) {
428
-		$options = array_merge(self::get_default_options(true), $options);
428
+		$options = array_merge(self::get_default_options(TRUE), $options);
429 429
 
430 430
 		if (!empty($options['hooks'])) {
431 431
 			$options['hooks']->register('transport.internal.parse_response', array('Requests', 'parse_multiple'));
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 	 * @param boolean $multirequest Is this a multirequest?
500 500
 	 * @return array Default option values
501 501
 	 */
502
-	protected static function get_default_options($multirequest = false) {
502
+	protected static function get_default_options($multirequest = FALSE) {
503 503
 		$defaults = array(
504 504
 			'timeout' => 10,
505 505
 			'connect_timeout' => 10,
@@ -507,22 +507,22 @@  discard block
 block discarded – undo
507 507
 			'protocol_version' => 1.1,
508 508
 			'redirected' => 0,
509 509
 			'redirects' => 10,
510
-			'follow_redirects' => true,
511
-			'blocking' => true,
510
+			'follow_redirects' => TRUE,
511
+			'blocking' => TRUE,
512 512
 			'type' => self::GET,
513
-			'filename' => false,
514
-			'auth' => false,
515
-			'proxy' => false,
516
-			'cookies' => false,
517
-			'max_bytes' => false,
518
-			'idn' => true,
519
-			'hooks' => null,
520
-			'transport' => null,
513
+			'filename' => FALSE,
514
+			'auth' => FALSE,
515
+			'proxy' => FALSE,
516
+			'cookies' => FALSE,
517
+			'max_bytes' => FALSE,
518
+			'idn' => TRUE,
519
+			'hooks' => NULL,
520
+			'transport' => NULL,
521 521
 			'verify' => Requests::get_certificate_path(),
522
-			'verifyname' => true,
522
+			'verifyname' => TRUE,
523 523
 		);
524
-		if ($multirequest !== false) {
525
-			$defaults['complete'] = null;
524
+		if ($multirequest !== FALSE) {
525
+			$defaults['complete'] = NULL;
526 526
 		}
527 527
 		return $defaults;
528 528
 	}
@@ -571,14 +571,14 @@  discard block
 block discarded – undo
571 571
 		if (is_array($options['auth'])) {
572 572
 			$options['auth'] = new Requests_Auth_Basic($options['auth']);
573 573
 		}
574
-		if ($options['auth'] !== false) {
574
+		if ($options['auth'] !== FALSE) {
575 575
 			$options['auth']->register($options['hooks']);
576 576
 		}
577 577
 
578 578
 		if (is_string($options['proxy']) || is_array($options['proxy'])) {
579 579
 			$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
580 580
 		}
581
-		if ($options['proxy'] !== false) {
581
+		if ($options['proxy'] !== FALSE) {
582 582
 			$options['proxy']->register($options['hooks']);
583 583
 		}
584 584
 
@@ -588,11 +588,11 @@  discard block
 block discarded – undo
588 588
 		elseif (empty($options['cookies'])) {
589 589
 			$options['cookies'] = new Requests_Cookie_Jar();
590 590
 		}
591
-		if ($options['cookies'] !== false) {
591
+		if ($options['cookies'] !== FALSE) {
592 592
 			$options['cookies']->register($options['hooks']);
593 593
 		}
594 594
 
595
-		if ($options['idn'] !== false) {
595
+		if ($options['idn'] !== FALSE) {
596 596
 			$iri = new Requests_IRI($url);
597 597
 			$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
598 598
 			$url = $iri->uri;
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 		$return->url = $url;
636 636
 
637 637
 		if (!$options['filename']) {
638
-			if (($pos = strpos($headers, "\r\n\r\n")) === false) {
638
+			if (($pos = strpos($headers, "\r\n\r\n")) === FALSE) {
639 639
 				// Crap!
640 640
 				throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator');
641 641
 			}
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 		$return->protocol_version = (float) $matches[1];
659 659
 		$return->status_code = (int) $matches[2];
660 660
 		if ($return->status_code >= 200 && $return->status_code < 300) {
661
-			$return->success = true;
661
+			$return->success = TRUE;
662 662
 		}
663 663
 
664 664
 		foreach ($headers as $header) {
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 
683 683
 		$options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options));
684 684
 
685
-		if ($return->is_redirect() && $options['follow_redirects'] === true) {
685
+		if ($return->is_redirect() && $options['follow_redirects'] === TRUE) {
686 686
 			if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
687 687
 				if ($return->status_code === 303) {
688 688
 					$options['type'] = self::GET;
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 		$decoded = '';
759 759
 		$encoded = $data;
760 760
 
761
-		while (true) {
761
+		while (TRUE) {
762 762
 			$is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
763 763
 			if (!$is_chunked) {
764 764
 				// Looks like it's not chunked after all
@@ -826,16 +826,16 @@  discard block
 block discarded – undo
826 826
 			return $data;
827 827
 		}
828 828
 
829
-		if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== false) {
829
+		if (function_exists('gzdecode') && ($decoded = @gzdecode($data)) !== FALSE) {
830 830
 			return $decoded;
831 831
 		}
832
-		elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== false) {
832
+		elseif (function_exists('gzinflate') && ($decoded = @gzinflate($data)) !== FALSE) {
833 833
 			return $decoded;
834 834
 		}
835
-		elseif (($decoded = self::compatible_gzinflate($data)) !== false) {
835
+		elseif (($decoded = self::compatible_gzinflate($data)) !== FALSE) {
836 836
 			return $decoded;
837 837
 		}
838
-		elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== false) {
838
+		elseif (function_exists('gzuncompress') && ($decoded = @gzuncompress($data)) !== FALSE) {
839 839
 			return $decoded;
840 840
 		}
841 841
 
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 				}
885 885
 			}
886 886
 			$decompressed = self::compatible_gzinflate(substr($gzData, $i));
887
-			if (false !== $decompressed) {
887
+			if (FALSE !== $decompressed) {
888 888
 				return $decompressed;
889 889
 			}
890 890
 		}
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 		//
898 898
 		// See https://decompres.blogspot.com/ for a quick explanation of this
899 899
 		// data type
900
-		$huffman_encoded = false;
900
+		$huffman_encoded = FALSE;
901 901
 
902 902
 		// low nibble of first byte should be 0x08
903 903
 		list(, $first_nibble)    = unpack('h', $gzData);
@@ -906,11 +906,11 @@  discard block
 block discarded – undo
906 906
 		list(, $first_two_bytes) = unpack('n', $gzData);
907 907
 
908 908
 		if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
909
-			$huffman_encoded = true;
909
+			$huffman_encoded = TRUE;
910 910
 		}
911 911
 
912 912
 		if ($huffman_encoded) {
913
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
913
+			if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
914 914
 				return $decompressed;
915 915
 			}
916 916
 		}
@@ -937,44 +937,44 @@  discard block
 block discarded – undo
937 937
 			// Determine the first byte of data, based on the above ZIP header
938 938
 			// offsets:
939 939
 			$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
940
-			if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
940
+			if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
941 941
 				return $decompressed;
942 942
 			}
943
-			return false;
943
+			return FALSE;
944 944
 		}
945 945
 
946 946
 		// Finally fall back to straight gzinflate
947
-		if (false !== ($decompressed = @gzinflate($gzData))) {
947
+		if (FALSE !== ($decompressed = @gzinflate($gzData))) {
948 948
 			return $decompressed;
949 949
 		}
950 950
 
951 951
 		// Fallback for all above failing, not expected, but included for
952 952
 		// debugging and preventing regressions and to track stats
953
-		if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
953
+		if (FALSE !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
954 954
 			return $decompressed;
955 955
 		}
956 956
 
957
-		return false;
957
+		return FALSE;
958 958
 	}
959 959
 
960 960
 	public static function match_domain($host, $reference) {
961 961
 		// Check for a direct match
962 962
 		if ($host === $reference) {
963
-			return true;
963
+			return TRUE;
964 964
 		}
965 965
 
966 966
 		// Calculate the valid wildcard match if the host is not an IP address
967 967
 		// Also validates that the host has 3 parts or more, as per Firefox's
968 968
 		// ruleset.
969 969
 		$parts = explode('.', $host);
970
-		if (ip2long($host) === false && count($parts) >= 3) {
970
+		if (ip2long($host) === FALSE && count($parts) >= 3) {
971 971
 			$parts[0] = '*';
972 972
 			$wildcard = implode('.', $parts);
973 973
 			if ($wildcard === $reference) {
974
-				return true;
974
+				return TRUE;
975 975
 			}
976 976
 		}
977 977
 
978
-		return false;
978
+		return FALSE;
979 979
 	}
980 980
 }
Please login to merge, or discard this patch.
php/Requests/libary/Requests/IDNAEncoder.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@
 block discarded – undo
357 357
 	 * @param int $delta
358 358
 	 * @param int $numpoints
359 359
 	 * @param bool $firsttime
360
-	 * @return int New bias
360
+	 * @return double New bias
361 361
 	 */
362 362
 	protected static function adapt($delta, $numpoints, $firsttime) {
363 363
 #	function adapt(delta,numpoints,firsttime):
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public static function encode($string) {
44 44
 		$parts = explode('.', $string);
45
-		foreach ($parts as &$part) {
45
+		foreach($parts as &$part) {
46 46
 			$part = self::to_ascii($part);
47 47
 		}
48 48
 		return implode('.', $parts);
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public static function to_ascii($string) {
63 63
 		// Step 1: Check if the string is already ASCII
64
-		if (self::is_ascii($string)) {
64
+		if(self::is_ascii($string)) {
65 65
 			// Skip to step 7
66
-			if (strlen($string) < 64) {
66
+			if(strlen($string) < 64) {
67 67
 				return $string;
68 68
 			}
69 69
 
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 
76 76
 		// Step 3: UseSTD3ASCIIRules is false, continue
77 77
 		// Step 4: Check if it's ASCII now
78
-		if (self::is_ascii($string)) {
78
+		if(self::is_ascii($string)) {
79 79
 			// Skip to step 7
80
-			if (strlen($string) < 64) {
80
+			if(strlen($string) < 64) {
81 81
 				return $string;
82 82
 			}
83 83
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		}
86 86
 
87 87
 		// Step 5: Check ACE prefix
88
-		if (strpos($string, self::ACE_PREFIX) === 0) {
88
+		if(strpos($string, self::ACE_PREFIX) === 0) {
89 89
 			throw new Requests_Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $string);
90 90
 		}
91 91
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		$string = self::ACE_PREFIX . $string;
97 97
 
98 98
 		// Step 8: Check size
99
-		if (strlen($string) < 64) {
99
+		if(strlen($string) < 64) {
100 100
 			return $string;
101 101
 		}
102 102
 
@@ -141,30 +141,30 @@  discard block
 block discarded – undo
141 141
 		// Get number of bytes
142 142
 		$strlen = strlen($input);
143 143
 
144
-		for ($position = 0; $position < $strlen; $position++) {
144
+		for($position = 0; $position < $strlen; $position++) {
145 145
 			$value = ord($input[$position]);
146 146
 
147 147
 			// One byte sequence:
148
-			if ((~$value & 0x80) === 0x80) {
148
+			if((~$value&0x80) === 0x80) {
149 149
 				$character = $value;
150 150
 				$length = 1;
151 151
 				$remaining = 0;
152 152
 			}
153 153
 			// Two byte sequence:
154
-			elseif (($value & 0xE0) === 0xC0) {
155
-				$character = ($value & 0x1F) << 6;
154
+			elseif(($value&0xE0) === 0xC0) {
155
+				$character = ($value&0x1F) << 6;
156 156
 				$length = 2;
157 157
 				$remaining = 1;
158 158
 			}
159 159
 			// Three byte sequence:
160
-			elseif (($value & 0xF0) === 0xE0) {
161
-				$character = ($value & 0x0F) << 12;
160
+			elseif(($value&0xF0) === 0xE0) {
161
+				$character = ($value&0x0F) << 12;
162 162
 				$length = 3;
163 163
 				$remaining = 2;
164 164
 			}
165 165
 			// Four byte sequence:
166
-			elseif (($value & 0xF8) === 0xF0) {
167
-				$character = ($value & 0x07) << 18;
166
+			elseif(($value&0xF8) === 0xF0) {
167
+				$character = ($value&0x07) << 18;
168 168
 				$length = 4;
169 169
 				$remaining = 3;
170 170
 			}
@@ -173,31 +173,31 @@  discard block
 block discarded – undo
173 173
 				throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
174 174
 			}
175 175
 
176
-			if ($remaining > 0) {
177
-				if ($position + $length > $strlen) {
176
+			if($remaining > 0) {
177
+				if($position + $length > $strlen) {
178 178
 					throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
179 179
 				}
180
-				for ($position++; $remaining > 0; $position++) {
180
+				for($position++; $remaining > 0; $position++) {
181 181
 					$value = ord($input[$position]);
182 182
 
183 183
 					// If it is invalid, count the sequence as invalid and reprocess the current byte:
184
-					if (($value & 0xC0) !== 0x80) {
184
+					if(($value&0xC0) !== 0x80) {
185 185
 						throw new Requests_Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
186 186
 					}
187 187
 
188
-					$character |= ($value & 0x3F) << (--$remaining * 6);
188
+					$character |= ($value&0x3F) << (--$remaining * 6);
189 189
 				}
190 190
 				$position--;
191 191
 			}
192 192
 
193
-			if (
193
+			if(
194 194
 				// Non-shortest form sequences are invalid
195 195
 				   $length > 1 && $character <= 0x7F
196 196
 				|| $length > 2 && $character <= 0x7FF
197 197
 				|| $length > 3 && $character <= 0xFFFF
198 198
 				// Outside of range of ucschar codepoints
199 199
 				// Noncharacters
200
-				|| ($character & 0xFFFE) === 0xFFFE
200
+				|| ($character&0xFFFE) === 0xFFFE
201 201
 				|| $character >= 0xFDD0 && $character <= 0xFDEF
202 202
 				|| (
203 203
 					// Everything else not in ucschar
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 		$codepoints = self::utf8_to_codepoints($input);
240 240
 		$extended = array();
241 241
 
242
-		foreach ($codepoints as $char) {
243
-			if ($char < 128) {
242
+		foreach($codepoints as $char) {
243
+			if($char < 128) {
244 244
 				// Character is valid ASCII
245 245
 				// TODO: this should also check if it's valid for a URL
246 246
 				$output .= chr($char);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			// Check if the character is non-ASCII, but below initial n
250 250
 			// This never occurs for Punycode, so ignore in coverage
251 251
 			// @codeCoverageIgnoreStart
252
-			elseif ($char < $n) {
252
+			elseif($char < $n) {
253 253
 				throw new Requests_Exception('Invalid character', 'idna.character_outside_domain', $char);
254 254
 			}
255 255
 			// @codeCoverageIgnoreEnd
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
 		sort($extended);
262 262
 		$b = $h;
263 263
 #		[copy them] followed by a delimiter if b > 0
264
-		if (strlen($output) > 0) {
264
+		if(strlen($output) > 0) {
265 265
 			$output .= '-';
266 266
 		}
267 267
 #		{if the input contains a non-basic code point < n then fail}
268 268
 #		while h < length(input) do begin
269
-		while ($h < count($codepoints)) {
269
+		while($h < count($codepoints)) {
270 270
 #			let m = the minimum code point >= n in the input
271 271
 			$m = array_shift($extended);
272 272
 			//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
@@ -275,31 +275,31 @@  discard block
 block discarded – undo
275 275
 #			let n = m
276 276
 			$n = $m;
277 277
 #			for each code point c in the input (in order) do begin
278
-			for ($num = 0; $num < count($codepoints); $num++) {
278
+			for($num = 0; $num < count($codepoints); $num++) {
279 279
 				$c = $codepoints[$num];
280 280
 #				if c < n then increment delta, fail on overflow
281
-				if ($c < $n) {
281
+				if($c < $n) {
282 282
 					$delta++;
283 283
 				}
284 284
 #				if c == n then begin
285
-				elseif ($c === $n) {
285
+				elseif($c === $n) {
286 286
 #					let q = delta
287 287
 					$q = $delta;
288 288
 #					for k = base to infinity in steps of base do begin
289
-					for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
289
+					for($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
290 290
 #						let t = tmin if k <= bias {+ tmin}, or
291 291
 #								tmax if k >= bias + tmax, or k - bias otherwise
292
-						if ($k <= ($bias + self::BOOTSTRAP_TMIN)) {
292
+						if($k <= ($bias + self::BOOTSTRAP_TMIN)) {
293 293
 							$t = self::BOOTSTRAP_TMIN;
294 294
 						}
295
-						elseif ($k >= ($bias + self::BOOTSTRAP_TMAX)) {
295
+						elseif($k >= ($bias + self::BOOTSTRAP_TMAX)) {
296 296
 							$t = self::BOOTSTRAP_TMAX;
297 297
 						}
298 298
 						else {
299 299
 							$t = $k - $bias;
300 300
 						}
301 301
 #						if q < t then break
302
-						if ($q < $t) {
302
+						if($q < $t) {
303 303
 							break;
304 304
 						}
305 305
 #						output the code point for digit t + ((q - t) mod (base - t))
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	protected static function digit_to_char($digit) {
343 343
 		// @codeCoverageIgnoreStart
344 344
 		// As far as I know, this never happens, but still good to be sure.
345
-		if ($digit < 0 || $digit > 35) {
345
+		if($digit < 0 || $digit > 35) {
346 346
 			throw new Requests_Exception(sprintf('Invalid digit %d', $digit), 'idna.invalid_digit', $digit);
347 347
 		}
348 348
 		// @codeCoverageIgnoreEnd
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	protected static function adapt($delta, $numpoints, $firsttime) {
363 363
 #	function adapt(delta,numpoints,firsttime):
364 364
 #		if firsttime then let delta = delta div damp
365
-		if ($firsttime) {
365
+		if($firsttime) {
366 366
 			$delta = floor($delta / self::BOOTSTRAP_DAMP);
367 367
 		}
368 368
 #		else let delta = delta div 2
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 		$k = 0;
376 376
 #		while delta > ((base - tmin) * tmax) div 2 do begin
377 377
 		$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
378
-		while ($delta > $max) {
378
+		while($delta > $max) {
379 379
 #			let delta = delta div (base - tmin)
380 380
 			$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
381 381
 #			let k = k + base
Please login to merge, or discard this 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.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -254,7 +254,7 @@
 block discarded – undo
254 254
 			}
255 255
 			// @codeCoverageIgnoreEnd
256 256
 			else {
257
-				$extended[$char] = true;
257
+				$extended[$char] = TRUE;
258 258
 			}
259 259
 		}
260 260
 		$extended = array_keys($extended);
Please login to merge, or discard this patch.
php/Requests/libary/Requests/IRI.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 *
250 250
 	 * Returns false if $base is not absolute, otherwise an IRI.
251 251
 	 *
252
-	 * @param IRI|string $base (Absolute) Base IRI
252
+	 * @param string $base (Absolute) Base IRI
253 253
 	 * @param IRI|string $relative Relative IRI
254 254
 	 * @return IRI|false
255 255
 	 */
@@ -984,6 +984,7 @@  discard block
 block discarded – undo
984 984
 	 * Convert an IRI to a URI (or parts thereof)
985 985
 	 *
986 986
 	 * @param string|bool IRI to convert (or false from {@see get_iri})
987
+	 * @param false|string $string
987 988
 	 * @return string|false URI if IRI is valid, false otherwise.
988 989
 	 */
989 990
 	protected function to_uri($string) {
Please login to merge, or discard this patch.
Spacing   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	 * @param mixed $value Property value
154 154
 	 */
155 155
 	public function __set($name, $value) {
156
-		if (method_exists($this, 'set_' . $name)) {
156
+		if(method_exists($this, 'set_' . $name)) {
157 157
 			call_user_func(array($this, 'set_' . $name), $value);
158 158
 		}
159
-		elseif (
159
+		elseif(
160 160
 			   $name === 'iauthority'
161 161
 			|| $name === 'iuserinfo'
162 162
 			|| $name === 'ihost'
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		// Also why we use array_key_exists below instead of isset()
180 180
 		$props = get_object_vars($this);
181 181
 
182
-		if (
182
+		if(
183 183
 			$name === 'iri' ||
184 184
 			$name === 'uri' ||
185 185
 			$name === 'iauthority' ||
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 			$method = 'get_' . $name;
189 189
 			$return = $this->$method();
190 190
 		}
191
-		elseif (array_key_exists($name, $props)) {
191
+		elseif(array_key_exists($name, $props)) {
192 192
 			$return = $this->$name;
193 193
 		}
194 194
 		// host -> ihost
195
-		elseif (($prop = 'i' . $name) && array_key_exists($prop, $props)) {
195
+		elseif(($prop = 'i' . $name) && array_key_exists($prop, $props)) {
196 196
 			$name = $prop;
197 197
 			$return = $this->$prop;
198 198
 		}
199 199
 		// ischeme -> scheme
200
-		elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) {
200
+		elseif(($prop = substr($name, 1)) && array_key_exists($prop, $props)) {
201 201
 			$name = $prop;
202 202
 			$return = $this->$prop;
203 203
 		}
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 			$return = null;
207 207
 		}
208 208
 
209
-		if ($return === null && isset($this->normalization[$this->scheme][$name])) {
209
+		if($return === null && isset($this->normalization[$this->scheme][$name])) {
210 210
 			return $this->normalization[$this->scheme][$name];
211 211
 		}
212 212
 		else {
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 * @param string $name Property name
231 231
 	 */
232 232
 	public function __unset($name) {
233
-		if (method_exists($this, 'set_' . $name)) {
233
+		if(method_exists($this, 'set_' . $name)) {
234 234
 			call_user_func(array($this, 'set_' . $name), '');
235 235
 		}
236 236
 	}
@@ -254,25 +254,25 @@  discard block
 block discarded – undo
254 254
 	 * @return IRI|false
255 255
 	 */
256 256
 	public static function absolutize($base, $relative) {
257
-		if (!($relative instanceof Requests_IRI)) {
257
+		if(!($relative instanceof Requests_IRI)) {
258 258
 			$relative = new Requests_IRI($relative);
259 259
 		}
260
-		if (!$relative->is_valid()) {
260
+		if(!$relative->is_valid()) {
261 261
 			return false;
262 262
 		}
263
-		elseif ($relative->scheme !== null) {
263
+		elseif($relative->scheme !== null) {
264 264
 			return clone $relative;
265 265
 		}
266 266
 
267
-		if (!($base instanceof Requests_IRI)) {
267
+		if(!($base instanceof Requests_IRI)) {
268 268
 			$base = new Requests_IRI($base);
269 269
 		}
270
-		if ($base->scheme === null || !$base->is_valid()) {
270
+		if($base->scheme === null || !$base->is_valid()) {
271 271
 			return false;
272 272
 		}
273 273
 
274
-		if ($relative->get_iri() !== '') {
275
-			if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
274
+		if($relative->get_iri() !== '') {
275
+			if($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
276 276
 				$target = clone $relative;
277 277
 				$target->scheme = $base->scheme;
278 278
 			}
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
 				$target->iuserinfo = $base->iuserinfo;
283 283
 				$target->ihost = $base->ihost;
284 284
 				$target->port = $base->port;
285
-				if ($relative->ipath !== '') {
286
-					if ($relative->ipath[0] === '/') {
285
+				if($relative->ipath !== '') {
286
+					if($relative->ipath[0] === '/') {
287 287
 						$target->ipath = $relative->ipath;
288 288
 					}
289
-					elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
289
+					elseif(($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
290 290
 						$target->ipath = '/' . $relative->ipath;
291 291
 					}
292
-					elseif (($last_segment = strrpos($base->ipath, '/')) !== false) {
292
+					elseif(($last_segment = strrpos($base->ipath, '/')) !== false) {
293 293
 						$target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
294 294
 					}
295 295
 					else {
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
 				}
301 301
 				else {
302 302
 					$target->ipath = $base->ipath;
303
-					if ($relative->iquery !== null) {
303
+					if($relative->iquery !== null) {
304 304
 						$target->iquery = $relative->iquery;
305 305
 					}
306
-					elseif ($base->iquery !== null) {
306
+					elseif($base->iquery !== null) {
307 307
 						$target->iquery = $base->iquery;
308 308
 					}
309 309
 				}
@@ -327,23 +327,23 @@  discard block
 block discarded – undo
327 327
 	protected function parse_iri($iri) {
328 328
 		$iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
329 329
 		$has_match = preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match);
330
-		if (!$has_match) {
330
+		if(!$has_match) {
331 331
 			throw new Requests_Exception('Cannot parse supplied IRI', 'iri.cannot_parse', $iri);
332 332
 		}
333 333
 
334
-		if ($match[1] === '') {
334
+		if($match[1] === '') {
335 335
 			$match['scheme'] = null;
336 336
 		}
337
-		if (!isset($match[3]) || $match[3] === '') {
337
+		if(!isset($match[3]) || $match[3] === '') {
338 338
 			$match['authority'] = null;
339 339
 		}
340
-		if (!isset($match[5])) {
340
+		if(!isset($match[5])) {
341 341
 			$match['path'] = '';
342 342
 		}
343
-		if (!isset($match[6]) || $match[6] === '') {
343
+		if(!isset($match[6]) || $match[6] === '') {
344 344
 			$match['query'] = null;
345 345
 		}
346
-		if (!isset($match[8]) || $match[8] === '') {
346
+		if(!isset($match[8]) || $match[8] === '') {
347 347
 			$match['fragment'] = null;
348 348
 		}
349 349
 		return $match;
@@ -357,46 +357,46 @@  discard block
 block discarded – undo
357 357
 	 */
358 358
 	protected function remove_dot_segments($input) {
359 359
 		$output = '';
360
-		while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
360
+		while(strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
361 361
 			// A: If the input buffer begins with a prefix of "../" or "./",
362 362
 			// then remove that prefix from the input buffer; otherwise,
363
-			if (strpos($input, '../') === 0) {
363
+			if(strpos($input, '../') === 0) {
364 364
 				$input = substr($input, 3);
365 365
 			}
366
-			elseif (strpos($input, './') === 0) {
366
+			elseif(strpos($input, './') === 0) {
367 367
 				$input = substr($input, 2);
368 368
 			}
369 369
 			// B: if the input buffer begins with a prefix of "/./" or "/.",
370 370
 			// where "." is a complete path segment, then replace that prefix
371 371
 			// with "/" in the input buffer; otherwise,
372
-			elseif (strpos($input, '/./') === 0) {
372
+			elseif(strpos($input, '/./') === 0) {
373 373
 				$input = substr($input, 2);
374 374
 			}
375
-			elseif ($input === '/.') {
375
+			elseif($input === '/.') {
376 376
 				$input = '/';
377 377
 			}
378 378
 			// C: if the input buffer begins with a prefix of "/../" or "/..",
379 379
 			// where ".." is a complete path segment, then replace that prefix
380 380
 			// with "/" in the input buffer and remove the last segment and its
381 381
 			// preceding "/" (if any) from the output buffer; otherwise,
382
-			elseif (strpos($input, '/../') === 0) {
382
+			elseif(strpos($input, '/../') === 0) {
383 383
 				$input = substr($input, 3);
384 384
 				$output = substr_replace($output, '', strrpos($output, '/'));
385 385
 			}
386
-			elseif ($input === '/..') {
386
+			elseif($input === '/..') {
387 387
 				$input = '/';
388 388
 				$output = substr_replace($output, '', strrpos($output, '/'));
389 389
 			}
390 390
 			// D: if the input buffer consists only of "." or "..", then remove
391 391
 			// that from the input buffer; otherwise,
392
-			elseif ($input === '.' || $input === '..') {
392
+			elseif($input === '.' || $input === '..') {
393 393
 				$input = '';
394 394
 			}
395 395
 			// E: move the first path segment in the input buffer to the end of
396 396
 			// the output buffer, including the initial "/" character (if any)
397 397
 			// and any subsequent characters up to, but not including, the next
398 398
 			// "/" character or the end of the input buffer
399
-			elseif (($pos = strpos($input, '/', 1)) !== false) {
399
+			elseif(($pos = strpos($input, '/', 1)) !== false) {
400 400
 				$output .= substr($input, 0, $pos);
401 401
 				$input = substr_replace($input, '', 0, $pos);
402 402
 			}
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 		// Now replace any bytes that aren't allowed with their pct-encoded versions
432 432
 		$position = 0;
433 433
 		$strlen = strlen($string);
434
-		while (($position += strspn($string, $extra_chars, $position)) < $strlen) {
434
+		while(($position += strspn($string, $extra_chars, $position)) < $strlen) {
435 435
 			$value = ord($string[$position]);
436 436
 
437 437
 			// Start position
@@ -442,20 +442,20 @@  discard block
 block discarded – undo
442 442
 
443 443
 			// No one byte sequences are valid due to the while.
444 444
 			// Two byte sequence:
445
-			if (($value & 0xE0) === 0xC0) {
446
-				$character = ($value & 0x1F) << 6;
445
+			if(($value&0xE0) === 0xC0) {
446
+				$character = ($value&0x1F) << 6;
447 447
 				$length = 2;
448 448
 				$remaining = 1;
449 449
 			}
450 450
 			// Three byte sequence:
451
-			elseif (($value & 0xF0) === 0xE0) {
452
-				$character = ($value & 0x0F) << 12;
451
+			elseif(($value&0xF0) === 0xE0) {
452
+				$character = ($value&0x0F) << 12;
453 453
 				$length = 3;
454 454
 				$remaining = 2;
455 455
 			}
456 456
 			// Four byte sequence:
457
-			elseif (($value & 0xF8) === 0xF0) {
458
-				$character = ($value & 0x07) << 18;
457
+			elseif(($value&0xF8) === 0xF0) {
458
+				$character = ($value&0x07) << 18;
459 459
 				$length = 4;
460 460
 				$remaining = 3;
461 461
 			}
@@ -466,14 +466,14 @@  discard block
 block discarded – undo
466 466
 				$remaining = 0;
467 467
 			}
468 468
 
469
-			if ($remaining) {
470
-				if ($position + $length <= $strlen) {
471
-					for ($position++; $remaining; $position++) {
469
+			if($remaining) {
470
+				if($position + $length <= $strlen) {
471
+					for($position++; $remaining; $position++) {
472 472
 						$value = ord($string[$position]);
473 473
 
474 474
 						// Check that the byte is valid, then add it to the character:
475
-						if (($value & 0xC0) === 0x80) {
476
-							$character |= ($value & 0x3F) << (--$remaining * 6);
475
+						if(($value&0xC0) === 0x80) {
476
+							$character |= ($value&0x3F) << (--$remaining * 6);
477 477
 						}
478 478
 						// If it is invalid, count the sequence as invalid and reprocess the current byte:
479 479
 						else {
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 			}
491 491
 
492 492
 			// Percent encode anything invalid or not in ucschar
493
-			if (
493
+			if(
494 494
 				// Invalid sequences
495 495
 				!$valid
496 496
 				// Non-shortest form sequences are invalid
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 				|| $length > 3 && $character <= 0xFFFF
500 500
 				// Outside of range of ucschar codepoints
501 501
 				// Noncharacters
502
-				|| ($character & 0xFFFE) === 0xFFFE
502
+				|| ($character&0xFFFE) === 0xFFFE
503 503
 				|| $character >= 0xFDD0 && $character <= 0xFDEF
504 504
 				|| (
505 505
 					// Everything else not in ucschar
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
 				)
516 516
 			) {
517 517
 				// If we were a character, pretend we weren't, but rather an error.
518
-				if ($valid) {
518
+				if($valid) {
519 519
 					$position--;
520 520
 				}
521 521
 
522
-				for ($j = $start; $j <= $position; $j++) {
522
+				for($j = $start; $j <= $position; $j++) {
523 523
 					$string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
524 524
 					$j += 2;
525 525
 					$position += 2;
@@ -552,11 +552,11 @@  discard block
 block discarded – undo
552 552
 		$remaining = 0;
553 553
 
554 554
 		// Loop over each and every byte, and set $value to its value
555
-		for ($i = 1, $len = count($bytes); $i < $len; $i++) {
555
+		for($i = 1, $len = count($bytes); $i < $len; $i++) {
556 556
 			$value = hexdec($bytes[$i]);
557 557
 
558 558
 			// If we're the first byte of sequence:
559
-			if (!$remaining) {
559
+			if(!$remaining) {
560 560
 				// Start position
561 561
 				$start = $i;
562 562
 
@@ -564,25 +564,25 @@  discard block
 block discarded – undo
564 564
 				$valid = true;
565 565
 
566 566
 				// One byte sequence:
567
-				if ($value <= 0x7F) {
567
+				if($value <= 0x7F) {
568 568
 					$character = $value;
569 569
 					$length = 1;
570 570
 				}
571 571
 				// Two byte sequence:
572
-				elseif (($value & 0xE0) === 0xC0) {
573
-					$character = ($value & 0x1F) << 6;
572
+				elseif(($value&0xE0) === 0xC0) {
573
+					$character = ($value&0x1F) << 6;
574 574
 					$length = 2;
575 575
 					$remaining = 1;
576 576
 				}
577 577
 				// Three byte sequence:
578
-				elseif (($value & 0xF0) === 0xE0) {
579
-					$character = ($value & 0x0F) << 12;
578
+				elseif(($value&0xF0) === 0xE0) {
579
+					$character = ($value&0x0F) << 12;
580 580
 					$length = 3;
581 581
 					$remaining = 2;
582 582
 				}
583 583
 				// Four byte sequence:
584
-				elseif (($value & 0xF8) === 0xF0) {
585
-					$character = ($value & 0x07) << 18;
584
+				elseif(($value&0xF8) === 0xF0) {
585
+					$character = ($value&0x07) << 18;
586 586
 					$length = 4;
587 587
 					$remaining = 3;
588 588
 				}
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 			// Continuation byte:
596 596
 			else {
597 597
 				// Check that the byte is valid, then add it to the character:
598
-				if (($value & 0xC0) === 0x80) {
598
+				if(($value&0xC0) === 0x80) {
599 599
 					$remaining--;
600
-					$character |= ($value & 0x3F) << ($remaining * 6);
600
+					$character |= ($value&0x3F) << ($remaining * 6);
601 601
 				}
602 602
 				// If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
603 603
 				else {
@@ -608,9 +608,9 @@  discard block
 block discarded – undo
608 608
 			}
609 609
 
610 610
 			// If we've reached the end of the current byte sequence, append it to Unicode::$data
611
-			if (!$remaining) {
611
+			if(!$remaining) {
612 612
 				// Percent encode anything invalid or not in iunreserved
613
-				if (
613
+				if(
614 614
 					// Invalid sequences
615 615
 					!$valid
616 616
 					// Non-shortest form sequences are invalid
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 					|| $character < 0x2D
622 622
 					|| $character > 0xEFFFD
623 623
 					// Noncharacters
624
-					|| ($character & 0xFFFE) === 0xFFFE
624
+					|| ($character&0xFFFE) === 0xFFFE
625 625
 					|| $character >= 0xFDD0 && $character <= 0xFDEF
626 626
 					// Everything else not in iunreserved (this is all BMP)
627 627
 					|| $character === 0x2F
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
 					|| $character > 0x7E && $character < 0xA0
632 632
 					|| $character > 0xD7FF && $character < 0xF900
633 633
 				) {
634
-					for ($j = $start; $j <= $i; $j++) {
634
+					for($j = $start; $j <= $i; $j++) {
635 635
 						$string .= '%' . strtoupper($bytes[$j]);
636 636
 					}
637 637
 				}
638 638
 				else {
639
-					for ($j = $start; $j <= $i; $j++) {
639
+					for($j = $start; $j <= $i; $j++) {
640 640
 						$string .= chr(hexdec($bytes[$j]));
641 641
 					}
642 642
 				}
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
 
646 646
 		// If we have any bytes left over they are invalid (i.e., we are
647 647
 		// mid-way through a multi-byte sequence)
648
-		if ($remaining) {
649
-			for ($j = $start; $j < $len; $j++) {
648
+		if($remaining) {
649
+			for($j = $start; $j < $len; $j++) {
650 650
 				$string .= '%' . strtoupper($bytes[$j]);
651 651
 			}
652 652
 		}
@@ -655,25 +655,25 @@  discard block
 block discarded – undo
655 655
 	}
656 656
 
657 657
 	protected function scheme_normalization() {
658
-		if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
658
+		if(isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
659 659
 			$this->iuserinfo = null;
660 660
 		}
661
-		if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
661
+		if(isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
662 662
 			$this->ihost = null;
663 663
 		}
664
-		if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
664
+		if(isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
665 665
 			$this->port = null;
666 666
 		}
667
-		if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
667
+		if(isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
668 668
 			$this->ipath = '';
669 669
 		}
670
-		if (isset($this->ihost) && empty($this->ipath)) {
670
+		if(isset($this->ihost) && empty($this->ipath)) {
671 671
 			$this->ipath = '/';
672 672
 		}
673
-		if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
673
+		if(isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
674 674
 			$this->iquery = null;
675 675
 		}
676
-		if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
676
+		if(isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
677 677
 			$this->ifragment = null;
678 678
 		}
679 679
 	}
@@ -686,14 +686,14 @@  discard block
 block discarded – undo
686 686
 	 */
687 687
 	public function is_valid() {
688 688
 		$isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
689
-		if ($this->ipath !== '' &&
689
+		if($this->ipath !== '' &&
690 690
 			(
691 691
 				$isauthority && $this->ipath[0] !== '/' ||
692 692
 				(
693 693
 					$this->scheme === null &&
694 694
 					!$isauthority &&
695 695
 					strpos($this->ipath, ':') !== false &&
696
-					(strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
696
+					(strpos($this->ipath, '/') === false?true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
697 697
 				)
698 698
 			)
699 699
 		) {
@@ -712,14 +712,14 @@  discard block
 block discarded – undo
712 712
 	 */
713 713
 	protected function set_iri($iri) {
714 714
 		static $cache;
715
-		if (!$cache) {
715
+		if(!$cache) {
716 716
 			$cache = array();
717 717
 		}
718 718
 
719
-		if ($iri === null) {
719
+		if($iri === null) {
720 720
 			return true;
721 721
 		}
722
-		if (isset($cache[$iri])) {
722
+		if(isset($cache[$iri])) {
723 723
 			list($this->scheme,
724 724
 				 $this->iuserinfo,
725 725
 				 $this->ihost,
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 			return $return;
732 732
 		}
733 733
 
734
-		$parsed = $this->parse_iri((string) $iri);
734
+		$parsed = $this->parse_iri((string)$iri);
735 735
 
736 736
 		$return = $this->set_scheme($parsed['scheme'])
737 737
 			&& $this->set_authority($parsed['authority'])
@@ -758,10 +758,10 @@  discard block
 block discarded – undo
758 758
 	 * @return bool
759 759
 	 */
760 760
 	protected function set_scheme($scheme) {
761
-		if ($scheme === null) {
761
+		if($scheme === null) {
762 762
 			$this->scheme = null;
763 763
 		}
764
-		elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
764
+		elseif(!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
765 765
 			$this->scheme = null;
766 766
 			return false;
767 767
 		}
@@ -780,17 +780,17 @@  discard block
 block discarded – undo
780 780
 	 */
781 781
 	protected function set_authority($authority) {
782 782
 		static $cache;
783
-		if (!$cache) {
783
+		if(!$cache) {
784 784
 			$cache = array();
785 785
 		}
786 786
 
787
-		if ($authority === null) {
787
+		if($authority === null) {
788 788
 			$this->iuserinfo = null;
789 789
 			$this->ihost = null;
790 790
 			$this->port = null;
791 791
 			return true;
792 792
 		}
793
-		if (isset($cache[$authority])) {
793
+		if(isset($cache[$authority])) {
794 794
 			list($this->iuserinfo,
795 795
 				 $this->ihost,
796 796
 				 $this->port,
@@ -800,16 +800,16 @@  discard block
 block discarded – undo
800 800
 		}
801 801
 
802 802
 		$remaining = $authority;
803
-		if (($iuserinfo_end = strrpos($remaining, '@')) !== false) {
803
+		if(($iuserinfo_end = strrpos($remaining, '@')) !== false) {
804 804
 			$iuserinfo = substr($remaining, 0, $iuserinfo_end);
805 805
 			$remaining = substr($remaining, $iuserinfo_end + 1);
806 806
 		}
807 807
 		else {
808 808
 			$iuserinfo = null;
809 809
 		}
810
-		if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
810
+		if(($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
811 811
 			$port = substr($remaining, $port_start + 1);
812
-			if ($port === false || $port === '') {
812
+			if($port === false || $port === '') {
813 813
 				$port = null;
814 814
 			}
815 815
 			$remaining = substr($remaining, 0, $port_start);
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 	 * @return bool
838 838
 	 */
839 839
 	protected function set_userinfo($iuserinfo) {
840
-		if ($iuserinfo === null) {
840
+		if($iuserinfo === null) {
841 841
 			$this->iuserinfo = null;
842 842
 		}
843 843
 		else {
@@ -856,12 +856,12 @@  discard block
 block discarded – undo
856 856
 	 * @return bool
857 857
 	 */
858 858
 	protected function set_host($ihost) {
859
-		if ($ihost === null) {
859
+		if($ihost === null) {
860 860
 			$this->ihost = null;
861 861
 			return true;
862 862
 		}
863
-		if (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
864
-			if (Requests_IPv6::check_ipv6(substr($ihost, 1, -1))) {
863
+		if(substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
864
+			if(Requests_IPv6::check_ipv6(substr($ihost, 1, -1))) {
865 865
 				$this->ihost = '[' . Requests_IPv6::compress(substr($ihost, 1, -1)) . ']';
866 866
 			}
867 867
 			else {
@@ -877,8 +877,8 @@  discard block
 block discarded – undo
877 877
 			// as that can add unescaped characters.
878 878
 			$position = 0;
879 879
 			$strlen = strlen($ihost);
880
-			while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) {
881
-				if ($ihost[$position] === '%') {
880
+			while(($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) {
881
+				if($ihost[$position] === '%') {
882 882
 					$position += 3;
883 883
 				}
884 884
 				else {
@@ -903,13 +903,13 @@  discard block
 block discarded – undo
903 903
 	 * @return bool
904 904
 	 */
905 905
 	protected function set_port($port) {
906
-		if ($port === null) {
906
+		if($port === null) {
907 907
 			$this->port = null;
908 908
 			return true;
909 909
 		}
910 910
 
911
-		if (strspn($port, '0123456789') === strlen($port)) {
912
-			$this->port = (int) $port;
911
+		if(strspn($port, '0123456789') === strlen($port)) {
912
+			$this->port = (int)$port;
913 913
 			$this->scheme_normalization();
914 914
 			return true;
915 915
 		}
@@ -926,21 +926,21 @@  discard block
 block discarded – undo
926 926
 	 */
927 927
 	protected function set_path($ipath) {
928 928
 		static $cache;
929
-		if (!$cache) {
929
+		if(!$cache) {
930 930
 			$cache = array();
931 931
 		}
932 932
 
933
-		$ipath = (string) $ipath;
933
+		$ipath = (string)$ipath;
934 934
 
935
-		if (isset($cache[$ipath])) {
936
-			$this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
935
+		if(isset($cache[$ipath])) {
936
+			$this->ipath = $cache[$ipath][(int)($this->scheme !== null)];
937 937
 		}
938 938
 		else {
939 939
 			$valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
940 940
 			$removed = $this->remove_dot_segments($valid);
941 941
 
942 942
 			$cache[$ipath] = array($valid, $removed);
943
-			$this->ipath = ($this->scheme !== null) ? $removed : $valid;
943
+			$this->ipath = ($this->scheme !== null)?$removed : $valid;
944 944
 		}
945 945
 		$this->scheme_normalization();
946 946
 		return true;
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 	 * @return bool
954 954
 	 */
955 955
 	protected function set_query($iquery) {
956
-		if ($iquery === null) {
956
+		if($iquery === null) {
957 957
 			$this->iquery = null;
958 958
 		}
959 959
 		else {
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
 	 * @return bool
971 971
 	 */
972 972
 	protected function set_fragment($ifragment) {
973
-		if ($ifragment === null) {
973
+		if($ifragment === null) {
974 974
 			$this->ifragment = null;
975 975
 		}
976 976
 		else {
@@ -987,18 +987,18 @@  discard block
 block discarded – undo
987 987
 	 * @return string|false URI if IRI is valid, false otherwise.
988 988
 	 */
989 989
 	protected function to_uri($string) {
990
-		if (!is_string($string)) {
990
+		if(!is_string($string)) {
991 991
 			return false;
992 992
 		}
993 993
 
994 994
 		static $non_ascii;
995
-		if (!$non_ascii) {
995
+		if(!$non_ascii) {
996 996
 			$non_ascii = implode('', range("\x80", "\xFF"));
997 997
 		}
998 998
 
999 999
 		$position = 0;
1000 1000
 		$strlen = strlen($string);
1001
-		while (($position += strcspn($string, $non_ascii, $position)) < $strlen) {
1001
+		while(($position += strcspn($string, $non_ascii, $position)) < $strlen) {
1002 1002
 			$string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
1003 1003
 			$position += 3;
1004 1004
 			$strlen += 2;
@@ -1013,22 +1013,22 @@  discard block
 block discarded – undo
1013 1013
 	 * @return string
1014 1014
 	 */
1015 1015
 	protected function get_iri() {
1016
-		if (!$this->is_valid()) {
1016
+		if(!$this->is_valid()) {
1017 1017
 			return false;
1018 1018
 		}
1019 1019
 
1020 1020
 		$iri = '';
1021
-		if ($this->scheme !== null) {
1021
+		if($this->scheme !== null) {
1022 1022
 			$iri .= $this->scheme . ':';
1023 1023
 		}
1024
-		if (($iauthority = $this->get_iauthority()) !== null) {
1024
+		if(($iauthority = $this->get_iauthority()) !== null) {
1025 1025
 			$iri .= '//' . $iauthority;
1026 1026
 		}
1027 1027
 		$iri .= $this->ipath;
1028
-		if ($this->iquery !== null) {
1028
+		if($this->iquery !== null) {
1029 1029
 			$iri .= '?' . $this->iquery;
1030 1030
 		}
1031
-		if ($this->ifragment !== null) {
1031
+		if($this->ifragment !== null) {
1032 1032
 			$iri .= '#' . $this->ifragment;
1033 1033
 		}
1034 1034
 
@@ -1050,18 +1050,18 @@  discard block
 block discarded – undo
1050 1050
 	 * @return string
1051 1051
 	 */
1052 1052
 	protected function get_iauthority() {
1053
-		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
1053
+		if($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
1054 1054
 			return null;
1055 1055
 		}
1056 1056
 
1057 1057
 		$iauthority = '';
1058
-		if ($this->iuserinfo !== null) {
1058
+		if($this->iuserinfo !== null) {
1059 1059
 			$iauthority .= $this->iuserinfo . '@';
1060 1060
 		}
1061
-		if ($this->ihost !== null) {
1061
+		if($this->ihost !== null) {
1062 1062
 			$iauthority .= $this->ihost;
1063 1063
 		}
1064
-		if ($this->port !== null) {
1064
+		if($this->port !== null) {
1065 1065
 			$iauthority .= ':' . $this->port;
1066 1066
 		}
1067 1067
 		return $iauthority;
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 	 */
1075 1075
 	protected function get_authority() {
1076 1076
 		$iauthority = $this->get_iauthority();
1077
-		if (is_string($iauthority)) {
1077
+		if(is_string($iauthority)) {
1078 1078
 			return $this->to_uri($iauthority);
1079 1079
 		}
1080 1080
 		else {
Please login to merge, or discard this patch.
Braces   +304 added lines, -152 removed lines patch added patch discarded remove patch
@@ -63,7 +63,8 @@  discard block
 block discarded – undo
63 63
  * @property string $fragment Fragment, formatted for a URI (after '#')
64 64
  * @property string $ifragment Fragment part of the IRI (after '#')
65 65
  */
66
-class Requests_IRI {
66
+class Requests_IRI
67
+{
67 68
 	/**
68 69
 	 * Scheme
69 70
 	 *
@@ -142,7 +143,8 @@  discard block
 block discarded – undo
142 143
 	 *
143 144
 	 * @return string
144 145
 	 */
145
-	public function __toString() {
146
+	public function __toString()
147
+	{
146 148
 		return $this->get_iri();
147 149
 	}
148 150
 
@@ -152,8 +154,10 @@  discard block
 block discarded – undo
152 154
 	 * @param string $name Property name
153 155
 	 * @param mixed $value Property value
154 156
 	 */
155
-	public function __set($name, $value) {
156
-		if (method_exists($this, 'set_' . $name)) {
157
+	public function __set($name, $value)
158
+	{
159
+		if (method_exists($this, 'set_' . $name))
160
+		{
157 161
 			call_user_func(array($this, 'set_' . $name), $value);
158 162
 		}
159 163
 		elseif (
@@ -174,7 +178,8 @@  discard block
 block discarded – undo
174 178
 	 * @param string $name Property name
175 179
 	 * @return mixed
176 180
 	 */
177
-	public function __get($name) {
181
+	public function __get($name)
182
+	{
178 183
 		// isset() returns false for null, we don't want to do that
179 184
 		// Also why we use array_key_exists below instead of isset()
180 185
 		$props = get_object_vars($this);
@@ -188,28 +193,34 @@  discard block
 block discarded – undo
188 193
 			$method = 'get_' . $name;
189 194
 			$return = $this->$method();
190 195
 		}
191
-		elseif (array_key_exists($name, $props)) {
196
+		elseif (array_key_exists($name, $props))
197
+		{
192 198
 			$return = $this->$name;
193 199
 		}
194 200
 		// host -> ihost
195
-		elseif (($prop = 'i' . $name) && array_key_exists($prop, $props)) {
201
+		elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
202
+		{
196 203
 			$name = $prop;
197 204
 			$return = $this->$prop;
198 205
 		}
199 206
 		// ischeme -> scheme
200
-		elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) {
207
+		elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
208
+		{
201 209
 			$name = $prop;
202 210
 			$return = $this->$prop;
203 211
 		}
204
-		else {
212
+		else
213
+		{
205 214
 			trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
206 215
 			$return = null;
207 216
 		}
208 217
 
209
-		if ($return === null && isset($this->normalization[$this->scheme][$name])) {
218
+		if ($return === null && isset($this->normalization[$this->scheme][$name]))
219
+		{
210 220
 			return $this->normalization[$this->scheme][$name];
211 221
 		}
212
-		else {
222
+		else
223
+		{
213 224
 			return $return;
214 225
 		}
215 226
 	}
@@ -220,7 +231,8 @@  discard block
 block discarded – undo
220 231
 	 * @param string $name Property name
221 232
 	 * @return bool
222 233
 	 */
223
-	public function __isset($name) {
234
+	public function __isset($name)
235
+	{
224 236
 		return (method_exists($this, 'get_' . $name) || isset($this->$name));
225 237
 	}
226 238
 
@@ -229,8 +241,10 @@  discard block
 block discarded – undo
229 241
 	 *
230 242
 	 * @param string $name Property name
231 243
 	 */
232
-	public function __unset($name) {
233
-		if (method_exists($this, 'set_' . $name)) {
244
+	public function __unset($name)
245
+	{
246
+		if (method_exists($this, 'set_' . $name))
247
+		{
234 248
 			call_user_func(array($this, 'set_' . $name), '');
235 249
 		}
236 250
 	}
@@ -240,7 +254,8 @@  discard block
 block discarded – undo
240 254
 	 *
241 255
 	 * @param string|null $iri
242 256
 	 */
243
-	public function __construct($iri = null) {
257
+	public function __construct($iri = null)
258
+	{
244 259
 		$this->set_iri($iri);
245 260
 	}
246 261
 
@@ -253,64 +268,82 @@  discard block
 block discarded – undo
253 268
 	 * @param IRI|string $relative Relative IRI
254 269
 	 * @return IRI|false
255 270
 	 */
256
-	public static function absolutize($base, $relative) {
257
-		if (!($relative instanceof Requests_IRI)) {
271
+	public static function absolutize($base, $relative)
272
+	{
273
+		if (!($relative instanceof Requests_IRI))
274
+		{
258 275
 			$relative = new Requests_IRI($relative);
259 276
 		}
260
-		if (!$relative->is_valid()) {
277
+		if (!$relative->is_valid())
278
+		{
261 279
 			return false;
262 280
 		}
263
-		elseif ($relative->scheme !== null) {
281
+		elseif ($relative->scheme !== null)
282
+		{
264 283
 			return clone $relative;
265 284
 		}
266 285
 
267
-		if (!($base instanceof Requests_IRI)) {
286
+		if (!($base instanceof Requests_IRI))
287
+		{
268 288
 			$base = new Requests_IRI($base);
269 289
 		}
270
-		if ($base->scheme === null || !$base->is_valid()) {
290
+		if ($base->scheme === null || !$base->is_valid())
291
+		{
271 292
 			return false;
272 293
 		}
273 294
 
274
-		if ($relative->get_iri() !== '') {
275
-			if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
295
+		if ($relative->get_iri() !== '')
296
+		{
297
+			if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
298
+			{
276 299
 				$target = clone $relative;
277 300
 				$target->scheme = $base->scheme;
278 301
 			}
279
-			else {
302
+			else
303
+			{
280 304
 				$target = new Requests_IRI;
281 305
 				$target->scheme = $base->scheme;
282 306
 				$target->iuserinfo = $base->iuserinfo;
283 307
 				$target->ihost = $base->ihost;
284 308
 				$target->port = $base->port;
285
-				if ($relative->ipath !== '') {
286
-					if ($relative->ipath[0] === '/') {
309
+				if ($relative->ipath !== '')
310
+				{
311
+					if ($relative->ipath[0] === '/')
312
+					{
287 313
 						$target->ipath = $relative->ipath;
288 314
 					}
289
-					elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
315
+					elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
316
+					{
290 317
 						$target->ipath = '/' . $relative->ipath;
291 318
 					}
292
-					elseif (($last_segment = strrpos($base->ipath, '/')) !== false) {
319
+					elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
320
+					{
293 321
 						$target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
294 322
 					}
295
-					else {
323
+					else
324
+					{
296 325
 						$target->ipath = $relative->ipath;
297 326
 					}
298 327
 					$target->ipath = $target->remove_dot_segments($target->ipath);
299 328
 					$target->iquery = $relative->iquery;
300 329
 				}
301
-				else {
330
+				else
331
+				{
302 332
 					$target->ipath = $base->ipath;
303
-					if ($relative->iquery !== null) {
333
+					if ($relative->iquery !== null)
334
+					{
304 335
 						$target->iquery = $relative->iquery;
305 336
 					}
306
-					elseif ($base->iquery !== null) {
337
+					elseif ($base->iquery !== null)
338
+					{
307 339
 						$target->iquery = $base->iquery;
308 340
 					}
309 341
 				}
310 342
 				$target->ifragment = $relative->ifragment;
311 343
 			}
312 344
 		}
313
-		else {
345
+		else
346
+		{
314 347
 			$target = clone $base;
315 348
 			$target->ifragment = null;
316 349
 		}
@@ -324,26 +357,33 @@  discard block
 block discarded – undo
324 357
 	 * @param string $iri
325 358
 	 * @return array
326 359
 	 */
327
-	protected function parse_iri($iri) {
360
+	protected function parse_iri($iri)
361
+	{
328 362
 		$iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
329 363
 		$has_match = preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match);
330
-		if (!$has_match) {
364
+		if (!$has_match)
365
+		{
331 366
 			throw new Requests_Exception('Cannot parse supplied IRI', 'iri.cannot_parse', $iri);
332 367
 		}
333 368
 
334
-		if ($match[1] === '') {
369
+		if ($match[1] === '')
370
+		{
335 371
 			$match['scheme'] = null;
336 372
 		}
337
-		if (!isset($match[3]) || $match[3] === '') {
373
+		if (!isset($match[3]) || $match[3] === '')
374
+		{
338 375
 			$match['authority'] = null;
339 376
 		}
340
-		if (!isset($match[5])) {
377
+		if (!isset($match[5]))
378
+		{
341 379
 			$match['path'] = '';
342 380
 		}
343
-		if (!isset($match[6]) || $match[6] === '') {
381
+		if (!isset($match[6]) || $match[6] === '')
382
+		{
344 383
 			$match['query'] = null;
345 384
 		}
346
-		if (!isset($match[8]) || $match[8] === '') {
385
+		if (!isset($match[8]) || $match[8] === '')
386
+		{
347 387
 			$match['fragment'] = null;
348 388
 		}
349 389
 		return $match;
@@ -355,52 +395,63 @@  discard block
 block discarded – undo
355 395
 	 * @param string $input
356 396
 	 * @return string
357 397
 	 */
358
-	protected function remove_dot_segments($input) {
398
+	protected function remove_dot_segments($input)
399
+	{
359 400
 		$output = '';
360
-		while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
401
+		while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
402
+		{
361 403
 			// A: If the input buffer begins with a prefix of "../" or "./",
362 404
 			// then remove that prefix from the input buffer; otherwise,
363
-			if (strpos($input, '../') === 0) {
405
+			if (strpos($input, '../') === 0)
406
+			{
364 407
 				$input = substr($input, 3);
365 408
 			}
366
-			elseif (strpos($input, './') === 0) {
409
+			elseif (strpos($input, './') === 0)
410
+			{
367 411
 				$input = substr($input, 2);
368 412
 			}
369 413
 			// B: if the input buffer begins with a prefix of "/./" or "/.",
370 414
 			// where "." is a complete path segment, then replace that prefix
371 415
 			// with "/" in the input buffer; otherwise,
372
-			elseif (strpos($input, '/./') === 0) {
416
+			elseif (strpos($input, '/./') === 0)
417
+			{
373 418
 				$input = substr($input, 2);
374 419
 			}
375
-			elseif ($input === '/.') {
420
+			elseif ($input === '/.')
421
+			{
376 422
 				$input = '/';
377 423
 			}
378 424
 			// C: if the input buffer begins with a prefix of "/../" or "/..",
379 425
 			// where ".." is a complete path segment, then replace that prefix
380 426
 			// with "/" in the input buffer and remove the last segment and its
381 427
 			// preceding "/" (if any) from the output buffer; otherwise,
382
-			elseif (strpos($input, '/../') === 0) {
428
+			elseif (strpos($input, '/../') === 0)
429
+			{
383 430
 				$input = substr($input, 3);
384 431
 				$output = substr_replace($output, '', strrpos($output, '/'));
385 432
 			}
386
-			elseif ($input === '/..') {
433
+			elseif ($input === '/..')
434
+			{
387 435
 				$input = '/';
388 436
 				$output = substr_replace($output, '', strrpos($output, '/'));
389 437
 			}
390 438
 			// D: if the input buffer consists only of "." or "..", then remove
391 439
 			// that from the input buffer; otherwise,
392
-			elseif ($input === '.' || $input === '..') {
440
+			elseif ($input === '.' || $input === '..')
441
+			{
393 442
 				$input = '';
394 443
 			}
395 444
 			// E: move the first path segment in the input buffer to the end of
396 445
 			// the output buffer, including the initial "/" character (if any)
397 446
 			// and any subsequent characters up to, but not including, the next
398 447
 			// "/" character or the end of the input buffer
399
-			elseif (($pos = strpos($input, '/', 1)) !== false) {
448
+			elseif (($pos = strpos($input, '/', 1)) !== false)
449
+			{
400 450
 				$output .= substr($input, 0, $pos);
401 451
 				$input = substr_replace($input, '', 0, $pos);
402 452
 			}
403
-			else {
453
+			else
454
+			{
404 455
 				$output .= $input;
405 456
 				$input = '';
406 457
 			}
@@ -417,7 +468,8 @@  discard block
 block discarded – undo
417 468
 	 * @param bool $iprivate Allow iprivate
418 469
 	 * @return string
419 470
 	 */
420
-	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) {
471
+	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
472
+	{
421 473
 		// Normalize as many pct-encoded sections as possible
422 474
 		$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array(&$this, 'remove_iunreserved_percent_encoded'), $string);
423 475
 
@@ -431,7 +483,8 @@  discard block
 block discarded – undo
431 483
 		// Now replace any bytes that aren't allowed with their pct-encoded versions
432 484
 		$position = 0;
433 485
 		$strlen = strlen($string);
434
-		while (($position += strspn($string, $extra_chars, $position)) < $strlen) {
486
+		while (($position += strspn($string, $extra_chars, $position)) < $strlen)
487
+		{
435 488
 			$value = ord($string[$position]);
436 489
 
437 490
 			// Start position
@@ -442,48 +495,58 @@  discard block
 block discarded – undo
442 495
 
443 496
 			// No one byte sequences are valid due to the while.
444 497
 			// Two byte sequence:
445
-			if (($value & 0xE0) === 0xC0) {
498
+			if (($value & 0xE0) === 0xC0)
499
+			{
446 500
 				$character = ($value & 0x1F) << 6;
447 501
 				$length = 2;
448 502
 				$remaining = 1;
449 503
 			}
450 504
 			// Three byte sequence:
451
-			elseif (($value & 0xF0) === 0xE0) {
505
+			elseif (($value & 0xF0) === 0xE0)
506
+			{
452 507
 				$character = ($value & 0x0F) << 12;
453 508
 				$length = 3;
454 509
 				$remaining = 2;
455 510
 			}
456 511
 			// Four byte sequence:
457
-			elseif (($value & 0xF8) === 0xF0) {
512
+			elseif (($value & 0xF8) === 0xF0)
513
+			{
458 514
 				$character = ($value & 0x07) << 18;
459 515
 				$length = 4;
460 516
 				$remaining = 3;
461 517
 			}
462 518
 			// Invalid byte:
463
-			else {
519
+			else
520
+			{
464 521
 				$valid = false;
465 522
 				$length = 1;
466 523
 				$remaining = 0;
467 524
 			}
468 525
 
469
-			if ($remaining) {
470
-				if ($position + $length <= $strlen) {
471
-					for ($position++; $remaining; $position++) {
526
+			if ($remaining)
527
+			{
528
+				if ($position + $length <= $strlen)
529
+				{
530
+					for ($position++; $remaining; $position++)
531
+					{
472 532
 						$value = ord($string[$position]);
473 533
 
474 534
 						// Check that the byte is valid, then add it to the character:
475
-						if (($value & 0xC0) === 0x80) {
535
+						if (($value & 0xC0) === 0x80)
536
+						{
476 537
 							$character |= ($value & 0x3F) << (--$remaining * 6);
477 538
 						}
478 539
 						// If it is invalid, count the sequence as invalid and reprocess the current byte:
479
-						else {
540
+						else
541
+						{
480 542
 							$valid = false;
481 543
 							$position--;
482 544
 							break;
483 545
 						}
484 546
 					}
485 547
 				}
486
-				else {
548
+				else
549
+				{
487 550
 					$position = $strlen - 1;
488 551
 					$valid = false;
489 552
 				}
@@ -515,11 +578,13 @@  discard block
 block discarded – undo
515 578
 				)
516 579
 			) {
517 580
 				// If we were a character, pretend we weren't, but rather an error.
518
-				if ($valid) {
581
+				if ($valid)
582
+				{
519 583
 					$position--;
520 584
 				}
521 585
 
522
-				for ($j = $start; $j <= $position; $j++) {
586
+				for ($j = $start; $j <= $position; $j++)
587
+				{
523 588
 					$string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
524 589
 					$j += 2;
525 590
 					$position += 2;
@@ -540,7 +605,8 @@  discard block
 block discarded – undo
540 605
 	 * @param array $match PCRE match
541 606
 	 * @return string Replacement
542 607
 	 */
543
-	protected function remove_iunreserved_percent_encoded($match) {
608
+	protected function remove_iunreserved_percent_encoded($match)
609
+	{
544 610
 		// As we just have valid percent encoded sequences we can just explode
545 611
 		// and ignore the first member of the returned array (an empty string).
546 612
 		$bytes = explode('%', $match[0]);
@@ -552,11 +618,13 @@  discard block
 block discarded – undo
552 618
 		$remaining = 0;
553 619
 
554 620
 		// Loop over each and every byte, and set $value to its value
555
-		for ($i = 1, $len = count($bytes); $i < $len; $i++) {
621
+		for ($i = 1, $len = count($bytes); $i < $len; $i++)
622
+		{
556 623
 			$value = hexdec($bytes[$i]);
557 624
 
558 625
 			// If we're the first byte of sequence:
559
-			if (!$remaining) {
626
+			if (!$remaining)
627
+			{
560 628
 				// Start position
561 629
 				$start = $i;
562 630
 
@@ -564,43 +632,51 @@  discard block
 block discarded – undo
564 632
 				$valid = true;
565 633
 
566 634
 				// One byte sequence:
567
-				if ($value <= 0x7F) {
635
+				if ($value <= 0x7F)
636
+				{
568 637
 					$character = $value;
569 638
 					$length = 1;
570 639
 				}
571 640
 				// Two byte sequence:
572
-				elseif (($value & 0xE0) === 0xC0) {
641
+				elseif (($value & 0xE0) === 0xC0)
642
+				{
573 643
 					$character = ($value & 0x1F) << 6;
574 644
 					$length = 2;
575 645
 					$remaining = 1;
576 646
 				}
577 647
 				// Three byte sequence:
578
-				elseif (($value & 0xF0) === 0xE0) {
648
+				elseif (($value & 0xF0) === 0xE0)
649
+				{
579 650
 					$character = ($value & 0x0F) << 12;
580 651
 					$length = 3;
581 652
 					$remaining = 2;
582 653
 				}
583 654
 				// Four byte sequence:
584
-				elseif (($value & 0xF8) === 0xF0) {
655
+				elseif (($value & 0xF8) === 0xF0)
656
+				{
585 657
 					$character = ($value & 0x07) << 18;
586 658
 					$length = 4;
587 659
 					$remaining = 3;
588 660
 				}
589 661
 				// Invalid byte:
590
-				else {
662
+				else
663
+				{
591 664
 					$valid = false;
592 665
 					$remaining = 0;
593 666
 				}
594 667
 			}
595 668
 			// Continuation byte:
596
-			else {
669
+			else
670
+			{
597 671
 				// Check that the byte is valid, then add it to the character:
598
-				if (($value & 0xC0) === 0x80) {
672
+				if (($value & 0xC0) === 0x80)
673
+				{
599 674
 					$remaining--;
600 675
 					$character |= ($value & 0x3F) << ($remaining * 6);
601 676
 				}
602 677
 				// If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
603
-				else {
678
+				else
679
+				{
604 680
 					$valid = false;
605 681
 					$remaining = 0;
606 682
 					$i--;
@@ -608,7 +684,8 @@  discard block
 block discarded – undo
608 684
 			}
609 685
 
610 686
 			// If we've reached the end of the current byte sequence, append it to Unicode::$data
611
-			if (!$remaining) {
687
+			if (!$remaining)
688
+			{
612 689
 				// Percent encode anything invalid or not in iunreserved
613 690
 				if (
614 691
 					// Invalid sequences
@@ -631,12 +708,15 @@  discard block
 block discarded – undo
631 708
 					|| $character > 0x7E && $character < 0xA0
632 709
 					|| $character > 0xD7FF && $character < 0xF900
633 710
 				) {
634
-					for ($j = $start; $j <= $i; $j++) {
711
+					for ($j = $start; $j <= $i; $j++)
712
+					{
635 713
 						$string .= '%' . strtoupper($bytes[$j]);
636 714
 					}
637 715
 				}
638
-				else {
639
-					for ($j = $start; $j <= $i; $j++) {
716
+				else
717
+				{
718
+					for ($j = $start; $j <= $i; $j++)
719
+					{
640 720
 						$string .= chr(hexdec($bytes[$j]));
641 721
 					}
642 722
 				}
@@ -645,8 +725,10 @@  discard block
 block discarded – undo
645 725
 
646 726
 		// If we have any bytes left over they are invalid (i.e., we are
647 727
 		// mid-way through a multi-byte sequence)
648
-		if ($remaining) {
649
-			for ($j = $start; $j < $len; $j++) {
728
+		if ($remaining)
729
+		{
730
+			for ($j = $start; $j < $len; $j++)
731
+			{
650 732
 				$string .= '%' . strtoupper($bytes[$j]);
651 733
 			}
652 734
 		}
@@ -654,26 +736,34 @@  discard block
 block discarded – undo
654 736
 		return $string;
655 737
 	}
656 738
 
657
-	protected function scheme_normalization() {
658
-		if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
739
+	protected function scheme_normalization()
740
+	{
741
+		if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo'])
742
+		{
659 743
 			$this->iuserinfo = null;
660 744
 		}
661
-		if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
745
+		if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost'])
746
+		{
662 747
 			$this->ihost = null;
663 748
 		}
664
-		if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
749
+		if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port'])
750
+		{
665 751
 			$this->port = null;
666 752
 		}
667
-		if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
753
+		if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath'])
754
+		{
668 755
 			$this->ipath = '';
669 756
 		}
670
-		if (isset($this->ihost) && empty($this->ipath)) {
757
+		if (isset($this->ihost) && empty($this->ipath))
758
+		{
671 759
 			$this->ipath = '/';
672 760
 		}
673
-		if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
761
+		if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
762
+		{
674 763
 			$this->iquery = null;
675 764
 		}
676
-		if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
765
+		if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment'])
766
+		{
677 767
 			$this->ifragment = null;
678 768
 		}
679 769
 	}
@@ -684,7 +774,8 @@  discard block
 block discarded – undo
684 774
 	 *
685 775
 	 * @return bool
686 776
 	 */
687
-	public function is_valid() {
777
+	public function is_valid()
778
+	{
688 779
 		$isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
689 780
 		if ($this->ipath !== '' &&
690 781
 			(
@@ -710,16 +801,20 @@  discard block
 block discarded – undo
710 801
 	 * @param string $iri
711 802
 	 * @return bool
712 803
 	 */
713
-	protected function set_iri($iri) {
804
+	protected function set_iri($iri)
805
+	{
714 806
 		static $cache;
715
-		if (!$cache) {
807
+		if (!$cache)
808
+		{
716 809
 			$cache = array();
717 810
 		}
718 811
 
719
-		if ($iri === null) {
812
+		if ($iri === null)
813
+		{
720 814
 			return true;
721 815
 		}
722
-		if (isset($cache[$iri])) {
816
+		if (isset($cache[$iri]))
817
+		{
723 818
 			list($this->scheme,
724 819
 				 $this->iuserinfo,
725 820
 				 $this->ihost,
@@ -757,15 +852,19 @@  discard block
 block discarded – undo
757 852
 	 * @param string $scheme
758 853
 	 * @return bool
759 854
 	 */
760
-	protected function set_scheme($scheme) {
761
-		if ($scheme === null) {
855
+	protected function set_scheme($scheme)
856
+	{
857
+		if ($scheme === null)
858
+		{
762 859
 			$this->scheme = null;
763 860
 		}
764
-		elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
861
+		elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme))
862
+		{
765 863
 			$this->scheme = null;
766 864
 			return false;
767 865
 		}
768
-		else {
866
+		else
867
+		{
769 868
 			$this->scheme = strtolower($scheme);
770 869
 		}
771 870
 		return true;
@@ -778,19 +877,23 @@  discard block
 block discarded – undo
778 877
 	 * @param string $authority
779 878
 	 * @return bool
780 879
 	 */
781
-	protected function set_authority($authority) {
880
+	protected function set_authority($authority)
881
+	{
782 882
 		static $cache;
783
-		if (!$cache) {
883
+		if (!$cache)
884
+		{
784 885
 			$cache = array();
785 886
 		}
786 887
 
787
-		if ($authority === null) {
888
+		if ($authority === null)
889
+		{
788 890
 			$this->iuserinfo = null;
789 891
 			$this->ihost = null;
790 892
 			$this->port = null;
791 893
 			return true;
792 894
 		}
793
-		if (isset($cache[$authority])) {
895
+		if (isset($cache[$authority]))
896
+		{
794 897
 			list($this->iuserinfo,
795 898
 				 $this->ihost,
796 899
 				 $this->port,
@@ -800,21 +903,26 @@  discard block
 block discarded – undo
800 903
 		}
801 904
 
802 905
 		$remaining = $authority;
803
-		if (($iuserinfo_end = strrpos($remaining, '@')) !== false) {
906
+		if (($iuserinfo_end = strrpos($remaining, '@')) !== false)
907
+		{
804 908
 			$iuserinfo = substr($remaining, 0, $iuserinfo_end);
805 909
 			$remaining = substr($remaining, $iuserinfo_end + 1);
806 910
 		}
807
-		else {
911
+		else
912
+		{
808 913
 			$iuserinfo = null;
809 914
 		}
810
-		if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
915
+		if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false)
916
+		{
811 917
 			$port = substr($remaining, $port_start + 1);
812
-			if ($port === false || $port === '') {
918
+			if ($port === false || $port === '')
919
+			{
813 920
 				$port = null;
814 921
 			}
815 922
 			$remaining = substr($remaining, 0, $port_start);
816 923
 		}
817
-		else {
924
+		else
925
+		{
818 926
 			$port = null;
819 927
 		}
820 928
 
@@ -836,11 +944,14 @@  discard block
 block discarded – undo
836 944
 	 * @param string $iuserinfo
837 945
 	 * @return bool
838 946
 	 */
839
-	protected function set_userinfo($iuserinfo) {
840
-		if ($iuserinfo === null) {
947
+	protected function set_userinfo($iuserinfo)
948
+	{
949
+		if ($iuserinfo === null)
950
+		{
841 951
 			$this->iuserinfo = null;
842 952
 		}
843
-		else {
953
+		else
954
+		{
844 955
 			$this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
845 956
 			$this->scheme_normalization();
846 957
 		}
@@ -855,21 +966,27 @@  discard block
 block discarded – undo
855 966
 	 * @param string $ihost
856 967
 	 * @return bool
857 968
 	 */
858
-	protected function set_host($ihost) {
859
-		if ($ihost === null) {
969
+	protected function set_host($ihost)
970
+	{
971
+		if ($ihost === null)
972
+		{
860 973
 			$this->ihost = null;
861 974
 			return true;
862 975
 		}
863
-		if (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
864
-			if (Requests_IPv6::check_ipv6(substr($ihost, 1, -1))) {
976
+		if (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']')
977
+		{
978
+			if (Requests_IPv6::check_ipv6(substr($ihost, 1, -1)))
979
+			{
865 980
 				$this->ihost = '[' . Requests_IPv6::compress(substr($ihost, 1, -1)) . ']';
866 981
 			}
867
-			else {
982
+			else
983
+			{
868 984
 				$this->ihost = null;
869 985
 				return false;
870 986
 			}
871 987
 		}
872
-		else {
988
+		else
989
+		{
873 990
 			$ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
874 991
 
875 992
 			// Lowercase, but ignore pct-encoded sections (as they should
@@ -877,11 +994,14 @@  discard block
 block discarded – undo
877 994
 			// as that can add unescaped characters.
878 995
 			$position = 0;
879 996
 			$strlen = strlen($ihost);
880
-			while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) {
881
-				if ($ihost[$position] === '%') {
997
+			while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
998
+			{
999
+				if ($ihost[$position] === '%')
1000
+				{
882 1001
 					$position += 3;
883 1002
 				}
884
-				else {
1003
+				else
1004
+				{
885 1005
 					$ihost[$position] = strtolower($ihost[$position]);
886 1006
 					$position++;
887 1007
 				}
@@ -902,13 +1022,16 @@  discard block
 block discarded – undo
902 1022
 	 * @param string $port
903 1023
 	 * @return bool
904 1024
 	 */
905
-	protected function set_port($port) {
906
-		if ($port === null) {
1025
+	protected function set_port($port)
1026
+	{
1027
+		if ($port === null)
1028
+		{
907 1029
 			$this->port = null;
908 1030
 			return true;
909 1031
 		}
910 1032
 
911
-		if (strspn($port, '0123456789') === strlen($port)) {
1033
+		if (strspn($port, '0123456789') === strlen($port))
1034
+		{
912 1035
 			$this->port = (int) $port;
913 1036
 			$this->scheme_normalization();
914 1037
 			return true;
@@ -924,18 +1047,22 @@  discard block
 block discarded – undo
924 1047
 	 * @param string $ipath
925 1048
 	 * @return bool
926 1049
 	 */
927
-	protected function set_path($ipath) {
1050
+	protected function set_path($ipath)
1051
+	{
928 1052
 		static $cache;
929
-		if (!$cache) {
1053
+		if (!$cache)
1054
+		{
930 1055
 			$cache = array();
931 1056
 		}
932 1057
 
933 1058
 		$ipath = (string) $ipath;
934 1059
 
935
-		if (isset($cache[$ipath])) {
1060
+		if (isset($cache[$ipath]))
1061
+		{
936 1062
 			$this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
937 1063
 		}
938
-		else {
1064
+		else
1065
+		{
939 1066
 			$valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
940 1067
 			$removed = $this->remove_dot_segments($valid);
941 1068
 
@@ -952,11 +1079,14 @@  discard block
 block discarded – undo
952 1079
 	 * @param string $iquery
953 1080
 	 * @return bool
954 1081
 	 */
955
-	protected function set_query($iquery) {
956
-		if ($iquery === null) {
1082
+	protected function set_query($iquery)
1083
+	{
1084
+		if ($iquery === null)
1085
+		{
957 1086
 			$this->iquery = null;
958 1087
 		}
959
-		else {
1088
+		else
1089
+		{
960 1090
 			$this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
961 1091
 			$this->scheme_normalization();
962 1092
 		}
@@ -969,11 +1099,14 @@  discard block
 block discarded – undo
969 1099
 	 * @param string $ifragment
970 1100
 	 * @return bool
971 1101
 	 */
972
-	protected function set_fragment($ifragment) {
973
-		if ($ifragment === null) {
1102
+	protected function set_fragment($ifragment)
1103
+	{
1104
+		if ($ifragment === null)
1105
+		{
974 1106
 			$this->ifragment = null;
975 1107
 		}
976
-		else {
1108
+		else
1109
+		{
977 1110
 			$this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
978 1111
 			$this->scheme_normalization();
979 1112
 		}
@@ -986,19 +1119,23 @@  discard block
 block discarded – undo
986 1119
 	 * @param string|bool IRI to convert (or false from {@see get_iri})
987 1120
 	 * @return string|false URI if IRI is valid, false otherwise.
988 1121
 	 */
989
-	protected function to_uri($string) {
990
-		if (!is_string($string)) {
1122
+	protected function to_uri($string)
1123
+	{
1124
+		if (!is_string($string))
1125
+		{
991 1126
 			return false;
992 1127
 		}
993 1128
 
994 1129
 		static $non_ascii;
995
-		if (!$non_ascii) {
1130
+		if (!$non_ascii)
1131
+		{
996 1132
 			$non_ascii = implode('', range("\x80", "\xFF"));
997 1133
 		}
998 1134
 
999 1135
 		$position = 0;
1000 1136
 		$strlen = strlen($string);
1001
-		while (($position += strcspn($string, $non_ascii, $position)) < $strlen) {
1137
+		while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
1138
+		{
1002 1139
 			$string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
1003 1140
 			$position += 3;
1004 1141
 			$strlen += 2;
@@ -1012,23 +1149,29 @@  discard block
 block discarded – undo
1012 1149
 	 *
1013 1150
 	 * @return string
1014 1151
 	 */
1015
-	protected function get_iri() {
1016
-		if (!$this->is_valid()) {
1152
+	protected function get_iri()
1153
+	{
1154
+		if (!$this->is_valid())
1155
+		{
1017 1156
 			return false;
1018 1157
 		}
1019 1158
 
1020 1159
 		$iri = '';
1021
-		if ($this->scheme !== null) {
1160
+		if ($this->scheme !== null)
1161
+		{
1022 1162
 			$iri .= $this->scheme . ':';
1023 1163
 		}
1024
-		if (($iauthority = $this->get_iauthority()) !== null) {
1164
+		if (($iauthority = $this->get_iauthority()) !== null)
1165
+		{
1025 1166
 			$iri .= '//' . $iauthority;
1026 1167
 		}
1027 1168
 		$iri .= $this->ipath;
1028
-		if ($this->iquery !== null) {
1169
+		if ($this->iquery !== null)
1170
+		{
1029 1171
 			$iri .= '?' . $this->iquery;
1030 1172
 		}
1031
-		if ($this->ifragment !== null) {
1173
+		if ($this->ifragment !== null)
1174
+		{
1032 1175
 			$iri .= '#' . $this->ifragment;
1033 1176
 		}
1034 1177
 
@@ -1040,7 +1183,8 @@  discard block
 block discarded – undo
1040 1183
 	 *
1041 1184
 	 * @return string
1042 1185
 	 */
1043
-	protected function get_uri() {
1186
+	protected function get_uri()
1187
+	{
1044 1188
 		return $this->to_uri($this->get_iri());
1045 1189
 	}
1046 1190
 
@@ -1049,19 +1193,24 @@  discard block
 block discarded – undo
1049 1193
 	 *
1050 1194
 	 * @return string
1051 1195
 	 */
1052
-	protected function get_iauthority() {
1053
-		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
1196
+	protected function get_iauthority()
1197
+	{
1198
+		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null)
1199
+		{
1054 1200
 			return null;
1055 1201
 		}
1056 1202
 
1057 1203
 		$iauthority = '';
1058
-		if ($this->iuserinfo !== null) {
1204
+		if ($this->iuserinfo !== null)
1205
+		{
1059 1206
 			$iauthority .= $this->iuserinfo . '@';
1060 1207
 		}
1061
-		if ($this->ihost !== null) {
1208
+		if ($this->ihost !== null)
1209
+		{
1062 1210
 			$iauthority .= $this->ihost;
1063 1211
 		}
1064
-		if ($this->port !== null) {
1212
+		if ($this->port !== null)
1213
+		{
1065 1214
 			$iauthority .= ':' . $this->port;
1066 1215
 		}
1067 1216
 		return $iauthority;
@@ -1072,12 +1221,15 @@  discard block
 block discarded – undo
1072 1221
 	 *
1073 1222
 	 * @return string
1074 1223
 	 */
1075
-	protected function get_authority() {
1224
+	protected function get_authority()
1225
+	{
1076 1226
 		$iauthority = $this->get_iauthority();
1077
-		if (is_string($iauthority)) {
1227
+		if (is_string($iauthority))
1228
+		{
1078 1229
 			return $this->to_uri($iauthority);
1079 1230
 		}
1080
-		else {
1231
+		else
1232
+		{
1081 1233
 			return $iauthority;
1082 1234
 		}
1083 1235
 	}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -69,28 +69,28 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @var string
71 71
 	 */
72
-	protected $scheme = null;
72
+	protected $scheme = NULL;
73 73
 
74 74
 	/**
75 75
 	 * User Information
76 76
 	 *
77 77
 	 * @var string
78 78
 	 */
79
-	protected $iuserinfo = null;
79
+	protected $iuserinfo = NULL;
80 80
 
81 81
 	/**
82 82
 	 * ihost
83 83
 	 *
84 84
 	 * @var string
85 85
 	 */
86
-	protected $ihost = null;
86
+	protected $ihost = NULL;
87 87
 
88 88
 	/**
89 89
 	 * Port
90 90
 	 *
91 91
 	 * @var string
92 92
 	 */
93
-	protected $port = null;
93
+	protected $port = NULL;
94 94
 
95 95
 	/**
96 96
 	 * ipath
@@ -104,14 +104,14 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @var string
106 106
 	 */
107
-	protected $iquery = null;
107
+	protected $iquery = NULL;
108 108
 
109 109
 	/**
110 110
 	 * ifragment
111 111
 	 *
112 112
 	 * @var string
113 113
 	 */
114
-	protected $ifragment = null;
114
+	protected $ifragment = NULL;
115 115
 
116 116
 	/**
117 117
 	 * Normalization database
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 		}
204 204
 		else {
205 205
 			trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
206
-			$return = null;
206
+			$return = NULL;
207 207
 		}
208 208
 
209
-		if ($return === null && isset($this->normalization[$this->scheme][$name])) {
209
+		if ($return === NULL && isset($this->normalization[$this->scheme][$name])) {
210 210
 			return $this->normalization[$this->scheme][$name];
211 211
 		}
212 212
 		else {
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @param string|null $iri
242 242
 	 */
243
-	public function __construct($iri = null) {
243
+	public function __construct($iri = NULL) {
244 244
 		$this->set_iri($iri);
245 245
 	}
246 246
 
@@ -258,21 +258,21 @@  discard block
 block discarded – undo
258 258
 			$relative = new Requests_IRI($relative);
259 259
 		}
260 260
 		if (!$relative->is_valid()) {
261
-			return false;
261
+			return FALSE;
262 262
 		}
263
-		elseif ($relative->scheme !== null) {
263
+		elseif ($relative->scheme !== NULL) {
264 264
 			return clone $relative;
265 265
 		}
266 266
 
267 267
 		if (!($base instanceof Requests_IRI)) {
268 268
 			$base = new Requests_IRI($base);
269 269
 		}
270
-		if ($base->scheme === null || !$base->is_valid()) {
271
-			return false;
270
+		if ($base->scheme === NULL || !$base->is_valid()) {
271
+			return FALSE;
272 272
 		}
273 273
 
274 274
 		if ($relative->get_iri() !== '') {
275
-			if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
275
+			if ($relative->iuserinfo !== NULL || $relative->ihost !== NULL || $relative->port !== NULL) {
276 276
 				$target = clone $relative;
277 277
 				$target->scheme = $base->scheme;
278 278
 			}
@@ -286,10 +286,10 @@  discard block
 block discarded – undo
286 286
 					if ($relative->ipath[0] === '/') {
287 287
 						$target->ipath = $relative->ipath;
288 288
 					}
289
-					elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
289
+					elseif (($base->iuserinfo !== NULL || $base->ihost !== NULL || $base->port !== NULL) && $base->ipath === '') {
290 290
 						$target->ipath = '/' . $relative->ipath;
291 291
 					}
292
-					elseif (($last_segment = strrpos($base->ipath, '/')) !== false) {
292
+					elseif (($last_segment = strrpos($base->ipath, '/')) !== FALSE) {
293 293
 						$target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
294 294
 					}
295 295
 					else {
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
 				}
301 301
 				else {
302 302
 					$target->ipath = $base->ipath;
303
-					if ($relative->iquery !== null) {
303
+					if ($relative->iquery !== NULL) {
304 304
 						$target->iquery = $relative->iquery;
305 305
 					}
306
-					elseif ($base->iquery !== null) {
306
+					elseif ($base->iquery !== NULL) {
307 307
 						$target->iquery = $base->iquery;
308 308
 					}
309 309
 				}
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 		}
313 313
 		else {
314 314
 			$target = clone $base;
315
-			$target->ifragment = null;
315
+			$target->ifragment = NULL;
316 316
 		}
317 317
 		$target->scheme_normalization();
318 318
 		return $target;
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
 		}
333 333
 
334 334
 		if ($match[1] === '') {
335
-			$match['scheme'] = null;
335
+			$match['scheme'] = NULL;
336 336
 		}
337 337
 		if (!isset($match[3]) || $match[3] === '') {
338
-			$match['authority'] = null;
338
+			$match['authority'] = NULL;
339 339
 		}
340 340
 		if (!isset($match[5])) {
341 341
 			$match['path'] = '';
342 342
 		}
343 343
 		if (!isset($match[6]) || $match[6] === '') {
344
-			$match['query'] = null;
344
+			$match['query'] = NULL;
345 345
 		}
346 346
 		if (!isset($match[8]) || $match[8] === '') {
347
-			$match['fragment'] = null;
347
+			$match['fragment'] = NULL;
348 348
 		}
349 349
 		return $match;
350 350
 	}
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	 */
358 358
 	protected function remove_dot_segments($input) {
359 359
 		$output = '';
360
-		while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
360
+		while (strpos($input, './') !== FALSE || strpos($input, '/.') !== FALSE || $input === '.' || $input === '..') {
361 361
 			// A: If the input buffer begins with a prefix of "../" or "./",
362 362
 			// then remove that prefix from the input buffer; otherwise,
363 363
 			if (strpos($input, '../') === 0) {
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 			// the output buffer, including the initial "/" character (if any)
397 397
 			// and any subsequent characters up to, but not including, the next
398 398
 			// "/" character or the end of the input buffer
399
-			elseif (($pos = strpos($input, '/', 1)) !== false) {
399
+			elseif (($pos = strpos($input, '/', 1)) !== FALSE) {
400 400
 				$output .= substr($input, 0, $pos);
401 401
 				$input = substr_replace($input, '', 0, $pos);
402 402
 			}
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 	 * @param bool $iprivate Allow iprivate
418 418
 	 * @return string
419 419
 	 */
420
-	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) {
420
+	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = FALSE) {
421 421
 		// Normalize as many pct-encoded sections as possible
422 422
 		$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array(&$this, 'remove_iunreserved_percent_encoded'), $string);
423 423
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 			$start = $position;
439 439
 
440 440
 			// By default we are valid
441
-			$valid = true;
441
+			$valid = TRUE;
442 442
 
443 443
 			// No one byte sequences are valid due to the while.
444 444
 			// Two byte sequence:
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 			}
462 462
 			// Invalid byte:
463 463
 			else {
464
-				$valid = false;
464
+				$valid = FALSE;
465 465
 				$length = 1;
466 466
 				$remaining = 0;
467 467
 			}
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 						}
478 478
 						// If it is invalid, count the sequence as invalid and reprocess the current byte:
479 479
 						else {
480
-							$valid = false;
480
+							$valid = FALSE;
481 481
 							$position--;
482 482
 							break;
483 483
 						}
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 				}
486 486
 				else {
487 487
 					$position = $strlen - 1;
488
-					$valid = false;
488
+					$valid = FALSE;
489 489
 				}
490 490
 			}
491 491
 
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 				$start = $i;
562 562
 
563 563
 				// By default we are valid
564
-				$valid = true;
564
+				$valid = TRUE;
565 565
 
566 566
 				// One byte sequence:
567 567
 				if ($value <= 0x7F) {
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 				}
589 589
 				// Invalid byte:
590 590
 				else {
591
-					$valid = false;
591
+					$valid = FALSE;
592 592
 					$remaining = 0;
593 593
 				}
594 594
 			}
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 				}
602 602
 				// If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
603 603
 				else {
604
-					$valid = false;
604
+					$valid = FALSE;
605 605
 					$remaining = 0;
606 606
 					$i--;
607 607
 				}
@@ -656,13 +656,13 @@  discard block
 block discarded – undo
656 656
 
657 657
 	protected function scheme_normalization() {
658 658
 		if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
659
-			$this->iuserinfo = null;
659
+			$this->iuserinfo = NULL;
660 660
 		}
661 661
 		if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
662
-			$this->ihost = null;
662
+			$this->ihost = NULL;
663 663
 		}
664 664
 		if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
665
-			$this->port = null;
665
+			$this->port = NULL;
666 666
 		}
667 667
 		if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
668 668
 			$this->ipath = '';
@@ -671,10 +671,10 @@  discard block
 block discarded – undo
671 671
 			$this->ipath = '/';
672 672
 		}
673 673
 		if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
674
-			$this->iquery = null;
674
+			$this->iquery = NULL;
675 675
 		}
676 676
 		if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
677
-			$this->ifragment = null;
677
+			$this->ifragment = NULL;
678 678
 		}
679 679
 	}
680 680
 
@@ -685,22 +685,22 @@  discard block
 block discarded – undo
685 685
 	 * @return bool
686 686
 	 */
687 687
 	public function is_valid() {
688
-		$isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
688
+		$isauthority = $this->iuserinfo !== NULL || $this->ihost !== NULL || $this->port !== NULL;
689 689
 		if ($this->ipath !== '' &&
690 690
 			(
691 691
 				$isauthority && $this->ipath[0] !== '/' ||
692 692
 				(
693
-					$this->scheme === null &&
693
+					$this->scheme === NULL &&
694 694
 					!$isauthority &&
695
-					strpos($this->ipath, ':') !== false &&
696
-					(strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
695
+					strpos($this->ipath, ':') !== FALSE &&
696
+					(strpos($this->ipath, '/') === FALSE ? TRUE : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
697 697
 				)
698 698
 			)
699 699
 		) {
700
-			return false;
700
+			return FALSE;
701 701
 		}
702 702
 
703
-		return true;
703
+		return TRUE;
704 704
 	}
705 705
 
706 706
 	/**
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
 			$cache = array();
717 717
 		}
718 718
 
719
-		if ($iri === null) {
720
-			return true;
719
+		if ($iri === NULL) {
720
+			return TRUE;
721 721
 		}
722 722
 		if (isset($cache[$iri])) {
723 723
 			list($this->scheme,
@@ -758,17 +758,17 @@  discard block
 block discarded – undo
758 758
 	 * @return bool
759 759
 	 */
760 760
 	protected function set_scheme($scheme) {
761
-		if ($scheme === null) {
762
-			$this->scheme = null;
761
+		if ($scheme === NULL) {
762
+			$this->scheme = NULL;
763 763
 		}
764 764
 		elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
765
-			$this->scheme = null;
766
-			return false;
765
+			$this->scheme = NULL;
766
+			return FALSE;
767 767
 		}
768 768
 		else {
769 769
 			$this->scheme = strtolower($scheme);
770 770
 		}
771
-		return true;
771
+		return TRUE;
772 772
 	}
773 773
 
774 774
 	/**
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
 			$cache = array();
785 785
 		}
786 786
 
787
-		if ($authority === null) {
788
-			$this->iuserinfo = null;
789
-			$this->ihost = null;
790
-			$this->port = null;
791
-			return true;
787
+		if ($authority === NULL) {
788
+			$this->iuserinfo = NULL;
789
+			$this->ihost = NULL;
790
+			$this->port = NULL;
791
+			return TRUE;
792 792
 		}
793 793
 		if (isset($cache[$authority])) {
794 794
 			list($this->iuserinfo,
@@ -800,22 +800,22 @@  discard block
 block discarded – undo
800 800
 		}
801 801
 
802 802
 		$remaining = $authority;
803
-		if (($iuserinfo_end = strrpos($remaining, '@')) !== false) {
803
+		if (($iuserinfo_end = strrpos($remaining, '@')) !== FALSE) {
804 804
 			$iuserinfo = substr($remaining, 0, $iuserinfo_end);
805 805
 			$remaining = substr($remaining, $iuserinfo_end + 1);
806 806
 		}
807 807
 		else {
808
-			$iuserinfo = null;
808
+			$iuserinfo = NULL;
809 809
 		}
810
-		if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) {
810
+		if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== FALSE) {
811 811
 			$port = substr($remaining, $port_start + 1);
812
-			if ($port === false || $port === '') {
813
-				$port = null;
812
+			if ($port === FALSE || $port === '') {
813
+				$port = NULL;
814 814
 			}
815 815
 			$remaining = substr($remaining, 0, $port_start);
816 816
 		}
817 817
 		else {
818
-			$port = null;
818
+			$port = NULL;
819 819
 		}
820 820
 
821 821
 		$return = $this->set_userinfo($iuserinfo) &&
@@ -837,15 +837,15 @@  discard block
 block discarded – undo
837 837
 	 * @return bool
838 838
 	 */
839 839
 	protected function set_userinfo($iuserinfo) {
840
-		if ($iuserinfo === null) {
841
-			$this->iuserinfo = null;
840
+		if ($iuserinfo === NULL) {
841
+			$this->iuserinfo = NULL;
842 842
 		}
843 843
 		else {
844 844
 			$this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
845 845
 			$this->scheme_normalization();
846 846
 		}
847 847
 
848
-		return true;
848
+		return TRUE;
849 849
 	}
850 850
 
851 851
 	/**
@@ -856,17 +856,17 @@  discard block
 block discarded – undo
856 856
 	 * @return bool
857 857
 	 */
858 858
 	protected function set_host($ihost) {
859
-		if ($ihost === null) {
860
-			$this->ihost = null;
861
-			return true;
859
+		if ($ihost === NULL) {
860
+			$this->ihost = NULL;
861
+			return TRUE;
862 862
 		}
863 863
 		if (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
864 864
 			if (Requests_IPv6::check_ipv6(substr($ihost, 1, -1))) {
865 865
 				$this->ihost = '[' . Requests_IPv6::compress(substr($ihost, 1, -1)) . ']';
866 866
 			}
867 867
 			else {
868
-				$this->ihost = null;
869
-				return false;
868
+				$this->ihost = NULL;
869
+				return FALSE;
870 870
 			}
871 871
 		}
872 872
 		else {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
 
893 893
 		$this->scheme_normalization();
894 894
 
895
-		return true;
895
+		return TRUE;
896 896
 	}
897 897
 
898 898
 	/**
@@ -903,19 +903,19 @@  discard block
 block discarded – undo
903 903
 	 * @return bool
904 904
 	 */
905 905
 	protected function set_port($port) {
906
-		if ($port === null) {
907
-			$this->port = null;
908
-			return true;
906
+		if ($port === NULL) {
907
+			$this->port = NULL;
908
+			return TRUE;
909 909
 		}
910 910
 
911 911
 		if (strspn($port, '0123456789') === strlen($port)) {
912 912
 			$this->port = (int) $port;
913 913
 			$this->scheme_normalization();
914
-			return true;
914
+			return TRUE;
915 915
 		}
916 916
 
917
-		$this->port = null;
918
-		return false;
917
+		$this->port = NULL;
918
+		return FALSE;
919 919
 	}
920 920
 
921 921
 	/**
@@ -933,17 +933,17 @@  discard block
 block discarded – undo
933 933
 		$ipath = (string) $ipath;
934 934
 
935 935
 		if (isset($cache[$ipath])) {
936
-			$this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
936
+			$this->ipath = $cache[$ipath][(int) ($this->scheme !== NULL)];
937 937
 		}
938 938
 		else {
939 939
 			$valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
940 940
 			$removed = $this->remove_dot_segments($valid);
941 941
 
942 942
 			$cache[$ipath] = array($valid, $removed);
943
-			$this->ipath = ($this->scheme !== null) ? $removed : $valid;
943
+			$this->ipath = ($this->scheme !== NULL) ? $removed : $valid;
944 944
 		}
945 945
 		$this->scheme_normalization();
946
-		return true;
946
+		return TRUE;
947 947
 	}
948 948
 
949 949
 	/**
@@ -953,14 +953,14 @@  discard block
 block discarded – undo
953 953
 	 * @return bool
954 954
 	 */
955 955
 	protected function set_query($iquery) {
956
-		if ($iquery === null) {
957
-			$this->iquery = null;
956
+		if ($iquery === NULL) {
957
+			$this->iquery = NULL;
958 958
 		}
959 959
 		else {
960
-			$this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
960
+			$this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', TRUE);
961 961
 			$this->scheme_normalization();
962 962
 		}
963
-		return true;
963
+		return TRUE;
964 964
 	}
965 965
 
966 966
 	/**
@@ -970,14 +970,14 @@  discard block
 block discarded – undo
970 970
 	 * @return bool
971 971
 	 */
972 972
 	protected function set_fragment($ifragment) {
973
-		if ($ifragment === null) {
974
-			$this->ifragment = null;
973
+		if ($ifragment === NULL) {
974
+			$this->ifragment = NULL;
975 975
 		}
976 976
 		else {
977 977
 			$this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
978 978
 			$this->scheme_normalization();
979 979
 		}
980
-		return true;
980
+		return TRUE;
981 981
 	}
982 982
 
983 983
 	/**
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
 	 */
989 989
 	protected function to_uri($string) {
990 990
 		if (!is_string($string)) {
991
-			return false;
991
+			return FALSE;
992 992
 		}
993 993
 
994 994
 		static $non_ascii;
@@ -1014,21 +1014,21 @@  discard block
 block discarded – undo
1014 1014
 	 */
1015 1015
 	protected function get_iri() {
1016 1016
 		if (!$this->is_valid()) {
1017
-			return false;
1017
+			return FALSE;
1018 1018
 		}
1019 1019
 
1020 1020
 		$iri = '';
1021
-		if ($this->scheme !== null) {
1021
+		if ($this->scheme !== NULL) {
1022 1022
 			$iri .= $this->scheme . ':';
1023 1023
 		}
1024
-		if (($iauthority = $this->get_iauthority()) !== null) {
1024
+		if (($iauthority = $this->get_iauthority()) !== NULL) {
1025 1025
 			$iri .= '//' . $iauthority;
1026 1026
 		}
1027 1027
 		$iri .= $this->ipath;
1028
-		if ($this->iquery !== null) {
1028
+		if ($this->iquery !== NULL) {
1029 1029
 			$iri .= '?' . $this->iquery;
1030 1030
 		}
1031
-		if ($this->ifragment !== null) {
1031
+		if ($this->ifragment !== NULL) {
1032 1032
 			$iri .= '#' . $this->ifragment;
1033 1033
 		}
1034 1034
 
@@ -1050,18 +1050,18 @@  discard block
 block discarded – undo
1050 1050
 	 * @return string
1051 1051
 	 */
1052 1052
 	protected function get_iauthority() {
1053
-		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
1054
-			return null;
1053
+		if ($this->iuserinfo === NULL && $this->ihost === NULL && $this->port === NULL) {
1054
+			return NULL;
1055 1055
 		}
1056 1056
 
1057 1057
 		$iauthority = '';
1058
-		if ($this->iuserinfo !== null) {
1058
+		if ($this->iuserinfo !== NULL) {
1059 1059
 			$iauthority .= $this->iuserinfo . '@';
1060 1060
 		}
1061
-		if ($this->ihost !== null) {
1061
+		if ($this->ihost !== NULL) {
1062 1062
 			$iauthority .= $this->ihost;
1063 1063
 		}
1064
-		if ($this->port !== null) {
1064
+		if ($this->port !== NULL) {
1065 1065
 			$iauthority .= ':' . $this->port;
1066 1066
 		}
1067 1067
 		return $iauthority;
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Session.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@
 block discarded – undo
232 232
 	 *
233 233
 	 * @param array $request Request data (same form as {@see request_multiple})
234 234
 	 * @param boolean $merge_options Should we merge options as well?
235
-	 * @return array Request data
235
+	 * @return string Request data
236 236
 	 */
237 237
 	protected function merge_request($request, $merge_options = true) {
238 238
 		if ($this->url !== null) {
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		$this->data = $data;
70 70
 		$this->options = $options;
71 71
 
72
-		if (empty($this->options['cookies'])) {
72
+		if(empty($this->options['cookies'])) {
73 73
 			$this->options['cookies'] = new Requests_Cookie_Jar();
74 74
 		}
75 75
 	}
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @return mixed|null Property value, null if none found
82 82
 	 */
83 83
 	public function __get($key) {
84
-		if (isset($this->options[$key])) {
84
+		if(isset($this->options[$key])) {
85 85
 			return $this->options[$key];
86 86
 		}
87 87
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param string $key Property key
114 114
 	 */
115 115
 	public function __unset($key) {
116
-		if (isset($this->options[$key])) {
116
+		if(isset($this->options[$key])) {
117 117
 			unset($this->options[$key]);
118 118
 		}
119 119
 	}
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 * @return array Responses (either Requests_Response or a Requests_Exception object)
216 216
 	 */
217 217
 	public function request_multiple($requests, $options = array()) {
218
-		foreach ($requests as $key => $request) {
218
+		foreach($requests as $key => $request) {
219 219
 			$requests[$key] = $this->merge_request($request, false);
220 220
 		}
221 221
 
@@ -235,26 +235,26 @@  discard block
 block discarded – undo
235 235
 	 * @return array Request data
236 236
 	 */
237 237
 	protected function merge_request($request, $merge_options = true) {
238
-		if ($this->url !== null) {
238
+		if($this->url !== null) {
239 239
 			$request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
240 240
 			$request['url'] = $request['url']->uri;
241 241
 		}
242 242
 
243
-		if (empty($request['headers'])) {
243
+		if(empty($request['headers'])) {
244 244
 			$request['headers'] = array();
245 245
 		}
246 246
 		$request['headers'] = array_merge($this->headers, $request['headers']);
247 247
 
248
-		if (empty($request['data'])) {
249
-			if (is_array($this->data)) {
248
+		if(empty($request['data'])) {
249
+			if(is_array($this->data)) {
250 250
 				$request['data'] = $this->data;
251 251
 			}
252 252
 		}
253
-		elseif (is_array($request['data']) && is_array($this->data)) {
253
+		elseif(is_array($request['data']) && is_array($this->data)) {
254 254
 			$request['data'] = array_merge($this->data, $request['data']);
255 255
 		}
256 256
 
257
-		if ($merge_options !== false) {
257
+		if($merge_options !== false) {
258 258
 			$request['options'] = array_merge($this->options, $request['options']);
259 259
 
260 260
 			// Disallow forcing the type, as that's a per request setting
Please login to merge, or discard this 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.
Upper-Lower-Casing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * URLs will be made absolute using this as the base
25 25
 	 * @var string|null
26 26
 	 */
27
-	public $url = null;
27
+	public $url = NULL;
28 28
 
29 29
 	/**
30 30
 	 * Base headers for requests
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @param array $data Default data for requests
64 64
 	 * @param array $options Default options for requests
65 65
 	 */
66
-	public function __construct($url = null, $headers = array(), $data = array(), $options = array()) {
66
+	public function __construct($url = NULL, $headers = array(), $data = array(), $options = array()) {
67 67
 		$this->url = $url;
68 68
 		$this->headers = $headers;
69 69
 		$this->data = $data;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 			return $this->options[$key];
86 86
 		}
87 87
 
88
-		return null;
88
+		return NULL;
89 89
 	}
90 90
 
91 91
 	/**
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
 	 * Send a GET request
130 130
 	 */
131 131
 	public function get($url, $headers = array(), $options = array()) {
132
-		return $this->request($url, $headers, null, Requests::GET, $options);
132
+		return $this->request($url, $headers, NULL, Requests::GET, $options);
133 133
 	}
134 134
 
135 135
 	/**
136 136
 	 * Send a HEAD request
137 137
 	 */
138 138
 	public function head($url, $headers = array(), $options = array()) {
139
-		return $this->request($url, $headers, null, Requests::HEAD, $options);
139
+		return $this->request($url, $headers, NULL, Requests::HEAD, $options);
140 140
 	}
141 141
 
142 142
 	/**
143 143
 	 * Send a DELETE request
144 144
 	 */
145 145
 	public function delete($url, $headers = array(), $options = array()) {
146
-		return $this->request($url, $headers, null, Requests::DELETE, $options);
146
+		return $this->request($url, $headers, NULL, Requests::DELETE, $options);
147 147
 	}
148 148
 	/**#@-*/
149 149
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	public function request_multiple($requests, $options = array()) {
218 218
 		foreach ($requests as $key => $request) {
219
-			$requests[$key] = $this->merge_request($request, false);
219
+			$requests[$key] = $this->merge_request($request, FALSE);
220 220
 		}
221 221
 
222 222
 		$options = array_merge($this->options, $options);
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 	 * @param boolean $merge_options Should we merge options as well?
235 235
 	 * @return array Request data
236 236
 	 */
237
-	protected function merge_request($request, $merge_options = true) {
238
-		if ($this->url !== null) {
237
+	protected function merge_request($request, $merge_options = TRUE) {
238
+		if ($this->url !== NULL) {
239 239
 			$request['url'] = Requests_IRI::absolutize($this->url, $request['url']);
240 240
 			$request['url'] = $request['url']->uri;
241 241
 		}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 			$request['data'] = array_merge($this->data, $request['data']);
255 255
 		}
256 256
 
257
-		if ($merge_options !== false) {
257
+		if ($merge_options !== FALSE) {
258 258
 			$request['options'] = array_merge($this->options, $request['options']);
259 259
 
260 260
 			// Disallow forcing the type, as that's a per request setting
Please login to merge, or discard this patch.
php/Requests/GetKarma.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 block discarded – undo
3 3
 
4 4
 class GetKarma extends AbstractRequest {
5 5
 		
6
-    function getApiEndPoint()
7
-    {
8
-        return '/v2/users/karma';
9
-    }
10
-    function getPayload()
11
-    {
12
-        return array(
13
-        );
14
-    }
15
-    function getMethod()
16
-    {
17
-        return 'GET';
18
-    }
6
+	function getApiEndPoint()
7
+	{
8
+		return '/v2/users/karma';
9
+	}
10
+	function getPayload()
11
+	{
12
+		return array(
13
+		);
14
+	}
15
+	function getMethod()
16
+	{
17
+		return 'GET';
18
+	}
19 19
 }
20 20
 
Please login to merge, or discard this 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/libary/Requests/Auth.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,5 +29,5 @@
 block discarded – undo
29 29
 	 * @see Requests_Hooks::register
30 30
 	 * @param Requests_Hooks $hooks Hook system
31 31
 	 */
32
-	public function register(Requests_Hooks &$hooks);
32
+	public function register(Requests_Hooks&$hooks);
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -28,6 +28,7 @@
 block discarded – undo
28 28
 	 *
29 29
 	 * @see Requests_Hooks::register
30 30
 	 * @param Requests_Hooks $hooks Hook system
31
+	 * @return void
31 32
 	 */
32 33
 	public function register(Requests_Hooks &$hooks);
33 34
 }
34 35
\ No newline at end of file
Please login to merge, or discard this 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/Location.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Location{
3
+class Location {
4 4
 
5 5
     public $cityName;
6 6
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     {
38 38
         $this->lng = $lng;
39 39
     }
40
-    public function toArray(){
40
+    public function toArray() {
41 41
         return array(
42 42
             "city" => $this->getCityName(),
43 43
             "country" => 'DE',
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Location{
3
+class Location
4
+{
4 5
 
5 6
     public $cityName;
6 7
 
@@ -37,7 +38,8 @@  discard block
 block discarded – undo
37 38
     {
38 39
         $this->lng = $lng;
39 40
     }
40
-    public function toArray(){
41
+    public function toArray()
42
+    {
41 43
         return array(
42 44
             "city" => $this->getCityName(),
43 45
             "country" => 'DE',
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -2,51 +2,51 @@
 block discarded – undo
2 2
 
3 3
 class Location{
4 4
 
5
-    public $cityName;
6
-
7
-    public $lat;
8
-
9
-    public $lng;
10
-
11
-    public function getCityName()
12
-    {
13
-        return $this->cityName;
14
-    }
15
-
16
-    public function setCityName($cityName)
17
-    {
18
-        $this->cityName = $cityName;
19
-    }
20
-
21
-    public function getLat()
22
-    {
23
-        return $this->lat;
24
-    }
25
-
26
-    public function setLat($lat)
27
-    {
28
-        $this->lat = $lat;
29
-    }
30
-
31
-    public function getLng()
32
-    {
33
-        return $this->lng;
34
-    }
35
-
36
-    public function setLng($lng)
37
-    {
38
-        $this->lng = $lng;
39
-    }
40
-    public function toArray(){
41
-        return array(
42
-            "city" => $this->getCityName(),
43
-            "country" => 'DE',
44
-            "loc_accuracy" => '0.0',
45
-            "loc_coordinates" => array(
46
-                "lat" => $this->getLat(),
47
-                "lng" => $this->getLng(),
48
-            ),
49
-            "name" => $this->getCityName()
50
-        );
51
-    }
5
+	public $cityName;
6
+
7
+	public $lat;
8
+
9
+	public $lng;
10
+
11
+	public function getCityName()
12
+	{
13
+		return $this->cityName;
14
+	}
15
+
16
+	public function setCityName($cityName)
17
+	{
18
+		$this->cityName = $cityName;
19
+	}
20
+
21
+	public function getLat()
22
+	{
23
+		return $this->lat;
24
+	}
25
+
26
+	public function setLat($lat)
27
+	{
28
+		$this->lat = $lat;
29
+	}
30
+
31
+	public function getLng()
32
+	{
33
+		return $this->lng;
34
+	}
35
+
36
+	public function setLng($lng)
37
+	{
38
+		$this->lng = $lng;
39
+	}
40
+	public function toArray(){
41
+		return array(
42
+			"city" => $this->getCityName(),
43
+			"country" => 'DE',
44
+			"loc_accuracy" => '0.0',
45
+			"loc_coordinates" => array(
46
+				"lat" => $this->getLat(),
47
+				"lng" => $this->getLng(),
48
+			),
49
+			"name" => $this->getCityName()
50
+		);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Cookie.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @param string $name
64 64
 	 * @param string $value
65
-	 * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
65
+	 * @param Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
66 66
 	 */
67 67
 	public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) {
68 68
 		$this->name = $name;
@@ -377,6 +377,7 @@  discard block
 block discarded – undo
377 377
 	 * specifies some of this handling, but not in a thorough manner.
378 378
 	 *
379 379
 	 * @param string Cookie header value (from a Set-Cookie header)
380
+	 * @param integer $reference_time
380 381
 	 * @return Requests_Cookie Parsed cookie object
381 382
 	 */
382 383
 	public static function parse($string, $name = '', $reference_time = null) {
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		$this->flags = array_merge($default_flags, $flags);
78 78
 
79 79
 		$this->reference_time = time();
80
-		if ($reference_time !== null) {
80
+		if($reference_time !== null) {
81 81
 			$this->reference_time = $reference_time;
82 82
 		}
83 83
 
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
 		// If a cookie has both the Max-Age and the Expires attribute, the Max-
98 98
 		// Age attribute has precedence and controls the expiration date of the
99 99
 		// cookie.
100
-		if (isset($this->attributes['max-age'])) {
100
+		if(isset($this->attributes['max-age'])) {
101 101
 			$max_age = $this->attributes['max-age'];
102 102
 			return $max_age < $this->reference_time;
103 103
 		}
104 104
 
105
-		if (isset($this->attributes['expires'])) {
105
+		if(isset($this->attributes['expires'])) {
106 106
 			$expires = $this->attributes['expires'];
107 107
 			return $expires < $this->reference_time;
108 108
 		}
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 * @return boolean Whether the cookie is valid for the given URI
118 118
 	 */
119 119
 	public function uri_matches(Requests_IRI $uri) {
120
-		if (!$this->domain_matches($uri->host)) {
120
+		if(!$this->domain_matches($uri->host)) {
121 121
 			return false;
122 122
 		}
123 123
 
124
-		if (!$this->path_matches($uri->path)) {
124
+		if(!$this->path_matches($uri->path)) {
125 125
 			return false;
126 126
 		}
127 127
 
@@ -135,37 +135,37 @@  discard block
 block discarded – undo
135 135
 	 * @return boolean Whether the cookie is valid for the given domain
136 136
 	 */
137 137
 	public function domain_matches($string) {
138
-		if (!isset($this->attributes['domain'])) {
138
+		if(!isset($this->attributes['domain'])) {
139 139
 			// Cookies created manually; cookies created by Requests will set
140 140
 			// the domain to the requested domain
141 141
 			return true;
142 142
 		}
143 143
 
144 144
 		$domain_string = $this->attributes['domain'];
145
-		if ($domain_string === $string) {
145
+		if($domain_string === $string) {
146 146
 			// The domain string and the string are identical.
147 147
 			return true;
148 148
 		}
149 149
 
150 150
 		// If the cookie is marked as host-only and we don't have an exact
151 151
 		// match, reject the cookie
152
-		if ($this->flags['host-only'] === true) {
152
+		if($this->flags['host-only'] === true) {
153 153
 			return false;
154 154
 		}
155 155
 
156
-		if (strlen($string) <= strlen($domain_string)) {
156
+		if(strlen($string) <= strlen($domain_string)) {
157 157
 			// For obvious reasons, the string cannot be a suffix if the domain
158 158
 			// is shorter than the domain string
159 159
 			return false;
160 160
 		}
161 161
 
162
-		if (substr($string, -1 * strlen($domain_string)) !== $domain_string) {
162
+		if(substr($string, -1 * strlen($domain_string)) !== $domain_string) {
163 163
 			// The domain string should be a suffix of the string.
164 164
 			return false;
165 165
 		}
166 166
 
167 167
 		$prefix = substr($string, 0, strlen($string) - strlen($domain_string));
168
-		if (substr($prefix, -1) !== '.') {
168
+		if(substr($prefix, -1) !== '.') {
169 169
 			// The last character of the string that is not included in the
170 170
 			// domain string should be a %x2E (".") character.
171 171
 			return false;
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
 	 * @return boolean Whether the cookie is valid for the given path
185 185
 	 */
186 186
 	public function path_matches($request_path) {
187
-		if (empty($request_path)) {
187
+		if(empty($request_path)) {
188 188
 			// Normalize empty path to root
189 189
 			$request_path = '/';
190 190
 		}
191 191
 
192
-		if (!isset($this->attributes['path'])) {
192
+		if(!isset($this->attributes['path'])) {
193 193
 			// Cookies created manually; cookies created by Requests will set
194 194
 			// the path to the requested path
195 195
 			return true;
@@ -197,19 +197,19 @@  discard block
 block discarded – undo
197 197
 
198 198
 		$cookie_path = $this->attributes['path'];
199 199
 
200
-		if ($cookie_path === $request_path) {
200
+		if($cookie_path === $request_path) {
201 201
 			// The cookie-path and the request-path are identical.
202 202
 			return true;
203 203
 		}
204 204
 
205
-		if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) {
206
-			if (substr($cookie_path, -1) === '/') {
205
+		if(strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) {
206
+			if(substr($cookie_path, -1) === '/') {
207 207
 				// The cookie-path is a prefix of the request-path, and the last
208 208
 				// character of the cookie-path is %x2F ("/").
209 209
 				return true;
210 210
 			}
211 211
 
212
-			if (substr($request_path, strlen($cookie_path), 1) === '/') {
212
+			if(substr($request_path, strlen($cookie_path), 1) === '/') {
213 213
 				// The cookie-path is a prefix of the request-path, and the
214 214
 				// first character of the request-path that is not included in
215 215
 				// the cookie-path is a %x2F ("/") character.
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
 	 * @return boolean Whether the cookie was successfully normalized
227 227
 	 */
228 228
 	public function normalize() {
229
-		foreach ($this->attributes as $key => $value) {
229
+		foreach($this->attributes as $key => $value) {
230 230
 			$orig_value = $value;
231 231
 			$value = $this->normalize_attribute($key, $value);
232
-			if ($value === null) {
232
+			if($value === null) {
233 233
 				unset($this->attributes[$key]);
234 234
 				continue;
235 235
 			}
236 236
 
237
-			if ($value !== $orig_value) {
237
+			if($value !== $orig_value) {
238 238
 				$this->attributes[$key] = $value;
239 239
 			}
240 240
 		}
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
 	 * @return mixed Value if available, or null if the attribute value is invalid (and should be skipped)
253 253
 	 */
254 254
 	protected function normalize_attribute($name, $value) {
255
-		switch (strtolower($name)) {
255
+		switch(strtolower($name)) {
256 256
 			case 'expires':
257 257
 				// Expiration parsing, as per RFC 6265 section 5.2.1
258
-				if (is_int($value)) {
258
+				if(is_int($value)) {
259 259
 					return $value;
260 260
 				}
261 261
 
262 262
 				$expiry_time = strtotime($value);
263
-				if ($expiry_time === false) {
263
+				if($expiry_time === false) {
264 264
 					return null;
265 265
 				}
266 266
 
@@ -268,17 +268,17 @@  discard block
 block discarded – undo
268 268
 
269 269
 			case 'max-age':
270 270
 				// Expiration parsing, as per RFC 6265 section 5.2.2
271
-				if (is_int($value)) {
271
+				if(is_int($value)) {
272 272
 					return $value;
273 273
 				}
274 274
 
275 275
 				// Check that we have a valid age
276
-				if (!preg_match('/^-?\d+$/', $value)) {
276
+				if(!preg_match('/^-?\d+$/', $value)) {
277 277
 					return null;
278 278
 				}
279 279
 
280
-				$delta_seconds = (int) $value;
281
-				if ($delta_seconds <= 0) {
280
+				$delta_seconds = (int)$value;
281
+				if($delta_seconds <= 0) {
282 282
 					$expiry_time = 0;
283 283
 				}
284 284
 				else {
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
 			case 'domain':
291 291
 				// Domain normalization, as per RFC 6265 section 5.2.3
292
-				if ($value[0] === '.') {
292
+				if($value[0] === '.') {
293 293
 					$value = substr($value, 1);
294 294
 				}
295 295
 
@@ -332,11 +332,11 @@  discard block
 block discarded – undo
332 332
 	 */
333 333
 	public function format_for_set_cookie() {
334 334
 		$header_value = $this->format_for_header();
335
-		if (!empty($this->attributes)) {
335
+		if(!empty($this->attributes)) {
336 336
 			$parts = array();
337
-			foreach ($this->attributes as $key => $value) {
337
+			foreach($this->attributes as $key => $value) {
338 338
 				// Ignore non-associative attributes
339
-				if (is_numeric($key)) {
339
+				if(is_numeric($key)) {
340 340
 					$parts[] = $value;
341 341
 				}
342 342
 				else {
@@ -383,10 +383,10 @@  discard block
 block discarded – undo
383 383
 		$parts = explode(';', $string);
384 384
 		$kvparts = array_shift($parts);
385 385
 
386
-		if (!empty($name)) {
386
+		if(!empty($name)) {
387 387
 			$value = $string;
388 388
 		}
389
-		elseif (strpos($kvparts, '=') === false) {
389
+		elseif(strpos($kvparts, '=') === false) {
390 390
 			// Some sites might only have a value without the equals separator.
391 391
 			// Deviate from RFC 6265 and pretend it was actually a blank name
392 392
 			// (`=foo`)
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
 		// Attribute key are handled case-insensitively
405 405
 		$attributes = new Requests_Utility_CaseInsensitiveDictionary();
406 406
 
407
-		if (!empty($parts)) {
408
-			foreach ($parts as $part) {
409
-				if (strpos($part, '=') === false) {
407
+		if(!empty($parts)) {
408
+			foreach($parts as $part) {
409
+				if(strpos($part, '=') === false) {
410 410
 					$part_key = $part;
411 411
 					$part_value = true;
412 412
 				}
@@ -433,16 +433,16 @@  discard block
 block discarded – undo
433 433
 	 */
434 434
 	public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) {
435 435
 		$cookie_headers = $headers->getValues('Set-Cookie');
436
-		if (empty($cookie_headers)) {
436
+		if(empty($cookie_headers)) {
437 437
 			return array();
438 438
 		}
439 439
 
440 440
 		$cookies = array();
441
-		foreach ($cookie_headers as $header) {
441
+		foreach($cookie_headers as $header) {
442 442
 			$parsed = self::parse($header, '', $time);
443 443
 
444 444
 			// Default domain/path attributes
445
-			if (empty($parsed->attributes['domain']) && !empty($origin)) {
445
+			if(empty($parsed->attributes['domain']) && !empty($origin)) {
446 446
 				$parsed->attributes['domain'] = $origin->host;
447 447
 				$parsed->flags['host-only'] = true;
448 448
 			}
@@ -451,17 +451,17 @@  discard block
 block discarded – undo
451 451
 			}
452 452
 
453 453
 			$path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/');
454
-			if (!$path_is_valid && !empty($origin)) {
454
+			if(!$path_is_valid && !empty($origin)) {
455 455
 				$path = $origin->path;
456 456
 
457 457
 				// Default path normalization as per RFC 6265 section 5.1.4
458
-				if (substr($path, 0, 1) !== '/') {
458
+				if(substr($path, 0, 1) !== '/') {
459 459
 					// If the uri-path is empty or if the first character of
460 460
 					// the uri-path is not a %x2F ("/") character, output
461 461
 					// %x2F ("/") and skip the remaining steps.
462 462
 					$path = '/';
463 463
 				}
464
-				elseif (substr_count($path, '/') === 1) {
464
+				elseif(substr_count($path, '/') === 1) {
465 465
 					// If the uri-path contains no more than one %x2F ("/")
466 466
 					// character, output %x2F ("/") and skip the remaining
467 467
 					// step.
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 			}
478 478
 
479 479
 			// Reject invalid cookie domains
480
-			if (!empty($origin) && !$parsed->domain_matches($origin->host)) {
480
+			if(!empty($origin) && !$parsed->domain_matches($origin->host)) {
481 481
 				continue;
482 482
 			}
483 483
 
Please login to merge, or discard this patch.
Braces   +128 added lines, -64 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
  * @package Requests
13 13
  * @subpackage Cookies
14 14
  */
15
-class Requests_Cookie {
15
+class Requests_Cookie
16
+{
16 17
 	/**
17 18
 	 * Cookie name.
18 19
 	 *
@@ -64,7 +65,8 @@  discard block
 block discarded – undo
64 65
 	 * @param string $value
65 66
 	 * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
66 67
 	 */
67
-	public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) {
68
+	public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null)
69
+	{
68 70
 		$this->name = $name;
69 71
 		$this->value = $value;
70 72
 		$this->attributes = $attributes;
@@ -77,7 +79,8 @@  discard block
 block discarded – undo
77 79
 		$this->flags = array_merge($default_flags, $flags);
78 80
 
79 81
 		$this->reference_time = time();
80
-		if ($reference_time !== null) {
82
+		if ($reference_time !== null)
83
+		{
81 84
 			$this->reference_time = $reference_time;
82 85
 		}
83 86
 
@@ -92,17 +95,20 @@  discard block
 block discarded – undo
92 95
 	 *
93 96
 	 * @return boolean True if expired, false if time is valid.
94 97
 	 */
95
-	public function is_expired() {
98
+	public function is_expired()
99
+	{
96 100
 		// RFC6265, s. 4.1.2.2:
97 101
 		// If a cookie has both the Max-Age and the Expires attribute, the Max-
98 102
 		// Age attribute has precedence and controls the expiration date of the
99 103
 		// cookie.
100
-		if (isset($this->attributes['max-age'])) {
104
+		if (isset($this->attributes['max-age']))
105
+		{
101 106
 			$max_age = $this->attributes['max-age'];
102 107
 			return $max_age < $this->reference_time;
103 108
 		}
104 109
 
105
-		if (isset($this->attributes['expires'])) {
110
+		if (isset($this->attributes['expires']))
111
+		{
106 112
 			$expires = $this->attributes['expires'];
107 113
 			return $expires < $this->reference_time;
108 114
 		}
@@ -116,12 +122,15 @@  discard block
 block discarded – undo
116 122
 	 * @param Requests_IRI $uri URI to check
117 123
 	 * @return boolean Whether the cookie is valid for the given URI
118 124
 	 */
119
-	public function uri_matches(Requests_IRI $uri) {
120
-		if (!$this->domain_matches($uri->host)) {
125
+	public function uri_matches(Requests_IRI $uri)
126
+	{
127
+		if (!$this->domain_matches($uri->host))
128
+		{
121 129
 			return false;
122 130
 		}
123 131
 
124
-		if (!$this->path_matches($uri->path)) {
132
+		if (!$this->path_matches($uri->path))
133
+		{
125 134
 			return false;
126 135
 		}
127 136
 
@@ -134,38 +143,45 @@  discard block
 block discarded – undo
134 143
 	 * @param string $string Domain to check
135 144
 	 * @return boolean Whether the cookie is valid for the given domain
136 145
 	 */
137
-	public function domain_matches($string) {
138
-		if (!isset($this->attributes['domain'])) {
146
+	public function domain_matches($string)
147
+	{
148
+		if (!isset($this->attributes['domain']))
149
+		{
139 150
 			// Cookies created manually; cookies created by Requests will set
140 151
 			// the domain to the requested domain
141 152
 			return true;
142 153
 		}
143 154
 
144 155
 		$domain_string = $this->attributes['domain'];
145
-		if ($domain_string === $string) {
156
+		if ($domain_string === $string)
157
+		{
146 158
 			// The domain string and the string are identical.
147 159
 			return true;
148 160
 		}
149 161
 
150 162
 		// If the cookie is marked as host-only and we don't have an exact
151 163
 		// match, reject the cookie
152
-		if ($this->flags['host-only'] === true) {
164
+		if ($this->flags['host-only'] === true)
165
+		{
153 166
 			return false;
154 167
 		}
155 168
 
156
-		if (strlen($string) <= strlen($domain_string)) {
169
+		if (strlen($string) <= strlen($domain_string))
170
+		{
157 171
 			// For obvious reasons, the string cannot be a suffix if the domain
158 172
 			// is shorter than the domain string
159 173
 			return false;
160 174
 		}
161 175
 
162
-		if (substr($string, -1 * strlen($domain_string)) !== $domain_string) {
176
+		if (substr($string, -1 * strlen($domain_string)) !== $domain_string)
177
+		{
163 178
 			// The domain string should be a suffix of the string.
164 179
 			return false;
165 180
 		}
166 181
 
167 182
 		$prefix = substr($string, 0, strlen($string) - strlen($domain_string));
168
-		if (substr($prefix, -1) !== '.') {
183
+		if (substr($prefix, -1) !== '.')
184
+		{
169 185
 			// The last character of the string that is not included in the
170 186
 			// domain string should be a %x2E (".") character.
171 187
 			return false;
@@ -183,13 +199,16 @@  discard block
 block discarded – undo
183 199
 	 * @param string $request_path Path to check
184 200
 	 * @return boolean Whether the cookie is valid for the given path
185 201
 	 */
186
-	public function path_matches($request_path) {
187
-		if (empty($request_path)) {
202
+	public function path_matches($request_path)
203
+	{
204
+		if (empty($request_path))
205
+		{
188 206
 			// Normalize empty path to root
189 207
 			$request_path = '/';
190 208
 		}
191 209
 
192
-		if (!isset($this->attributes['path'])) {
210
+		if (!isset($this->attributes['path']))
211
+		{
193 212
 			// Cookies created manually; cookies created by Requests will set
194 213
 			// the path to the requested path
195 214
 			return true;
@@ -197,19 +216,23 @@  discard block
 block discarded – undo
197 216
 
198 217
 		$cookie_path = $this->attributes['path'];
199 218
 
200
-		if ($cookie_path === $request_path) {
219
+		if ($cookie_path === $request_path)
220
+		{
201 221
 			// The cookie-path and the request-path are identical.
202 222
 			return true;
203 223
 		}
204 224
 
205
-		if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) {
206
-			if (substr($cookie_path, -1) === '/') {
225
+		if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path)
226
+		{
227
+			if (substr($cookie_path, -1) === '/')
228
+			{
207 229
 				// The cookie-path is a prefix of the request-path, and the last
208 230
 				// character of the cookie-path is %x2F ("/").
209 231
 				return true;
210 232
 			}
211 233
 
212
-			if (substr($request_path, strlen($cookie_path), 1) === '/') {
234
+			if (substr($request_path, strlen($cookie_path), 1) === '/')
235
+			{
213 236
 				// The cookie-path is a prefix of the request-path, and the
214 237
 				// first character of the request-path that is not included in
215 238
 				// the cookie-path is a %x2F ("/") character.
@@ -225,16 +248,20 @@  discard block
 block discarded – undo
225 248
 	 *
226 249
 	 * @return boolean Whether the cookie was successfully normalized
227 250
 	 */
228
-	public function normalize() {
229
-		foreach ($this->attributes as $key => $value) {
251
+	public function normalize()
252
+	{
253
+		foreach ($this->attributes as $key => $value)
254
+		{
230 255
 			$orig_value = $value;
231 256
 			$value = $this->normalize_attribute($key, $value);
232
-			if ($value === null) {
257
+			if ($value === null)
258
+			{
233 259
 				unset($this->attributes[$key]);
234 260
 				continue;
235 261
 			}
236 262
 
237
-			if ($value !== $orig_value) {
263
+			if ($value !== $orig_value)
264
+			{
238 265
 				$this->attributes[$key] = $value;
239 266
 			}
240 267
 		}
@@ -251,16 +278,20 @@  discard block
 block discarded – undo
251 278
 	 * @param string|boolean $value Attribute value (string value, or true if empty/flag)
252 279
 	 * @return mixed Value if available, or null if the attribute value is invalid (and should be skipped)
253 280
 	 */
254
-	protected function normalize_attribute($name, $value) {
255
-		switch (strtolower($name)) {
281
+	protected function normalize_attribute($name, $value)
282
+	{
283
+		switch (strtolower($name))
284
+		{
256 285
 			case 'expires':
257 286
 				// Expiration parsing, as per RFC 6265 section 5.2.1
258
-				if (is_int($value)) {
287
+				if (is_int($value))
288
+				{
259 289
 					return $value;
260 290
 				}
261 291
 
262 292
 				$expiry_time = strtotime($value);
263
-				if ($expiry_time === false) {
293
+				if ($expiry_time === false)
294
+				{
264 295
 					return null;
265 296
 				}
266 297
 
@@ -268,20 +299,24 @@  discard block
 block discarded – undo
268 299
 
269 300
 			case 'max-age':
270 301
 				// Expiration parsing, as per RFC 6265 section 5.2.2
271
-				if (is_int($value)) {
302
+				if (is_int($value))
303
+				{
272 304
 					return $value;
273 305
 				}
274 306
 
275 307
 				// Check that we have a valid age
276
-				if (!preg_match('/^-?\d+$/', $value)) {
308
+				if (!preg_match('/^-?\d+$/', $value))
309
+				{
277 310
 					return null;
278 311
 				}
279 312
 
280 313
 				$delta_seconds = (int) $value;
281
-				if ($delta_seconds <= 0) {
314
+				if ($delta_seconds <= 0)
315
+				{
282 316
 					$expiry_time = 0;
283 317
 				}
284
-				else {
318
+				else
319
+				{
285 320
 					$expiry_time = $this->reference_time + $delta_seconds;
286 321
 				}
287 322
 
@@ -289,7 +324,8 @@  discard block
 block discarded – undo
289 324
 
290 325
 			case 'domain':
291 326
 				// Domain normalization, as per RFC 6265 section 5.2.3
292
-				if ($value[0] === '.') {
327
+				if ($value[0] === '.')
328
+				{
293 329
 					$value = substr($value, 1);
294 330
 				}
295 331
 
@@ -307,7 +343,8 @@  discard block
 block discarded – undo
307 343
 	 *
308 344
 	 * @return string Cookie formatted for Cookie header
309 345
 	 */
310
-	public function format_for_header() {
346
+	public function format_for_header()
347
+	{
311 348
 		return sprintf('%s=%s', $this->name, $this->value);
312 349
 	}
313 350
 
@@ -318,7 +355,8 @@  discard block
 block discarded – undo
318 355
 	 * @deprecated Use {@see Requests_Cookie::format_for_header}
319 356
 	 * @return string
320 357
 	 */
321
-	public function formatForHeader() {
358
+	public function formatForHeader()
359
+	{
322 360
 		return $this->format_for_header();
323 361
 	}
324 362
 
@@ -330,16 +368,21 @@  discard block
 block discarded – undo
330 368
 	 *
331 369
 	 * @return string Cookie formatted for Set-Cookie header
332 370
 	 */
333
-	public function format_for_set_cookie() {
371
+	public function format_for_set_cookie()
372
+	{
334 373
 		$header_value = $this->format_for_header();
335
-		if (!empty($this->attributes)) {
374
+		if (!empty($this->attributes))
375
+		{
336 376
 			$parts = array();
337
-			foreach ($this->attributes as $key => $value) {
377
+			foreach ($this->attributes as $key => $value)
378
+			{
338 379
 				// Ignore non-associative attributes
339
-				if (is_numeric($key)) {
380
+				if (is_numeric($key))
381
+				{
340 382
 					$parts[] = $value;
341 383
 				}
342
-				else {
384
+				else
385
+				{
343 386
 					$parts[] = sprintf('%s=%s', $key, $value);
344 387
 				}
345 388
 			}
@@ -356,7 +399,8 @@  discard block
 block discarded – undo
356 399
 	 * @deprecated Use {@see Requests_Cookie::format_for_set_cookie}
357 400
 	 * @return string
358 401
 	 */
359
-	public function formatForSetCookie() {
402
+	public function formatForSetCookie()
403
+	{
360 404
 		return $this->format_for_set_cookie();
361 405
 	}
362 406
 
@@ -365,7 +409,8 @@  discard block
 block discarded – undo
365 409
 	 *
366 410
 	 * Attributes and other data can be accessed via methods.
367 411
 	 */
368
-	public function __toString() {
412
+	public function __toString()
413
+	{
369 414
 		return $this->value;
370 415
 	}
371 416
 
@@ -379,14 +424,17 @@  discard block
 block discarded – undo
379 424
 	 * @param string Cookie header value (from a Set-Cookie header)
380 425
 	 * @return Requests_Cookie Parsed cookie object
381 426
 	 */
382
-	public static function parse($string, $name = '', $reference_time = null) {
427
+	public static function parse($string, $name = '', $reference_time = null)
428
+	{
383 429
 		$parts = explode(';', $string);
384 430
 		$kvparts = array_shift($parts);
385 431
 
386
-		if (!empty($name)) {
432
+		if (!empty($name))
433
+		{
387 434
 			$value = $string;
388 435
 		}
389
-		elseif (strpos($kvparts, '=') === false) {
436
+		elseif (strpos($kvparts, '=') === false)
437
+		{
390 438
 			// Some sites might only have a value without the equals separator.
391 439
 			// Deviate from RFC 6265 and pretend it was actually a blank name
392 440
 			// (`=foo`)
@@ -395,7 +443,8 @@  discard block
 block discarded – undo
395 443
 			$name = '';
396 444
 			$value = $kvparts;
397 445
 		}
398
-		else {
446
+		else
447
+		{
399 448
 			list($name, $value) = explode('=', $kvparts, 2);
400 449
 		}
401 450
 		$name = trim($name);
@@ -404,13 +453,17 @@  discard block
 block discarded – undo
404 453
 		// Attribute key are handled case-insensitively
405 454
 		$attributes = new Requests_Utility_CaseInsensitiveDictionary();
406 455
 
407
-		if (!empty($parts)) {
408
-			foreach ($parts as $part) {
409
-				if (strpos($part, '=') === false) {
456
+		if (!empty($parts))
457
+		{
458
+			foreach ($parts as $part)
459
+			{
460
+				if (strpos($part, '=') === false)
461
+				{
410 462
 					$part_key = $part;
411 463
 					$part_value = true;
412 464
 				}
413
-				else {
465
+				else
466
+				{
414 467
 					list($part_key, $part_value) = explode('=', $part, 2);
415 468
 					$part_value = trim($part_value);
416 469
 				}
@@ -431,43 +484,52 @@  discard block
 block discarded – undo
431 484
 	 * @param int|null $time Reference time for expiration calculation
432 485
 	 * @return array
433 486
 	 */
434
-	public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) {
487
+	public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null)
488
+	{
435 489
 		$cookie_headers = $headers->getValues('Set-Cookie');
436
-		if (empty($cookie_headers)) {
490
+		if (empty($cookie_headers))
491
+		{
437 492
 			return array();
438 493
 		}
439 494
 
440 495
 		$cookies = array();
441
-		foreach ($cookie_headers as $header) {
496
+		foreach ($cookie_headers as $header)
497
+		{
442 498
 			$parsed = self::parse($header, '', $time);
443 499
 
444 500
 			// Default domain/path attributes
445
-			if (empty($parsed->attributes['domain']) && !empty($origin)) {
501
+			if (empty($parsed->attributes['domain']) && !empty($origin))
502
+			{
446 503
 				$parsed->attributes['domain'] = $origin->host;
447 504
 				$parsed->flags['host-only'] = true;
448 505
 			}
449
-			else {
506
+			else
507
+			{
450 508
 				$parsed->flags['host-only'] = false;
451 509
 			}
452 510
 
453 511
 			$path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/');
454
-			if (!$path_is_valid && !empty($origin)) {
512
+			if (!$path_is_valid && !empty($origin))
513
+			{
455 514
 				$path = $origin->path;
456 515
 
457 516
 				// Default path normalization as per RFC 6265 section 5.1.4
458
-				if (substr($path, 0, 1) !== '/') {
517
+				if (substr($path, 0, 1) !== '/')
518
+				{
459 519
 					// If the uri-path is empty or if the first character of
460 520
 					// the uri-path is not a %x2F ("/") character, output
461 521
 					// %x2F ("/") and skip the remaining steps.
462 522
 					$path = '/';
463 523
 				}
464
-				elseif (substr_count($path, '/') === 1) {
524
+				elseif (substr_count($path, '/') === 1)
525
+				{
465 526
 					// If the uri-path contains no more than one %x2F ("/")
466 527
 					// character, output %x2F ("/") and skip the remaining
467 528
 					// step.
468 529
 					$path = '/';
469 530
 				}
470
-				else {
531
+				else
532
+				{
471 533
 					// Output the characters of the uri-path from the first
472 534
 					// character up to, but not including, the right-most
473 535
 					// %x2F ("/").
@@ -477,7 +539,8 @@  discard block
 block discarded – undo
477 539
 			}
478 540
 
479 541
 			// Reject invalid cookie domains
480
-			if (!empty($origin) && !$parsed->domain_matches($origin->host)) {
542
+			if (!empty($origin) && !$parsed->domain_matches($origin->host))
543
+			{
481 544
 				continue;
482 545
 			}
483 546
 
@@ -494,7 +557,8 @@  discard block
 block discarded – undo
494 557
 	 * @deprecated Use {@see Requests_Cookie::parse_from_headers}
495 558
 	 * @return string
496 559
 	 */
497
-	public static function parseFromHeaders(Requests_Response_Headers $headers) {
560
+	public static function parseFromHeaders(Requests_Response_Headers $headers)
561
+	{
498 562
 		return self::parse_from_headers($headers);
499 563
 	}
500 564
 }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
 	 * @param string $value
65 65
 	 * @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
66 66
 	 */
67
-	public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) {
67
+	public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = NULL) {
68 68
 		$this->name = $name;
69 69
 		$this->value = $value;
70 70
 		$this->attributes = $attributes;
71 71
 		$default_flags = array(
72 72
 			'creation' => time(),
73 73
 			'last-access' => time(),
74
-			'persistent' => false,
75
-			'host-only' => true,
74
+			'persistent' => FALSE,
75
+			'host-only' => TRUE,
76 76
 		);
77 77
 		$this->flags = array_merge($default_flags, $flags);
78 78
 
79 79
 		$this->reference_time = time();
80
-		if ($reference_time !== null) {
80
+		if ($reference_time !== NULL) {
81 81
 			$this->reference_time = $reference_time;
82 82
 		}
83 83
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 			return $expires < $this->reference_time;
108 108
 		}
109 109
 
110
-		return false;
110
+		return FALSE;
111 111
 	}
112 112
 
113 113
 	/**
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function uri_matches(Requests_IRI $uri) {
120 120
 		if (!$this->domain_matches($uri->host)) {
121
-			return false;
121
+			return FALSE;
122 122
 		}
123 123
 
124 124
 		if (!$this->path_matches($uri->path)) {
125
-			return false;
125
+			return FALSE;
126 126
 		}
127 127
 
128 128
 		return empty($this->attributes['secure']) || $uri->scheme === 'https';
@@ -138,37 +138,37 @@  discard block
 block discarded – undo
138 138
 		if (!isset($this->attributes['domain'])) {
139 139
 			// Cookies created manually; cookies created by Requests will set
140 140
 			// the domain to the requested domain
141
-			return true;
141
+			return TRUE;
142 142
 		}
143 143
 
144 144
 		$domain_string = $this->attributes['domain'];
145 145
 		if ($domain_string === $string) {
146 146
 			// The domain string and the string are identical.
147
-			return true;
147
+			return TRUE;
148 148
 		}
149 149
 
150 150
 		// If the cookie is marked as host-only and we don't have an exact
151 151
 		// match, reject the cookie
152
-		if ($this->flags['host-only'] === true) {
153
-			return false;
152
+		if ($this->flags['host-only'] === TRUE) {
153
+			return FALSE;
154 154
 		}
155 155
 
156 156
 		if (strlen($string) <= strlen($domain_string)) {
157 157
 			// For obvious reasons, the string cannot be a suffix if the domain
158 158
 			// is shorter than the domain string
159
-			return false;
159
+			return FALSE;
160 160
 		}
161 161
 
162 162
 		if (substr($string, -1 * strlen($domain_string)) !== $domain_string) {
163 163
 			// The domain string should be a suffix of the string.
164
-			return false;
164
+			return FALSE;
165 165
 		}
166 166
 
167 167
 		$prefix = substr($string, 0, strlen($string) - strlen($domain_string));
168 168
 		if (substr($prefix, -1) !== '.') {
169 169
 			// The last character of the string that is not included in the
170 170
 			// domain string should be a %x2E (".") character.
171
-			return false;
171
+			return FALSE;
172 172
 		}
173 173
 
174 174
 		// The string should be a host name (i.e., not an IP address).
@@ -192,32 +192,32 @@  discard block
 block discarded – undo
192 192
 		if (!isset($this->attributes['path'])) {
193 193
 			// Cookies created manually; cookies created by Requests will set
194 194
 			// the path to the requested path
195
-			return true;
195
+			return TRUE;
196 196
 		}
197 197
 
198 198
 		$cookie_path = $this->attributes['path'];
199 199
 
200 200
 		if ($cookie_path === $request_path) {
201 201
 			// The cookie-path and the request-path are identical.
202
-			return true;
202
+			return TRUE;
203 203
 		}
204 204
 
205 205
 		if (strlen($request_path) > strlen($cookie_path) && substr($request_path, 0, strlen($cookie_path)) === $cookie_path) {
206 206
 			if (substr($cookie_path, -1) === '/') {
207 207
 				// The cookie-path is a prefix of the request-path, and the last
208 208
 				// character of the cookie-path is %x2F ("/").
209
-				return true;
209
+				return TRUE;
210 210
 			}
211 211
 
212 212
 			if (substr($request_path, strlen($cookie_path), 1) === '/') {
213 213
 				// The cookie-path is a prefix of the request-path, and the
214 214
 				// first character of the request-path that is not included in
215 215
 				// the cookie-path is a %x2F ("/") character.
216
-				return true;
216
+				return TRUE;
217 217
 			}
218 218
 		}
219 219
 
220
-		return false;
220
+		return FALSE;
221 221
 	}
222 222
 
223 223
 	/**
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		foreach ($this->attributes as $key => $value) {
230 230
 			$orig_value = $value;
231 231
 			$value = $this->normalize_attribute($key, $value);
232
-			if ($value === null) {
232
+			if ($value === NULL) {
233 233
 				unset($this->attributes[$key]);
234 234
 				continue;
235 235
 			}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 			}
240 240
 		}
241 241
 
242
-		return true;
242
+		return TRUE;
243 243
 	}
244 244
 
245 245
 	/**
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
 				}
261 261
 
262 262
 				$expiry_time = strtotime($value);
263
-				if ($expiry_time === false) {
264
-					return null;
263
+				if ($expiry_time === FALSE) {
264
+					return NULL;
265 265
 				}
266 266
 
267 267
 				return $expiry_time;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 
275 275
 				// Check that we have a valid age
276 276
 				if (!preg_match('/^-?\d+$/', $value)) {
277
-					return null;
277
+					return NULL;
278 278
 				}
279 279
 
280 280
 				$delta_seconds = (int) $value;
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 	 * @param string Cookie header value (from a Set-Cookie header)
380 380
 	 * @return Requests_Cookie Parsed cookie object
381 381
 	 */
382
-	public static function parse($string, $name = '', $reference_time = null) {
382
+	public static function parse($string, $name = '', $reference_time = NULL) {
383 383
 		$parts = explode(';', $string);
384 384
 		$kvparts = array_shift($parts);
385 385
 
386 386
 		if (!empty($name)) {
387 387
 			$value = $string;
388 388
 		}
389
-		elseif (strpos($kvparts, '=') === false) {
389
+		elseif (strpos($kvparts, '=') === FALSE) {
390 390
 			// Some sites might only have a value without the equals separator.
391 391
 			// Deviate from RFC 6265 and pretend it was actually a blank name
392 392
 			// (`=foo`)
@@ -406,9 +406,9 @@  discard block
 block discarded – undo
406 406
 
407 407
 		if (!empty($parts)) {
408 408
 			foreach ($parts as $part) {
409
-				if (strpos($part, '=') === false) {
409
+				if (strpos($part, '=') === FALSE) {
410 410
 					$part_key = $part;
411
-					$part_value = true;
411
+					$part_value = TRUE;
412 412
 				}
413 413
 				else {
414 414
 					list($part_key, $part_value) = explode('=', $part, 2);
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	 * @param int|null $time Reference time for expiration calculation
432 432
 	 * @return array
433 433
 	 */
434
-	public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = null, $time = null) {
434
+	public static function parse_from_headers(Requests_Response_Headers $headers, Requests_IRI $origin = NULL, $time = NULL) {
435 435
 		$cookie_headers = $headers->getValues('Set-Cookie');
436 436
 		if (empty($cookie_headers)) {
437 437
 			return array();
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
 			// Default domain/path attributes
445 445
 			if (empty($parsed->attributes['domain']) && !empty($origin)) {
446 446
 				$parsed->attributes['domain'] = $origin->host;
447
-				$parsed->flags['host-only'] = true;
447
+				$parsed->flags['host-only'] = TRUE;
448 448
 			}
449 449
 			else {
450
-				$parsed->flags['host-only'] = false;
450
+				$parsed->flags['host-only'] = FALSE;
451 451
 			}
452 452
 
453 453
 			$path_is_valid = (!empty($parsed->attributes['path']) && $parsed->attributes['path'][0] === '/');
Please login to merge, or discard this patch.
php/Requests/libary/Requests/Exception/Transport/cURL.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -29,6 +29,9 @@
 block discarded – undo
29 29
 	 */
30 30
 	protected $reason = 'Unknown';
31 31
 
32
+	/**
33
+	 * @param string $message
34
+	 */
32 35
 	public function __construct($message, $type, $data = null, $code = 0) {
33 36
 		if ($type !== null) {
34 37
 			$this->type = $type;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@
 block discarded – undo
30 30
 	protected $reason = 'Unknown';
31 31
 
32 32
 	public function __construct($message, $type, $data = null, $code = 0) {
33
-		if ($type !== null) {
33
+		if($type !== null) {
34 34
 			$this->type = $type;
35 35
 		}
36 36
 
37
-		if ($code !== null) {
37
+		if($code !== null) {
38 38
 			$this->code = $code;
39 39
 		}
40 40
 
41
-		if ($message !== null) {
41
+		if($message !== null) {
42 42
 			$this->reason = $message;
43 43
 		}
44 44
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class Requests_Exception_Transport_cURL extends Requests_Exception_Transport {
3
+class Requests_Exception_Transport_cURL extends Requests_Exception_Transport
4
+{
4 5
 
5 6
 	const EASY = 'cURLEasy';
6 7
 	const MULTI = 'cURLMulti';
@@ -29,16 +30,20 @@  discard block
 block discarded – undo
29 30
 	 */
30 31
 	protected $reason = 'Unknown';
31 32
 
32
-	public function __construct($message, $type, $data = null, $code = 0) {
33
-		if ($type !== null) {
33
+	public function __construct($message, $type, $data = null, $code = 0)
34
+	{
35
+		if ($type !== null)
36
+		{
34 37
 			$this->type = $type;
35 38
 		}
36 39
 
37
-		if ($code !== null) {
40
+		if ($code !== null)
41
+		{
38 42
 			$this->code = $code;
39 43
 		}
40 44
 
41
-		if ($message !== null) {
45
+		if ($message !== null)
46
+		{
42 47
 			$this->reason = $message;
43 48
 		}
44 49
 
@@ -49,7 +54,8 @@  discard block
 block discarded – undo
49 54
 	/**
50 55
 	 * Get the error message
51 56
 	 */
52
-	public function getReason() {
57
+	public function getReason()
58
+	{
53 59
 		return $this->reason;
54 60
 	}
55 61
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,16 +29,16 @@
 block discarded – undo
29 29
 	 */
30 30
 	protected $reason = 'Unknown';
31 31
 
32
-	public function __construct($message, $type, $data = null, $code = 0) {
33
-		if ($type !== null) {
32
+	public function __construct($message, $type, $data = NULL, $code = 0) {
33
+		if ($type !== NULL) {
34 34
 			$this->type = $type;
35 35
 		}
36 36
 
37
-		if ($code !== null) {
37
+		if ($code !== NULL) {
38 38
 			$this->code = $code;
39 39
 		}
40 40
 
41
-		if ($message !== null) {
41
+		if ($message !== NULL) {
42 42
 			$this->reason = $message;
43 43
 		}
44 44
 
Please login to merge, or discard this patch.