Skip to content

Commit

Permalink
Fixes for PHP 8.4 deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Mar 31, 2024
1 parent bbff78d commit 3e78ae0
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 36 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
->setRules([
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PSR12:risky' => true,
'@Symfony' => true,
'global_namespace_import' => false,
'no_superfluous_phpdoc_tags' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public static function of(callable $generatorFn): self
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return $this->result->then($onFulfilled, $onRejected);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class Each
*/
public static function of(
$iterable,
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return (new EachPromise($iterable, [
'fulfilled' => $onFulfilled,
Expand All @@ -46,8 +46,8 @@ public static function of(
public static function ofLimit(
$iterable,
$concurrency,
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return (new EachPromise($iterable, [
'fulfilled' => $onFulfilled,
Expand All @@ -67,7 +67,7 @@ public static function ofLimit(
public static function ofLimitAll(
$iterable,
$concurrency,
callable $onFulfilled = null
?callable $onFulfilled = null
): PromiseInterface {
return self::ofLimit(
$iterable,
Expand Down
4 changes: 2 additions & 2 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct($value)
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
// Return itself if there is no onFulfilled function.
if (!$onFulfilled) {
Expand Down
8 changes: 4 additions & 4 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class Promise implements PromiseInterface
* @param callable $cancelFn Fn that when invoked cancels the promise.
*/
public function __construct(
callable $waitFn = null,
callable $cancelFn = null
?callable $waitFn = null,
?callable $cancelFn = null
) {
$this->waitFn = $waitFn;
$this->cancelFn = $cancelFn;
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
if ($this->state === self::PENDING) {
$p = new Promise(null, [$this, 'cancel']);
Expand Down
4 changes: 2 additions & 2 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface PromiseInterface
* @param callable $onRejected Invoked when the promise is rejected.
*/
public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct($reason)
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
// If there's no onRejected callback then just return self.
if (!$onRejected) {
Expand Down
2 changes: 1 addition & 1 deletion src/RejectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RejectionException extends \RuntimeException
* @param mixed $reason Rejection reason.
* @param string|null $description Optional description.
*/
public function __construct($reason, string $description = null)
public function __construct($reason, ?string $description = null)
{
$this->reason = $reason;

Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Utils
*
* @param TaskQueueInterface|null $assign Optionally specify a new queue instance.
*/
public static function queue(TaskQueueInterface $assign = null): TaskQueueInterface
public static function queue(?TaskQueueInterface $assign = null): TaskQueueInterface
{
static $queue;

Expand Down
11 changes: 5 additions & 6 deletions tests/CoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace GuzzleHttp\Promise\Tests;

use GuzzleHttp\Promise as P;
use GuzzleHttp\Promise\Coroutine;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
Expand All @@ -16,7 +15,7 @@ class CoroutineTest extends TestCase
public function testReturnsCoroutine(): void
{
$fn = function () { yield 'foo'; };
$this->assertInstanceOf(P\Coroutine::class, P\Coroutine::of($fn));
$this->assertInstanceOf(Coroutine::class, Coroutine::of($fn));
}

/**
Expand Down Expand Up @@ -77,7 +76,7 @@ public function testShouldCancelResultPromiseAndOutsideCurrentPromise(): void
public function testWaitShouldResolveChainedCoroutines(): void
{
$promisor = function () {
return P\Coroutine::of(function () {
return Coroutine::of(function () {
yield $promise = new Promise(function () use (&$promise): void {
$promise->resolve(1);
});
Expand All @@ -91,19 +90,19 @@ public function testWaitShouldResolveChainedCoroutines(): void

public function testWaitShouldHandleIntermediateErrors(): void
{
$promise = P\Coroutine::of(function () {
$promise = Coroutine::of(function () {
yield $promise = new Promise(function () use (&$promise): void {
$promise->resolve(1);
});
})
->then(function () {
return P\Coroutine::of(function () {
return Coroutine::of(function () {
yield $promise = new Promise(function () use (&$promise): void {
$promise->reject(new \Exception());
});
});
})
->otherwise(function (\Exception $error = null) {
->otherwise(function (?\Exception $error = null) {
if (!$error) {
self::fail('Error did not propagate.');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/NotPromiseInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
$this->nextPromise = new Promise();
}

public function then(callable $res = null, callable $rej = null): PromiseInterface
public function then(?callable $res = null, ?callable $rej = null): PromiseInterface
{
return $this->nextPromise->then($res, $rej);
}
Expand All @@ -36,7 +36,7 @@ public function reject($reason): void
$this->nextPromise->reject($reason);
}

public function wait(bool $unwrap = true, bool $defaultResolution = null): void
public function wait(bool $unwrap = true, ?bool $defaultResolution = null): void
{
}

Expand Down
8 changes: 4 additions & 4 deletions tests/PromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testInvokesWaitFunction(): void

public function testRejectsAndThrowsWhenWaitFailsToResolve(): void
{
$this->expectException(\GuzzleHttp\Promise\RejectionException::class);
$this->expectException(RejectionException::class);
$this->expectExceptionMessage('The promise was rejected with reason: Invoking the wait callback did not resolve the promise');

$p = new Promise(function (): void {});
Expand All @@ -84,7 +84,7 @@ public function testRejectsAndThrowsWhenWaitFailsToResolve(): void

public function testThrowsWhenUnwrapIsRejectedWithNonException(): void
{
$this->expectException(\GuzzleHttp\Promise\RejectionException::class);
$this->expectException(RejectionException::class);
$this->expectExceptionMessage('The promise was rejected with reason: foo');

$p = new Promise(function () use (&$p): void {
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testWaitsOnNestedPromises(): void

public function testThrowsWhenWaitingOnPromiseWithNoWaitFunction(): void
{
$this->expectException(\GuzzleHttp\Promise\RejectionException::class);
$this->expectException(RejectionException::class);

$p = new Promise();
$p->wait();
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testCannotCancelNonPending(): void

public function testCancelsPromiseWhenNoCancelFunction(): void
{
$this->expectException(\GuzzleHttp\Promise\CancellationException::class);
$this->expectException(CancellationException::class);

$p = new Promise();
$p->cancel();
Expand Down
2 changes: 1 addition & 1 deletion tests/Thennable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct()
$this->nextPromise = new Promise();
}

public function then(callable $res = null, callable $rej = null)
public function then(?callable $res = null, ?callable $rej = null)
{
return $this->nextPromise->then($res, $rej);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testWaitsOnAllPromisesIntoArray(): void

public function testUnwrapsPromisesWithNoDefaultAndFailure(): void
{
$this->expectException(\GuzzleHttp\Promise\RejectionException::class);
$this->expectException(RejectionException::class);

$promises = [new FulfilledPromise('a'), new Promise()];
P\Utils::unwrap($promises);
Expand Down Expand Up @@ -151,7 +151,7 @@ public function testCanWaitUntilSomeCountIsSatisfied(): void

public function testThrowsIfImpossibleToWaitForSomeCount(): void
{
$this->expectException(\GuzzleHttp\Promise\AggregateException::class);
$this->expectException(AggregateException::class);
$this->expectExceptionMessage('Not enough promises to fulfill count');

$a = new Promise(function () use (&$a): void { $a->resolve('a'); });
Expand All @@ -161,7 +161,7 @@ public function testThrowsIfImpossibleToWaitForSomeCount(): void

public function testThrowsIfResolvedWithoutCountTotalResults(): void
{
$this->expectException(\GuzzleHttp\Promise\AggregateException::class);
$this->expectException(AggregateException::class);
$this->expectExceptionMessage('Not enough promises to fulfill count');

$a = new Promise();
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": {
"php": "^7.4 || ^8.0",
"friendsofphp/php-cs-fixer": "3.40.2"
"friendsofphp/php-cs-fixer": "3.52.1"
},
"config": {
"preferred-install": "dist"
Expand Down

0 comments on commit 3e78ae0

Please sign in to comment.