Skip to content

Commit 86d026e

Browse files
committed
[3.x] Improve PHP 8.4+ support by avoiding implicitly nullable types
This changeset improves PHP 8.4+ support by avoiding implicitly nullable types as discussed in reactphp/promise#260. I'm planning to add native types to the public API and introduce PHPStan in follow-up PRs. Once merged, we should apply similar changes to all our upcoming v3 components. On top of this, we should backport similar changes to the v1 branch. Builds on top of #182, #222 and reactphp/promise#260
1 parent d9681b1 commit 86d026e

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/Query/TcpTransportExecutor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TcpTransportExecutor implements ExecutorInterface
135135
* @param string $nameserver
136136
* @param ?LoopInterface $loop
137137
*/
138-
public function __construct($nameserver, LoopInterface $loop = null)
138+
public function __construct($nameserver, ?LoopInterface $loop = null)
139139
{
140140
if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) {
141141
// several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets

src/Query/TimeoutExecutor.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ final class TimeoutExecutor implements ExecutorInterface
1212
private $loop;
1313
private $timeout;
1414

15-
public function __construct(ExecutorInterface $executor, $timeout, LoopInterface $loop = null)
15+
/**
16+
* @param ?ExecutorInterface $executor
17+
* @param float|int $timeout
18+
* @param ?LoopInterface $loop
19+
*/
20+
public function __construct(?ExecutorInterface $executor, $timeout, ?LoopInterface $loop = null)
1621
{
1722
$this->executor = $executor;
1823
$this->loop = $loop ?: Loop::get();

src/Query/UdpTransportExecutor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ final class UdpTransportExecutor implements ExecutorInterface
9999
* @param string $nameserver
100100
* @param ?LoopInterface $loop
101101
*/
102-
public function __construct($nameserver, LoopInterface $loop = null)
102+
public function __construct($nameserver, ?LoopInterface $loop = null)
103103
{
104104
if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) {
105105
// several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets

src/Resolver/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class Factory
3636
* @throws \InvalidArgumentException for invalid DNS server address
3737
* @throws \UnderflowException when given DNS Config object has an empty list of nameservers
3838
*/
39-
public function create($config, LoopInterface $loop = null)
39+
public function create($config, ?LoopInterface $loop = null)
4040
{
4141
$executor = $this->decorateHostsFileExecutor($this->createExecutor($config, $loop ?: Loop::get()));
4242

@@ -59,7 +59,7 @@ public function create($config, LoopInterface $loop = null)
5959
* @throws \InvalidArgumentException for invalid DNS server address
6060
* @throws \UnderflowException when given DNS Config object has an empty list of nameservers
6161
*/
62-
public function createCached($config, LoopInterface $loop = null, CacheInterface $cache = null)
62+
public function createCached($config, ?LoopInterface $loop = null, ?CacheInterface $cache = null)
6363
{
6464
// default to keeping maximum of 256 responses in cache unless explicitly given
6565
if (!($cache instanceof CacheInterface)) {

0 commit comments

Comments
 (0)