diff --git a/src/DnsConfig.php b/src/DnsConfig.php index 724c207..27b8803 100644 --- a/src/DnsConfig.php +++ b/src/DnsConfig.php @@ -19,12 +19,12 @@ final class DnsConfig private bool $rotation = false; /** - * @throws ConfigException + * @throws DnsConfigException */ public function __construct(array $nameservers, array $knownHosts = []) { if (\count($nameservers) < 1) { - throw new ConfigException("At least one nameserver is required for a valid config"); + throw new DnsConfigException("At least one nameserver is required for a valid config"); } foreach ($nameservers as $nameserver) { @@ -55,12 +55,12 @@ final class DnsConfig } /** - * @throws ConfigException + * @throws DnsConfigException */ public function withNdots(int $ndots): self { if ($ndots < 0) { - throw new ConfigException("Invalid ndots ($ndots), must be greater or equal to 0"); + throw new DnsConfigException("Invalid ndots ($ndots), must be greater or equal to 0"); } $self = clone $this; @@ -80,7 +80,7 @@ final class DnsConfig public function withTimeout(float $timeout): self { if ($timeout < 0) { - throw new ConfigException("Invalid timeout ($timeout), must be 0 or greater"); + throw new DnsConfigException("Invalid timeout ($timeout), must be 0 or greater"); } $self = clone $this; @@ -92,7 +92,7 @@ final class DnsConfig public function withAttempts(int $attempts): self { if ($attempts < 1) { - throw new ConfigException("Invalid attempt count ($attempts), must be 1 or greater"); + throw new DnsConfigException("Invalid attempt count ($attempts), must be 1 or greater"); } $self = clone $this; @@ -137,7 +137,7 @@ final class DnsConfig } /** - * @throws ConfigException + * @throws DnsConfigException */ private function validateNameserver(string $nameserver): void { @@ -145,13 +145,13 @@ final class DnsConfig $addr = \strstr(\substr($nameserver, 1), "]", true); $addrEnd = \strrpos($nameserver, "]"); if ($addrEnd === false) { - throw new ConfigException("Invalid nameserver: $nameserver"); + throw new DnsConfigException("Invalid nameserver: $nameserver"); } $port = \substr($nameserver, $addrEnd + 1); if ($port !== "" && !\preg_match("(^:(\\d+)$)", $port)) { - throw new ConfigException("Invalid nameserver: $nameserver"); + throw new DnsConfigException("Invalid nameserver: $nameserver"); } $port = $port === "" ? 53 : \substr($port, 1); @@ -170,11 +170,11 @@ final class DnsConfig $port = (int) $port; if (!@\inet_pton($addr)) { - throw new ConfigException("Invalid server IP: $addr"); + throw new DnsConfigException("Invalid server IP: $addr"); } if ($port < 1 || $port > 65535) { - throw new ConfigException("Invalid server port: $port"); + throw new DnsConfigException("Invalid server port: $port"); } } } diff --git a/src/ConfigException.php b/src/DnsConfigException.php similarity index 86% rename from src/ConfigException.php rename to src/DnsConfigException.php index 1384330..cba9867 100644 --- a/src/ConfigException.php +++ b/src/DnsConfigException.php @@ -5,7 +5,7 @@ namespace Amp\Dns; /** * MUST be thrown in case the config can't be read and no fallback is available. */ -class ConfigException extends DnsException +class DnsConfigException extends DnsException { public function __construct(string $message, ?\Throwable $previous = null) { diff --git a/src/HostLoader.php b/src/HostLoader.php index 6fa91b5..4c1d8fa 100644 --- a/src/HostLoader.php +++ b/src/HostLoader.php @@ -21,7 +21,7 @@ final class HostLoader { try { $contents = $this->readFile($this->path); - } catch (ConfigException) { + } catch (DnsConfigException) { return []; } @@ -62,7 +62,7 @@ final class HostLoader public function readFile(string $path): string { \set_error_handler(static function (int $errno, string $message) use ($path) { - throw new ConfigException("Could not read configuration file '{$path}' ({$errno}): $message"); + throw new DnsConfigException("Could not read configuration file '{$path}' ({$errno}): $message"); }); try { diff --git a/src/Rfc1035StubDnsResolver.php b/src/Rfc1035StubDnsResolver.php index 3c29388..064922a 100644 --- a/src/Rfc1035StubDnsResolver.php +++ b/src/Rfc1035StubDnsResolver.php @@ -239,7 +239,7 @@ final class Rfc1035StubDnsResolver implements DnsResolver try { $this->config = $this->configLoader->loadConfig(); $this->configStatus = self::CONFIG_LOADED; - } catch (ConfigException $e) { + } catch (DnsConfigException $e) { $this->configStatus = self::CONFIG_FAILED; $message = "Could not load the system's DNS configuration; " diff --git a/src/UnixDnsConfigLoader.php b/src/UnixDnsConfigLoader.php index 5c87d8b..f6da5f6 100644 --- a/src/UnixDnsConfigLoader.php +++ b/src/UnixDnsConfigLoader.php @@ -135,7 +135,7 @@ final class UnixDnsConfigLoader implements DnsConfigLoader private function readFile(string $path): string { \set_error_handler(static function (int $errno, string $message) use ($path) { - throw new ConfigException("Could not read configuration file '{$path}' ({$errno}) $message"); + throw new DnsConfigException("Could not read configuration file '{$path}' ({$errno}) $message"); }); try { diff --git a/src/WindowsDnsConfigLoader.php b/src/WindowsDnsConfigLoader.php index f26f24a..ac06dd3 100644 --- a/src/WindowsDnsConfigLoader.php +++ b/src/WindowsDnsConfigLoader.php @@ -55,7 +55,7 @@ final class WindowsDnsConfigLoader implements DnsConfigLoader } if ($nameserver === "") { - throw new ConfigException("Could not find a nameserver in the Windows Registry"); + throw new DnsConfigException("Could not find a nameserver in the Windows Registry"); } $nameservers = []; diff --git a/test/DnsConfigTest.php b/test/DnsConfigTest.php index 8072ae6..401ba68 100644 --- a/test/DnsConfigTest.php +++ b/test/DnsConfigTest.php @@ -2,7 +2,7 @@ namespace Amp\Dns\Test; -use Amp\Dns\ConfigException; +use Amp\Dns\DnsConfigException; use Amp\Dns\DnsConfig; use Amp\PHPUnit\AsyncTestCase; @@ -35,7 +35,7 @@ class DnsConfigTest extends AsyncTestCase */ public function testRejectsInvalidServers(array $nameservers): void { - $this->expectException(ConfigException::class); + $this->expectException(DnsConfigException::class); new DnsConfig($nameservers); } @@ -62,21 +62,21 @@ class DnsConfigTest extends AsyncTestCase public function testInvalidTimeout(): void { - $this->expectException(ConfigException::class); + $this->expectException(DnsConfigException::class); $config = new DnsConfig(["127.0.0.1"]); $config->withTimeout(-1); } public function testInvalidAttempts(): void { - $this->expectException(ConfigException::class); + $this->expectException(DnsConfigException::class); $config = new DnsConfig(["127.0.0.1"]); $config->withAttempts(0); } public function testInvalidNdots(): void { - $this->expectException(ConfigException::class); + $this->expectException(DnsConfigException::class); $config = new DnsConfig(["127.0.0.1"]); $config->withNdots(-1); } diff --git a/test/UnixDnsConfigLoaderTest.php b/test/UnixDnsConfigLoaderTest.php index 640e6da..8c6adfd 100644 --- a/test/UnixDnsConfigLoaderTest.php +++ b/test/UnixDnsConfigLoaderTest.php @@ -2,7 +2,7 @@ namespace Amp\Dns\Test; -use Amp\Dns\ConfigException; +use Amp\Dns\DnsConfigException; use Amp\Dns\UnixDnsConfigLoader; use Amp\PHPUnit\AsyncTestCase; @@ -106,7 +106,7 @@ class UnixDnsConfigLoaderTest extends AsyncTestCase public function testNoDefaultsOnConfNotFound(): void { - $this->expectException(ConfigException::class); + $this->expectException(DnsConfigException::class); (new UnixDnsConfigLoader(__DIR__ . "/data/non-existent.conf"))->loadConfig(); } }