WordPress / Requests

Compare f454910 ... +25 ... b4dc1ee

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -184,6 +184,25 @@
Loading
184 184
	 */
185 185
	protected static $certificate_path;
186 186
187 +
	/**
188 +
	 * All (known) valid deflate, gzip header magic markers.
189 +
	 *
190 +
	 * These markers relate to different compression levels.
191 +
	 *
192 +
	 * @link https://stackoverflow.com/a/43170354/482864 Marker source.
193 +
	 *
194 +
	 * @since 2.0.0
195 +
	 *
196 +
	 * @var array
197 +
	 */
198 +
	private static $magic_compression_headers = array(
199 +
		"\x1f\x8b" => true, // Gzip marker.
200 +
		"\x78\x01" => true, // Zlib marker - level 1.
201 +
		"\x78\x5e" => true, // Zlib marker - level 2 to 5.
202 +
		"\x78\x9c" => true, // Zlib marker - level 6.
203 +
		"\x78\xda" => true, // Zlib marker - level 7 to 9.
204 +
	);
205 +
187 206
	/**
188 207
	 * This is a static class, do not instantiate it
189 208
	 *
@@ -823,7 +842,8 @@
Loading
823 842
	 * @return string Decompressed string
824 843
	 */
825 844
	public static function decompress($data) {
826 -
		if (substr($data, 0, 2) !== "\x1f\x8b" && substr($data, 0, 2) !== "\x78\x9c") {
845 +
		$marker = substr($data, 0, 2);
846 +
		if (!isset(self::$magic_compression_headers[$marker])) {
827 847
			// Not actually compressed. Probably cURL ruining this for us.
828 848
			return $data;
829 849
		}

@@ -47,7 +47,10 @@
Loading
47 47
	 */
48 48
	#[ReturnTypeWillChange]
49 49
	public function offsetExists($offset) {
50 -
		$offset = strtolower($offset);
50 +
		if (is_string($offset)) {
51 +
			$offset = strtolower($offset);
52 +
		}
53 +
51 54
		return isset($this->data[$offset]);
52 55
	}
53 56
@@ -59,7 +62,10 @@
Loading
59 62
	 */
60 63
	#[ReturnTypeWillChange]
61 64
	public function offsetGet($offset) {
62 -
		$offset = strtolower($offset);
65 +
		if (is_string($offset)) {
66 +
			$offset = strtolower($offset);
67 +
		}
68 +
63 69
		if (!isset($this->data[$offset])) {
64 70
			return null;
65 71
		}
@@ -81,7 +87,10 @@
Loading
81 87
			throw new Exception('Object is a dictionary, not a list', 'invalidset');
82 88
		}
83 89
84 -
		$offset              = strtolower($offset);
90 +
		if (is_string($offset)) {
91 +
			$offset = strtolower($offset);
92 +
		}
93 +
85 94
		$this->data[$offset] = $value;
86 95
	}
87 96
@@ -92,7 +101,11 @@
Loading
92 101
	 */
93 102
	#[ReturnTypeWillChange]
94 103
	public function offsetUnset($offset) {
95 -
		unset($this->data[strtolower($offset)]);
104 +
		if (is_string($offset)) {
105 +
			$offset = strtolower($offset);
106 +
		}
107 +
108 +
		unset($this->data[$offset]);
96 109
	}
97 110
98 111
	/**

@@ -33,9 +33,10 @@
Loading
33 33
	 */
34 34
	public function register($hook, $callback, $priority = 0) {
35 35
		if (!isset($this->hooks[$hook])) {
36 -
			$this->hooks[$hook] = array();
37 -
		}
38 -
		if (!isset($this->hooks[$hook][$priority])) {
36 +
			$this->hooks[$hook] = array(
37 +
				$priority => array(),
38 +
			);
39 +
		} elseif (!isset($this->hooks[$hook][$priority])) {
39 40
			$this->hooks[$hook][$priority] = array();
40 41
		}
41 42

@@ -0,0 +1,111 @@
Loading
1 +
<?php
2 +
/**
3 +
 * Input validation utilities.
4 +
 *
5 +
 * @package Requests
6 +
 * @subpackage Utilities
7 +
 */
8 +
9 +
namespace WpOrg\Requests\Utility;
10 +
11 +
use ArrayAccess;
12 +
use CurlHandle;
13 +
use Traversable;
14 +
15 +
/**
16 +
 * Input validation utilities.
17 +
 *
18 +
 * @package Requests
19 +
 * @subpackage Utilities
20 +
 */
21 +
final class InputValidator {
22 +
23 +
	/**
24 +
	 * Verify that a received input parameter is of type string or is "stringable".
25 +
	 *
26 +
	 * @param mixed $input Input parameter to verify.
27 +
	 *
28 +
	 * @return bool
29 +
	 */
30 +
	public static function is_string_or_stringable($input) {
31 +
		return is_string($input) || self::is_stringable_object($input);
32 +
	}
33 +
34 +
	/**
35 +
	 * Verify whether a received input parameter is usable as an integer array key.
36 +
	 *
37 +
	 * @param mixed $input Input parameter to verify.
38 +
	 *
39 +
	 * @return bool
40 +
	 */
41 +
	public static function is_numeric_array_key($input) {
42 +
		if (is_int($input)) {
43 +
			return true;
44 +
		}
45 +
46 +
		if (!is_string($input)) {
47 +
			return false;
48 +
		}
49 +
50 +
		return (bool) preg_match('`^-?[0-9]+$`', $input);
51 +
	}
52 +
53 +
	/**
54 +
	 * Verify whether a received input parameter is "stringable".
55 +
	 *
56 +
	 * @param mixed $input Input parameter to verify.
57 +
	 *
58 +
	 * @return bool
59 +
	 */
60 +
	public static function is_stringable_object($input) {
61 +
		return is_object($input) && method_exists($input, '__toString');
62 +
	}
63 +
64 +
	/**
65 +
	 * Verify whether a received input parameter is _accessible as if it were an array_.
66 +
	 *
67 +
	 * @param mixed $input Input parameter to verify.
68 +
	 *
69 +
	 * @return bool
70 +
	 */
71 +
	public static function has_array_access($input) {
72 +
		return is_array($input) || $input instanceof ArrayAccess;
73 +
	}
74 +
75 +
	/**
76 +
	 * Verify whether a received input parameter is "iterable".
77 +
	 *
78 +
	 * @internal The PHP native `is_iterable()` function was only introduced in PHP 7.1
79 +
	 * and this library still supports PHP 5.6.
80 +
	 *
81 +
	 * @param mixed $input Input parameter to verify.
82 +
	 *
83 +
	 * @return bool
84 +
	 */
85 +
	public static function is_iterable($input) {
86 +
		return is_array($input) || $input instanceof Traversable;
87 +
	}
88 +
89 +
	/**
90 +
	 * Verify whether a received input parameter is a Curl handle.
91 +
	 *
92 +
	 * The PHP Curl extension worked with resources prior to PHP 8.0 and with
93 +
	 * an instance of the `CurlHandle` class since PHP 8.0.
94 +
	 * {@link https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object}
95 +
	 *
96 +
	 * @param mixed $input Input parameter to verify.
97 +
	 *
98 +
	 * @return bool
99 +
	 */
100 +
	public static function is_curl_handle($input) {
101 +
		if (is_resource($input)) {
102 +
			return get_resource_type($input) === 'curl';
103 +
		}
104 +
105 +
		if (is_object($input)) {
106 +
			return $input instanceof CurlHandle;
107 +
		}
108 +
109 +
		return false;
110 +
	}
111 +
}

Learn more Showing 4 files with coverage changes found.

Changes in src/Iri.php
-4
+4
Loading file...
Changes in src/Requests.php
-2
+2
Loading file...
New file src/Utility/InputValidator.php
New
Loading file...
Changes in src/Utility/CaseInsensitiveDictionary.php
-2
+2
Loading file...

27 Commits

Hiding 2 contexual commits
+6
+6
Hiding 7 contexual commits
+1 Files
+27
+24
+3
-5
-8
+3
+5
+14
-9
Hiding 4 contexual commits
-1
-7
+6
Hiding 1 contexual commits
+1
+1
-1 Files
-20
-20
+1 Files
+20
+25
-5
Hiding 2 contexual commits
-6
-11
+5
Files Complexity Coverage
src ø -0.05% 92.11%
Project Totals (25 files) 841 92.11%
Loading