Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ jobs:
coverage: ['xdebug']
code-style: ['no']
code-analysis: ['no']
rector-check: ['no']
include:
- php-versions: '7.4'
coverage: 'xdebug'
code-style: 'yes'
code-analysis: 'yes'
rector-check: ['no']
- php-versions: '8.5'
coverage: 'xdebug'
code-style: 'no'
code-analysis: 'yes'
rector-check: ['yes']
steps:
- name: Checkout
uses: actions/checkout@v6
Expand Down Expand Up @@ -62,6 +65,10 @@ jobs:
- name: Run application server
run: php -S localhost:8000 -t tests/www 2>/dev/null &

- name: Code Refactoring (rector)
if: matrix.rector-check == 'yes'
run: composer rector-check

- name: Test with phpunit
run: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml

Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/extension-installer": "^1.4",
"phpunit/phpunit" : "^9.6"
"phpunit/phpunit" : "^9.6",
"rector/rector": "^2.4"
},
"suggest" : {
"ext-curl" : " to make http requests with the Client class"
Expand Down Expand Up @@ -55,6 +56,12 @@
"cs-fixer": [
"PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix"
],
"rector-check": [
"rector process --dry-run"
],
"rector-fix": [
"rector process"
],
"phpunit": [
"phpunit --configuration tests/phpunit.xml"
],
Expand Down
4 changes: 2 additions & 2 deletions examples/asyncclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
$request,

// This is the 'success' callback
function ($response) use ($i) {
function ($response) use ($i): void {
echo "$i -> ".$response->getStatus()."\n";
},

// This is the 'error' callback. It is called for general connection
// problems (such as not being able to connect to a host, dns errors,
// etc.) and also cases where a response was returned, but it had a
// status code of 400 or higher.
function ($error) use ($i) {
function ($error) use ($i): void {
if (Client::STATUS_CURLERROR === $error['status']) {
// Curl errors
echo "$i -> curl error: ".$error['curl_errmsg']."\n";
Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/AWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function init(): bool
return false;
}

list($this->accessKey, $this->signature) = explode(':', $authHeader[1]);
[$this->accessKey, $this->signature] = explode(':', $authHeader[1]);

return true;
}
Expand Down
8 changes: 2 additions & 6 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct()
{
// See https://github.com/sabre-io/http/pull/115#discussion_r241292068
// Preserve compatibility for sub-classes that implement their own method `parseCurlResult`
$separatedHeaders = __CLASS__ === get_class($this);
$separatedHeaders = self::class === get_class($this);

$this->curlSettings = [
CURLOPT_RETURNTRANSFER => true,
Expand Down Expand Up @@ -217,11 +217,7 @@ public function poll(): bool
if ($status && CURLMSG_DONE === $status['msg']) {
$resourceId = (int) $status['handle'];

list(
$request,
$successCallback,
$errorCallback,
$retryCount) = $this->curlMultiMap[$resourceId];
[$request, $successCallback, $errorCallback, $retryCount] = $this->curlMultiMap[$resourceId];
unset($this->curlMultiMap[$resourceId]);

$curlHandle = $status['handle'];
Expand Down
4 changes: 2 additions & 2 deletions lib/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function getPath(): string

if (0 === strpos($uri, $baseUri)) {
// We're not interested in the query part (everything after the ?).
list($uri) = explode('?', $uri);
[$uri] = explode('?', $uri);

return trim(decodePath(substr($uri, strlen($baseUri))), '/');
}
Expand Down Expand Up @@ -260,7 +260,7 @@ public function __toString(): string
foreach ($this->getHeaders() as $key => $value) {
foreach ($value as $v) {
if ('Authorization' === $key) {
list($v) = explode(' ', $v, 2);
[$v] = explode(' ', $v, 2);
$v .= ' REDACTED';
}
$out .= $key.': '.$v."\r\n";
Expand Down
12 changes: 4 additions & 8 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ function parseMimeType(string $str): array
// Illegal value
throw new \InvalidArgumentException('Not a valid mime-type: '.$str);
}
list($type, $subType) = $mimeType;
[$type, $subType] = $mimeType;

foreach ($parts as $part) {
$part = trim($part);
if (strpos($part, '=')) {
list($partName, $partValue) =
[$partName, $partValue] =
explode('=', $part, 2);
} else {
$partName = $part;
Expand Down Expand Up @@ -374,9 +374,7 @@ function parseMimeType(string $str): array
*/
function encodePath(string $path): string
{
return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/', function ($match) {
return '%'.sprintf('%02x', ord($match[0]));
}, $path);
return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/', fn ($match) => '%'.sprintf('%02x', ord($match[0])), $path);
}

/**
Expand All @@ -386,9 +384,7 @@ function encodePath(string $path): string
*/
function encodePathSegment(string $pathSegment): string
{
return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/', function ($match) {
return '%'.sprintf('%02x', ord($match[0]));
}, $pathSegment);
return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/', fn ($match) => '%'.sprintf('%02x', ord($match[0])), $pathSegment);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__.'/examples',
__DIR__.'/lib',
__DIR__.'/tests',
])
->withPhpSets(false, false, false, false, true)
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
8 changes: 4 additions & 4 deletions tests/HTTP/Auth/DigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setUp(): void

public function testDigest(): void
{
list($nonce, $opaque) = $this->getServerTokens();
[$nonce, $opaque] = $this->getServerTokens();

$username = 'admin';
$password = '12345';
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testDigest(): void

public function testInvalidDigest(): void
{
list($nonce, $opaque) = $this->getServerTokens();
[$nonce, $opaque] = $this->getServerTokens();

$username = 'admin';
$password = 12345;
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testInvalidDigest2(): void
public function testDigestAuthInt(): void
{
$this->auth->setQOP(Digest::QOP_AUTHINT);
list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT);
[$nonce, $opaque] = $this->getServerTokens(Digest::QOP_AUTHINT);

$username = 'admin';
$password = 12345;
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testDigestAuthInt(): void
public function testDigestAuthBoth(): void
{
$this->auth->setQOP(Digest::QOP_AUTHINT | Digest::QOP_AUTH);
list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT | Digest::QOP_AUTH);
[$nonce, $opaque] = $this->getServerTokens(Digest::QOP_AUTHINT | Digest::QOP_AUTH);

$username = 'admin';
$password = 12345;
Expand Down
48 changes: 24 additions & 24 deletions tests/HTTP/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function testSend(): void
$client = new ClientMock();
$request = new Request('GET', 'http://example.org/');

$client->on('doRequest', function ($request, &$response) {
$client->on('doRequest', function ($request, &$response): void {
$response = new Response(200);
});

Expand Down Expand Up @@ -231,7 +231,7 @@ public function testSendToGetLargeContent(): void
$maxPeakMemoryUsageEnvVariable = 'SABRE_HTTP_TEST_GET_LARGE_CONTENT_MAX_PEAK_MEMORY_USAGE';
$maxPeakMemoryUsage = \getenv($maxPeakMemoryUsageEnvVariable);
if (false === $maxPeakMemoryUsage) {
$maxPeakMemoryUsage = 60 * pow(1024, 2);
$maxPeakMemoryUsage = 60 * 1024 ** 2;
}

$request = new Request('GET', $url);
Expand Down Expand Up @@ -259,11 +259,11 @@ public function testSendAsync(): void
$client = new Client();

$request = new Request('GET', $url);
$client->sendAsync($request, function (ResponseInterface $response) {
$client->sendAsync($request, function (ResponseInterface $response): void {
self::assertEquals("foo\n", $response->getBody());
self::assertEquals(200, $response->getStatus());
self::assertEquals(4, $response->getHeader('Content-Length'));
}, function ($error) use ($request) {
}, function ($error) use ($request): void {
$url = $request->getUrl();
self::fail("Failed to GET $url");
});
Expand All @@ -284,22 +284,22 @@ public function testSendAsynConsecutively(): void
$client = new Client();

$request = new Request('GET', $url);
$client->sendAsync($request, function (ResponseInterface $response) {
$client->sendAsync($request, function (ResponseInterface $response): void {
self::assertEquals("foo\n", $response->getBody());
self::assertEquals(200, $response->getStatus());
self::assertEquals(4, $response->getHeader('Content-Length'));
}, function ($error) use ($request) {
}, function ($error) use ($request): void {
$url = $request->getUrl();
self::fail("Failed to get $url");
});

$url = $this->getAbsoluteUrl('/bar.php');
$request = new Request('GET', $url);
$client->sendAsync($request, function (ResponseInterface $response) {
$client->sendAsync($request, function (ResponseInterface $response): void {
self::assertEquals("bar\n", $response->getBody());
self::assertEquals(200, $response->getStatus());
self::assertEquals('Bar', $response->getHeader('X-Test'));
}, function ($error) use ($request) {
}, function ($error) use ($request): void {
$url = $request->getUrl();
self::fail("Failed to get $url");
});
Expand All @@ -312,11 +312,11 @@ public function testSendClientError(): void
$client = new ClientMock();
$request = new Request('GET', 'http://example.org/');

$client->on('doRequest', function ($request, &$response) {
$client->on('doRequest', function ($request, &$response): void {
throw new ClientException('aaah', 1);
});
$called = false;
$client->on('exception', function () use (&$called) {
$client->on('exception', function () use (&$called): void {
$called = true;
});

Expand All @@ -333,14 +333,14 @@ public function testSendHttpError(): void
$client = new ClientMock();
$request = new Request('GET', 'http://example.org/');

$client->on('doRequest', function ($request, &$response) {
$client->on('doRequest', function ($request, &$response): void {
$response = new Response(404);
});
$called = 0;
$client->on('error', function () use (&$called) {
$client->on('error', function () use (&$called): void {
++$called;
});
$client->on('error:404', function () use (&$called) {
$client->on('error:404', function () use (&$called): void {
++$called;
});

Expand All @@ -354,7 +354,7 @@ public function testSendRetry(): void
$request = new Request('GET', 'http://example.org/');

$called = 0;
$client->on('doRequest', function ($request, &$response) use (&$called) {
$client->on('doRequest', function ($request, &$response) use (&$called): void {
++$called;
if ($called < 3) {
$response = new Response(404);
Expand All @@ -364,7 +364,7 @@ public function testSendRetry(): void
});

$errorCalled = 0;
$client->on('error', function ($request, $response, &$retry, $retryCount) use (&$errorCalled) {
$client->on('error', function ($request, $response, &$retry, $retryCount) use (&$errorCalled): void {
++$errorCalled;
$retry = true;
});
Expand All @@ -381,7 +381,7 @@ public function testHttpErrorException(): void
$client->setThrowExceptions(true);
$request = new Request('GET', 'http://example.org/');

$client->on('doRequest', function ($request, &$response) {
$client->on('doRequest', function ($request, &$response): void {
$response = new Response(404);
});

Expand All @@ -390,14 +390,14 @@ public function testHttpErrorException(): void
self::fail('An exception should have been thrown');
} catch (ClientHttpException $e) {
self::assertEquals(404, $e->getHttpStatus());
self::assertInstanceOf('Sabre\HTTP\Response', $e->getResponse());
self::assertInstanceOf(Response::class, $e->getResponse());
}
}

public function testParseCurlResult(): void
{
$client = new ClientMock();
$client->on('curlStuff', function (&$return) {
$client->on('curlStuff', function (&$return): void {
$return = [
[
'header_size' => 33,
Expand All @@ -422,7 +422,7 @@ public function testParseCurlResult(): void
public function testParseCurlResultEmptyBody(): void
{
$client = new ClientMock();
$client->on('curlStuff', function (&$return) {
$client->on('curlStuff', function (&$return): void {
$return = [
[
'header_size' => 33,
Expand All @@ -447,7 +447,7 @@ public function testParseCurlResultEmptyBody(): void
public function testParseCurlError(): void
{
$client = new ClientMock();
$client->on('curlStuff', function (&$return) {
$client->on('curlStuff', function (&$return): void {
$return = [
[],
1,
Expand All @@ -468,10 +468,10 @@ public function testDoRequest(): void
{
$client = new ClientMock();
$request = new Request('GET', 'http://example.org/');
$client->on('curlExec', function (&$return) {
$client->on('curlExec', function (&$return): void {
$return = "HTTP/1.1 200 OK\r\nHeader1:Val1\r\n\r\nFoo";
});
$client->on('curlStuff', function (&$return) {
$client->on('curlStuff', function (&$return): void {
$return = [
[
'header_size' => 33,
Expand All @@ -491,10 +491,10 @@ public function testDoRequestCurlError(): void
{
$client = new ClientMock();
$request = new Request('GET', 'http://example.org/');
$client->on('curlExec', function (&$return) {
$client->on('curlExec', function (&$return): void {
$return = '';
});
$client->on('curlStuff', function (&$return) {
$client->on('curlStuff', function (&$return): void {
$return = [
[],
1,
Expand Down
Loading
Loading