Skip to content

Commit e6d1219

Browse files
authored
Merge pull request #41 from clue-labs/nullable
Improve PHP 8.4+ support by avoiding implicitly nullable types
2 parents 61bbb92 + 45bd514 commit e6d1219

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.4
1415
- 8.3
1516
- 8.2
1617
- 8.1

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"require": {
1414
"php": ">=5.3",
1515
"react/event-loop": "^1.2",
16-
"react/promise": "^3 || ^2.1 || ^1.2.1",
17-
"react/promise-timer": "^1.9",
18-
"react/socket": "^1.12"
16+
"react/promise": "^3.2 || ^2.1 || ^1.2.1",
17+
"react/promise-timer": "^1.11",
18+
"react/socket": "^1.16"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"

src/ConnectionManagerDelay.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ class ConnectionManagerDelay implements ConnectorInterface
2323
* @param float $delay
2424
* @param ?LoopInterface $loop
2525
*/
26-
public function __construct(ConnectorInterface $connectionManager, $delay, LoopInterface $loop = null)
26+
public function __construct(ConnectorInterface $connectionManager, $delay, $loop = null)
2727
{
28+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
29+
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
30+
}
31+
2832
$this->connectionManager = $connectionManager;
2933
$this->delay = $delay;
3034
$this->loop = $loop ?: Loop::get();

src/ConnectionManagerTimeout.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ class ConnectionManagerTimeout implements ConnectorInterface
2323
* @param float $timeout
2424
* @param ?LoopInterface $loop
2525
*/
26-
public function __construct(ConnectorInterface $connectionManager, $timeout, LoopInterface $loop = null)
26+
public function __construct(ConnectorInterface $connectionManager, $timeout, $loop = null)
2727
{
28+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
29+
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
30+
}
31+
2832
$this->connectionManager = $connectionManager;
2933
$this->timeout = $timeout;
3034
$this->loop = $loop ?: Loop::get();

tests/ConnectionManagerDelayTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,22 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
2121
{
2222
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
2323
$cm = new ConnectionManagerDelay($unused, 0);
24-
24+
2525
$ref = new \ReflectionProperty($cm, 'loop');
2626
$ref->setAccessible(true);
2727
$loop = $ref->getValue($cm);
28-
28+
2929
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
3030
}
3131

32+
public function testContructorThrowsExceptionForInvalidLoop()
33+
{
34+
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
35+
36+
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
37+
new ConnectionManagerDelay($unused, 0, 'loop');
38+
}
39+
3240
public function testDelayTenth()
3341
{
3442
$will = $this->createConnectionManagerMock(true);

tests/ConnectionManagerTimeoutTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function testConstructWithoutLoopAssignsLoopAutomatically()
3131
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
3232
}
3333

34+
public function testContructorThrowsExceptionForInvalidLoop()
35+
{
36+
$unused = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
37+
38+
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
39+
new ConnectionManagerTimeout($unused, 0, 'loop');
40+
}
41+
3442
public function testTimeoutOkay()
3543
{
3644
$will = $this->createConnectionManagerMock(true);

0 commit comments

Comments
 (0)