From f1a0406b76e7dce5bc7ecb71e940a0352139fb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 5 Jul 2024 21:49:14 +0200 Subject: [PATCH] Improve PHP 8.4+ support by avoiding implicitly nullable types --- composer.json | 10 +++++----- src/Browser.php | 5 +++-- src/Io/Sender.php | 9 ++------- tests/Io/SenderTest.php | 4 +++- tests/Io/StreamingServerTest.php | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 2fe67da0..809e81c9 100644 --- a/composer.json +++ b/composer.json @@ -31,18 +31,18 @@ "fig/http-message-util": "^1.1", "psr/http-message": "^1.0", "react/event-loop": "^1.2", - "react/promise": "^3 || ^2.3 || ^1.2.1", - "react/socket": "^1.12", - "react/stream": "^1.2" + "react/promise": "^3.2 || ^2.3 || ^1.2.1", + "react/socket": "^1.16", + "react/stream": "^1.4" }, "require-dev": { "clue/http-proxy-react": "^1.8", "clue/reactphp-ssh-proxy": "^1.4", "clue/socks-react": "^1.4", "phpunit/phpunit": "^9.6 || ^7.5", - "react/async": "^4 || ^3", + "react/async": "^4.2 || ^3", "react/promise-stream": "^1.4", - "react/promise-timer": "^1.9" + "react/promise-timer": "^1.11" }, "autoload": { "psr-4": { diff --git a/src/Browser.php b/src/Browser.php index 06e194d9..f042b799 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -10,6 +10,7 @@ use React\Http\Message\Request; use React\Http\Message\Uri; use React\Promise\PromiseInterface; +use React\Socket\Connector; use React\Socket\ConnectorInterface; use React\Stream\ReadableStreamInterface; use InvalidArgumentException; @@ -68,11 +69,11 @@ class Browser * @param ?ConnectorInterface $connector * @param ?LoopInterface $loop */ - public function __construct(ConnectorInterface $connector = null, LoopInterface $loop = null) + public function __construct(?ConnectorInterface $connector = null, ?LoopInterface $loop = null) { $loop = $loop ?? Loop::get(); $this->transaction = new Transaction( - Sender::createFromLoop($loop, $connector), + Sender::createFromLoop($loop, $connector ?? new Connector([], $loop)), $loop ); } diff --git a/src/Io/Sender.php b/src/Io/Sender.php index 8ece2ee0..ccb1e1da 100644 --- a/src/Io/Sender.php +++ b/src/Io/Sender.php @@ -8,7 +8,6 @@ use React\Http\Client\Client as HttpClient; use React\Promise\PromiseInterface; use React\Promise\Deferred; -use React\Socket\Connector; use React\Socket\ConnectorInterface; use React\Stream\ReadableStreamInterface; @@ -45,15 +44,11 @@ class Sender * ``` * * @param LoopInterface $loop - * @param ConnectorInterface|null $connector + * @param ConnectorInterface $connector * @return self */ - public static function createFromLoop(LoopInterface $loop, ConnectorInterface $connector = null) + public static function createFromLoop(LoopInterface $loop, ConnectorInterface $connector) { - if ($connector === null) { - $connector = new Connector([], $loop); - } - return new self(new HttpClient(new ClientConnectionManager($connector, $loop))); } diff --git a/tests/Io/SenderTest.php b/tests/Io/SenderTest.php index df4c5359..4154a38d 100644 --- a/tests/Io/SenderTest.php +++ b/tests/Io/SenderTest.php @@ -34,7 +34,9 @@ public function setUpLoop() public function testCreateFromLoop() { - $sender = Sender::createFromLoop($this->loop, null); + $connector = $this->createMock(ConnectorInterface::class); + + $sender = Sender::createFromLoop($this->loop, $connector); $this->assertInstanceOf(Sender::class, $sender); } diff --git a/tests/Io/StreamingServerTest.php b/tests/Io/StreamingServerTest.php index a61d1425..803ff45c 100644 --- a/tests/Io/StreamingServerTest.php +++ b/tests/Io/StreamingServerTest.php @@ -36,7 +36,7 @@ public function setUpConnectionMockAndSocket() } - private function mockConnection(array $additionalMethods = null) + private function mockConnection(array $additionalMethods = []) { $connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() @@ -53,7 +53,7 @@ private function mockConnection(array $additionalMethods = null) 'getLocalAddress', 'pipe' ], - (is_array($additionalMethods) ? $additionalMethods : []) + $additionalMethods )) ->getMock();