Skip to content

Commit

Permalink
Make implicit nullable types explicit (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas authored Mar 20, 2024
1 parent c2bddbd commit 83b1bd6
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/BlockingFallbackResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down
2 changes: 1 addition & 1 deletion lib/ConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/HostLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Internal/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lib/Rfc1035StubResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/UnixConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/WindowsConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 83b1bd6

Please sign in to comment.