From b9ccc2d0a19a3931f33ecd2d1646b806471b7710 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 20 Mar 2024 08:48:49 +0100 Subject: [PATCH] Make implicit nullable types explicit --- lib/BlockingFallbackResolver.php | 2 +- lib/ConfigException.php | 2 +- lib/HostLoader.php | 2 +- lib/Internal/Socket.php | 2 +- lib/Record.php | 2 +- lib/Resolver.php | 2 +- lib/Rfc1035StubResolver.php | 6 +++--- lib/UnixConfigLoader.php | 2 +- lib/WindowsConfigLoader.php | 2 +- lib/functions.php | 4 ++-- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/BlockingFallbackResolver.php b/lib/BlockingFallbackResolver.php index 3a1a702..ad97104 100644 --- a/lib/BlockingFallbackResolver.php +++ b/lib/BlockingFallbackResolver.php @@ -8,7 +8,7 @@ class BlockingFallbackResolver implements Resolver { - public function resolve(string $name, int $typeRestriction = null): Promise + public function resolve(string $name, ?int $typeRestriction = null): Promise { if (!\in_array($typeRestriction, [Record::A, null], true)) { return new Failure(new DnsException("Query for '{$name}' failed, because loading the system's DNS configuration failed and querying records other than A records isn't supported in blocking fallback mode.")); diff --git a/lib/ConfigException.php b/lib/ConfigException.php index 9986ea2..6142b2f 100644 --- a/lib/ConfigException.php +++ b/lib/ConfigException.php @@ -9,7 +9,7 @@ */ class ConfigException extends DnsException { - public function __construct(string $message, Throwable $previous = null) + public function __construct(string $message, ?Throwable $previous = null) { parent::__construct($message, 0, $previous); } diff --git a/lib/HostLoader.php b/lib/HostLoader.php index 74a1517..92d76e8 100644 --- a/lib/HostLoader.php +++ b/lib/HostLoader.php @@ -11,7 +11,7 @@ class HostLoader { private $path; - public function __construct(string $path = null) + public function __construct(?string $path = null) { $this->path = $path ?? $this->getDefaultPath(); } diff --git a/lib/Internal/Socket.php b/lib/Internal/Socket.php index 3c5150a..9dda2c0 100644 --- a/lib/Internal/Socket.php +++ b/lib/Internal/Socket.php @@ -81,7 +81,7 @@ protected function __construct($socket) $this->messageFactory = new MessageFactory; $this->lastActivity = \time(); - $this->onResolve = function (\Throwable $exception = null, Message $message = null) { + $this->onResolve = function (?\Throwable $exception = null, ?Message $message = null) { $this->lastActivity = \time(); $this->receiving = false; diff --git a/lib/Record.php b/lib/Record.php index dc33fce..3cad63a 100644 --- a/lib/Record.php +++ b/lib/Record.php @@ -60,7 +60,7 @@ final class Record private $type; private $ttl; - public function __construct(string $value, int $type, int $ttl = null) + public function __construct(string $value, int $type, ?int $ttl = null) { $this->value = $value; $this->type = $type; diff --git a/lib/Resolver.php b/lib/Resolver.php index bf4c811..c39f6c9 100644 --- a/lib/Resolver.php +++ b/lib/Resolver.php @@ -18,7 +18,7 @@ interface Resolver * * @return Promise */ - public function resolve(string $name, int $typeRestriction = null): Promise; + public function resolve(string $name, ?int $typeRestriction = null): Promise; /** * Query specific DNS records. diff --git a/lib/Rfc1035StubResolver.php b/lib/Rfc1035StubResolver.php index a3d15be..66bb563 100644 --- a/lib/Rfc1035StubResolver.php +++ b/lib/Rfc1035StubResolver.php @@ -58,7 +58,7 @@ final class Rfc1035StubResolver implements Resolver /** @var int */ private $nextNameserver = 0; - public function __construct(Cache $cache = null, ConfigLoader $configLoader = null) + public function __construct(?Cache $cache = null, ?ConfigLoader $configLoader = null) { $this->cache = $cache ?? new ArrayCache(5000 /* default gc interval */, 256 /* size */); $this->configLoader = $configLoader ?? (\stripos(PHP_OS, "win") === 0 @@ -93,7 +93,7 @@ public function __destruct() } /** @inheritdoc */ - public function resolve(string $name, int $typeRestriction = null): Promise + public function resolve(string $name, ?int $typeRestriction = null): Promise { if ($typeRestriction !== null && $typeRestriction !== Record::A && $typeRestriction !== Record::AAAA) { throw new \Error("Invalid value for parameter 2: null|Record::A|Record::AAAA expected"); @@ -414,7 +414,7 @@ public function query(string $name, int $type): Promise return $promise; } - private function queryHosts(string $name, int $typeRestriction = null): array + private function queryHosts(string $name, ?int $typeRestriction = null): array { $hosts = $this->config->getKnownHosts(); $records = []; diff --git a/lib/UnixConfigLoader.php b/lib/UnixConfigLoader.php index 9c1a9b6..cae0fb6 100644 --- a/lib/UnixConfigLoader.php +++ b/lib/UnixConfigLoader.php @@ -29,7 +29,7 @@ class UnixConfigLoader implements ConfigLoader private $path; private $hostLoader; - public function __construct(string $path = "/etc/resolv.conf", HostLoader $hostLoader = null) + public function __construct(string $path = "/etc/resolv.conf", ?HostLoader $hostLoader = null) { $this->path = $path; $this->hostLoader = $hostLoader ?? new HostLoader; diff --git a/lib/WindowsConfigLoader.php b/lib/WindowsConfigLoader.php index 390bd65..e05793d 100644 --- a/lib/WindowsConfigLoader.php +++ b/lib/WindowsConfigLoader.php @@ -11,7 +11,7 @@ final class WindowsConfigLoader implements ConfigLoader { private $hostLoader; - public function __construct(HostLoader $hostLoader = null) + public function __construct(?HostLoader $hostLoader = null) { $this->hostLoader = $hostLoader ?? new HostLoader; } diff --git a/lib/functions.php b/lib/functions.php index b1a4f58..2430f59 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -14,7 +14,7 @@ * * @return \Amp\Dns\Resolver Returns the application-wide dns resolver instance */ -function resolver(Resolver $resolver = null): Resolver +function resolver(?Resolver $resolver = null): Resolver { if ($resolver === null) { $resolver = Loop::getState(LOOP_STATE_IDENTIFIER); @@ -44,7 +44,7 @@ function createDefaultResolver(): Resolver /** * @see Resolver::resolve() */ -function resolve(string $name, int $typeRestriction = null): Promise +function resolve(string $name, ?int $typeRestriction = null): Promise { return resolver()->resolve($name, $typeRestriction); }