Skip to content

Commit 5c22d81

Browse files
authored
Merge pull request #46 from clue-labs/nullable
Improve PHP 8.4+ support by avoiding implicitly nullable types
2 parents 29f9d70 + 6ed90a0 commit 5c22d81

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"php": ">=5.4",
1515
"evenement/evenement": "^3.0 || ^2.0",
1616
"react/event-loop": "^1.2",
17-
"react/http": "^1.6",
18-
"react/promise": "^3 || ^2.10 || ^1.2.1"
17+
"react/http": "^1.11",
18+
"react/promise": "^3.2 || ^2.10 || ^1.2.1"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"

src/EventSource.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,20 @@ class EventSource extends EventEmitter
150150
* @param ?LoopInterface $loop
151151
* @throws \InvalidArgumentException for invalid URL
152152
*/
153-
public function __construct($url, Browser $browser = null, LoopInterface $loop = null)
153+
public function __construct($url, $browser = null, $loop = null)
154154
{
155155
$parts = parse_url($url);
156156
if (!isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], array('http', 'https'))) {
157157
throw new \InvalidArgumentException();
158158
}
159159

160+
if ($browser !== null && !$browser instanceof Browser) { // manual type check to support legacy PHP < 7.1
161+
throw new \InvalidArgumentException('Argument #2 ($browser) expected null|React\Http\Browser');
162+
}
163+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
164+
throw new \InvalidArgumentException('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
165+
}
166+
160167
$this->loop = $loop ?: Loop::get();
161168
if ($browser === null) {
162169
$browser = new Browser(null, $this->loop);

tests/EventSourceTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public function testConstructorThrowsIfUriArgumentIncludesInvalidScheme()
3030
new EventSource('ftp://example.com');
3131
}
3232

33+
public function testCtorThrowsForInvalidBrowser()
34+
{
35+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($browser) expected null|React\Http\Browser');
36+
new EventSource('http://example.com', 'browser');
37+
}
38+
39+
public function testCtorThrowsForInvalidLoop()
40+
{
41+
$this->setExpectedException('InvalidArgumentException', 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface');
42+
new EventSource('http://example.com', null, 'loop');
43+
}
44+
3345
public function testConstructWithoutBrowserAndLoopAssignsBrowserAndLoopAutomatically()
3446
{
3547
$es = new EventSource('http://example.com');

0 commit comments

Comments
 (0)