Skip to content

Commit

Permalink
Improve PHP 8.4+ support by avoiding implicitly nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Nov 27, 2024
1 parent c1d0158 commit f557f9a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f557f9a

Please sign in to comment.