From f557f9ae66b420071dd891553cfb0450fd35b35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 27 Aug 2024 08:26:12 +0200 Subject: [PATCH] Improve PHP 8.4+ support by avoiding implicitly nullable types --- composer.json | 10 +++++----- src/Client.php | 6 +++++- tests/ClientTest.php | 6 ++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 530ea00..ef24590 100644 --- a/composer.json +++ b/composer.json @@ -14,18 +14,18 @@ "php": ">=5.3", "clue/json-stream": "^0.1", "react/event-loop": "^1.2", - "react/http": "^1.8", - "react/promise": "^3.1 || ^2.11 || ^1.3", + "react/http": "^1.11", + "react/promise": "^3.2 || ^2.11 || ^1.3", "react/promise-stream": "^1.6", - "react/socket": "^1.12", - "react/stream": "^1.2", + "react/socket": "^1.16", + "react/stream": "^1.4", "rize/uri-template": "^0.3" }, "require-dev": { "clue/caret-notation": "^0.2", "clue/tar-react": "^0.2", "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", - "react/async": "^4 || ^3 || ^2" + "react/async": "^4.2 || ^3 || ^2" }, "autoload": { "psr-4": { diff --git a/src/Client.php b/src/Client.php index 6285aab..3fc69d4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -56,8 +56,12 @@ class Client * @param ?string $url * @throws \InvalidArgumentException */ - public function __construct(LoopInterface $loop = null, $url = null) + public function __construct($loop = null, $url = null) { + if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1 + throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface'); + } + if ($url === null) { $url = 'unix:///var/run/docker.sock'; } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 05ee424..831791c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -59,6 +59,12 @@ public function testCtorWithLoop() new Client($loop); } + public function testCtorThrowsForInvalidLoop() + { + $this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface'); + new Client('loop'); + } + public function testCtorWithInvalidUrlThrows() { $this->setExpectedException('InvalidArgumentException');