From d2378297717feaf0fac79017a10593fe87297944 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 22 May 2024 08:21:55 +0200 Subject: [PATCH] [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 https://github.com/reactphp/promise/pull/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 https://github.com/reactphp/promise/pull/260 --- src/Query/TcpTransportExecutor.php | 2 +- src/Query/TimeoutExecutor.php | 2 +- src/Query/UdpTransportExecutor.php | 2 +- src/Resolver/Factory.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Query/TcpTransportExecutor.php b/src/Query/TcpTransportExecutor.php index d940da61..c3900e4f 100644 --- a/src/Query/TcpTransportExecutor.php +++ b/src/Query/TcpTransportExecutor.php @@ -135,7 +135,7 @@ class TcpTransportExecutor implements ExecutorInterface * @param string $nameserver * @param ?LoopInterface $loop */ - public function __construct($nameserver, LoopInterface $loop = null) + public function __construct($nameserver, ?LoopInterface $loop = null) { if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) { // several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets diff --git a/src/Query/TimeoutExecutor.php b/src/Query/TimeoutExecutor.php index d6a63211..eb12bebe 100644 --- a/src/Query/TimeoutExecutor.php +++ b/src/Query/TimeoutExecutor.php @@ -12,7 +12,7 @@ final class TimeoutExecutor implements ExecutorInterface private $loop; private $timeout; - public function __construct(ExecutorInterface $executor, $timeout, LoopInterface $loop = null) + public function __construct(ExecutorInterface $executor, float $timeout, ?LoopInterface $loop = null) { $this->executor = $executor; $this->loop = $loop ?: Loop::get(); diff --git a/src/Query/UdpTransportExecutor.php b/src/Query/UdpTransportExecutor.php index 31290284..d1cb86e2 100644 --- a/src/Query/UdpTransportExecutor.php +++ b/src/Query/UdpTransportExecutor.php @@ -99,7 +99,7 @@ final class UdpTransportExecutor implements ExecutorInterface * @param string $nameserver * @param ?LoopInterface $loop */ - public function __construct($nameserver, LoopInterface $loop = null) + public function __construct($nameserver, ?LoopInterface $loop = null) { if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) { // several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets diff --git a/src/Resolver/Factory.php b/src/Resolver/Factory.php index 5fe608cb..eedebe1a 100644 --- a/src/Resolver/Factory.php +++ b/src/Resolver/Factory.php @@ -36,7 +36,7 @@ final class Factory * @throws \InvalidArgumentException for invalid DNS server address * @throws \UnderflowException when given DNS Config object has an empty list of nameservers */ - public function create($config, LoopInterface $loop = null) + public function create($config, ?LoopInterface $loop = null) { $executor = $this->decorateHostsFileExecutor($this->createExecutor($config, $loop ?: Loop::get())); @@ -59,7 +59,7 @@ public function create($config, LoopInterface $loop = null) * @throws \InvalidArgumentException for invalid DNS server address * @throws \UnderflowException when given DNS Config object has an empty list of nameservers */ - public function createCached($config, LoopInterface $loop = null, CacheInterface $cache = null) + public function createCached($config, ?LoopInterface $loop = null, ?CacheInterface $cache = null) { // default to keeping maximum of 256 responses in cache unless explicitly given if (!($cache instanceof CacheInterface)) {