Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS/QA: various minor fixes #881

Merged
merged 7 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// Now let's make a request via a proxy.
$options = [
'proxy' => '127.0.0.1:8080', // syntax: host:port, eg 12.13.14.14:8080 or someproxy.com:3128
'proxy' => '127.0.0.1:8080', // Syntax: host:port, eg 12.13.14.14:8080 or someproxy.com:3128
// If you need to authenticate, use the following syntax:
// 'proxy' => array( '127.0.0.1:8080', 'username', 'password' ),
];
Expand Down
8 changes: 4 additions & 4 deletions src/Auth/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public function register(Hooks $hooks) {
}

/**
* Set cURL parameters before the data is sent
* Set cURL parameters before the data is sent.
*
* @param resource|\CurlHandle $handle cURL handle
jrfnl marked this conversation as resolved.
Show resolved Hide resolved
* @param resource|\CurlHandle $handle The cURL handle.
*/
public function curl_before_send(&$handle) {
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString());
}

/**
* Add extra headers to the request before sending
* Add extra headers to the request before sending.
*
* @param string $out HTTP header string
* @param string $out HTTP header string.
*/
public function fsockopen_header(&$out) {
$out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
Expand Down
2 changes: 1 addition & 1 deletion src/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Capability {
*
* Note: this does not automatically mean that the capability will be supported for your chosen transport!
*
* @var string[]
* @var array<string>
*/
const ALL = [
self::SSL,
Expand Down
2 changes: 1 addition & 1 deletion src/Cookie/Jar.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function offsetGet($offset) {
* @param string $offset Item name
* @param string $value Item value
*
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`).
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Ipv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function compress($ip) {
* 0:0:0:0:0:FFFF:129.144.52.38
*
* @param string $ip An IPv6 address
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
* @return array<string> [0] contains the IPv6 represented part, and [1] the IPv4 represented part
*/
private static function split_v6_v4($ip) {
if (strpos($ip, '.') !== false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use WpOrg\Requests\Utility\InputValidator;

/**
* cURL HTTP transport
* HTTP transport using libcurl.
*
* @package Requests\Transport
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/Cookie/IsExpiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public static function dataCookieExpiration() {
],
'Both max-age and expires keys set, max-age takes precedence, cookie not expired' => [
'attributes' => [
'max-age' => gmmktime(0, 0, 0, 2, 1, 2022),
'expires' => gmmktime(0, 0, 0, 12, 1, 2021),
'max-age' => gmmktime(0, 0, 0, 2, 1, 2022),
'expires' => gmmktime(0, 0, 0, 12, 1, 2021),
],
'expected' => false,
],
'Both max-age and expires keys set, max-age takes precedence, cookie expired' => [
'attributes' => [
'max-age' => gmmktime(0, 0, 0, 12, 1, 2021),
'expires' => gmmktime(0, 0, 0, 2, 1, 2022),
'max-age' => gmmktime(0, 0, 0, 12, 1, 2021),
'expires' => gmmktime(0, 0, 0, 2, 1, 2022),
],
'expected' => true,
],
Expand Down
4 changes: 2 additions & 2 deletions tests/Cookie/ParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,13 @@ private function check_parsed_cookie($cookie, $expected, $expected_attributes =
$this->assertSame($expected['expired'], $cookie->is_expired(), 'Cookie expiration identification does not match expectation');
}

if (isset($expected_attributes) && !empty($expected_attributes)) {
if (is_array($expected_attributes) && !empty($expected_attributes)) {
foreach ($expected_attributes as $attr_key => $attr_val) {
$this->assertSame($attr_val, $cookie->attributes[$attr_key], "Attribute '$attr_key' should match supplied value");
}
}

if (isset($expected_flags) && !empty($expected_flags)) {
if (is_array($expected_flags) && !empty($expected_flags)) {
foreach ($expected_flags as $flag_key => $flag_val) {
$this->assertSame($flag_val, $cookie->flags[$flag_key], "Flag '$flag_key' should match supplied value");
}
Expand Down
15 changes: 12 additions & 3 deletions tests/Response/Headers/FlattenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ public function testFlatten($input, $expected) {
*/
public static function dataFlatten() {
return [
'string' => ['text', 'text'],
'empty array' => [[], ''],
'array with values' => [['text', 10, 'more text'], 'text,10,more text'],
'string' => [
'input' => 'text',
'expected' => 'text',
],
'empty array' => [
'input' => [],
'expected' => '',
],
'array with values' => [
'input' => ['text', 10, 'more text'],
'expected' => 'text,10,more text',
],
];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Response/Headers/GetIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testIteration() {
$this->assertSame('10', $value, 'Content-Length header does not match');
break;
default:
throw new Exception('Invalid offset key: ' . $name);
throw new Exception('Invalid offset key: ' . $name, 'type');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static function transportProvider() {
/**
* Helper function to convert a single-level array containing text strings to a named data provider.
*
* @param string[] $input Input array.
* @param array<string> $input Input array.
*
* @return array[] Array which is usable as a test data provider with named data sets.
* @return array<array> Array which is usable as a test data provider with named data sets.
*/
public static function textArrayToDataprovider($input) {
$data = [];
Expand Down
11 changes: 10 additions & 1 deletion tests/Transport/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ abstract class BaseTestCase extends TestCase {

protected $completed = [];

/**
* Transport class to use for these tests.
*
* This property MUST be declared in the child class.
*
* @var string
*/
protected $transport;

public function set_up() {
// Intermediary variable $test_method. This can be simplified (removed) once the minimum supported PHP version is 7.0 or higher.
$test_method = [$this->transport, 'test'];
Expand Down Expand Up @@ -1198,7 +1207,7 @@ public function test303GETmethod() {
/**
* Get a Hooks instance that asserts correct enforcement for max_bytes.
*
* @return Hooks
* @return \WpOrg\Requests\Hooks
*/
protected function getMaxBytesAssertionHooks() {
$hooks = new Hooks();
Expand Down
38 changes: 19 additions & 19 deletions tests/TypeProviderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing null.
*
* @var string[]
* @var array<string>
*/
const GROUP_NULL = ['null'];

/**
* Keys of all type entries representing a boolean.
*
* @var string[]
* @var array<string>
*/
const GROUP_BOOL = [
'boolean false',
Expand All @@ -33,7 +33,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing an integer.
*
* @var string[]
* @var array<string>
*/
const GROUP_INT = [
'integer 0',
Expand All @@ -44,7 +44,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing a float.
*
* @var string[]
* @var array<string>
*/
const GROUP_FLOAT = [
'float 0.0',
Expand All @@ -55,7 +55,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing an integer or float.
*
* @var string[]
* @var array<string>
*/
const GROUP_INT_FLOAT = [
'integer 0',
Expand All @@ -69,7 +69,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing a string.
*
* @var string[]
* @var array<string>
*/
const GROUP_STRING = [
'empty string',
Expand All @@ -81,7 +81,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries which are stringable.
*
* @var string[]
* @var array<string>
*/
const GROUP_STRINGABLE = [
'empty string',
Expand All @@ -94,7 +94,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing an array.
*
* @var string[]
* @var array<string>
*/
const GROUP_ARRAY = [
'empty array',
Expand All @@ -105,7 +105,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries which are iterable.
*
* @var string[]
* @var array<string>
*/
const GROUP_ITERABLE = [
'empty array',
Expand All @@ -118,7 +118,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries which have array access.
*
* @var string[]
* @var array<string>
*/
const GROUP_ARRAY_ACCESSIBLE = [
'empty array',
Expand All @@ -131,7 +131,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing an object.
*
* @var string[]
* @var array<string>
*/
const GROUP_OBJECT = [
'plain object',
Expand All @@ -144,7 +144,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries representing a resource.
*
* @var string[]
* @var array<string>
*/
const GROUP_RESOURCE = [
'resource (open file handle)',
Expand All @@ -154,7 +154,7 @@ final class TypeProviderHelper {
/**
* Keys of all type entries which are considered empty.
*
* @var string[]
* @var array<string>
*/
const GROUP_EMPTY = [
'null',
Expand Down Expand Up @@ -198,9 +198,9 @@ public static function cleanUp() {
* Retrieve an array in data provider format with a selection of all typical PHP data types
* *except* the named types specified in the $except parameter.
*
* @param string[] ...$except One or more arrays containing the names of the types to exclude.
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
* @param array<string> ...$except One or more arrays containing the names of the types to exclude.
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
*
* @return array<string, array<mixed>>
*/
Expand All @@ -213,9 +213,9 @@ public static function getAllExcept(array ...$except) {
/**
* Retrieve an array in data provider format with a selection of typical PHP data types.
*
* @param string[] ...$selection One or more arrays containing the names of the types to include.
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
* @param array<string> ...$selection One or more arrays containing the names of the types to include.
* Typically, one or more of the predefined "groups" (see the constants)
* would be used here.
*
* @return array<string, array<mixed>>
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static function ($class_name) {
return false;
}

// Strip namespace prefix 'WpOrg\\Requests\Tests\'.
// Strip namespace prefix 'WpOrg\Requests\Tests\'.
$relative_class = substr($class_name, 21);
$file = realpath(__DIR__ . '/' . strtr($relative_class, '\\', '/') . '.php');

Expand Down