From 6db8207ed4e7706c48b24940467e483d704bfa58 Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Thu, 27 Jan 2022 19:05:35 +0300 Subject: [PATCH] Fix #40: Fix return type for callback of `set_error_handler()` function --- CHANGELOG.md | 5 ++--- src/DnsHelper.php | 31 +++++++++++++------------------ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66802d5..0ddb91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,9 @@ # Yii Network Utilities Change Log - ## 1.0.1 under development -- no changes in this release. +- Bug #40: Fix return type for callback of `set_error_handler()` function (devanych) ## 1.0.0 March 04, 2021 -- Initial release. \ No newline at end of file +- Initial release. diff --git a/src/DnsHelper.php b/src/DnsHelper.php index 14f2c92..ca87ace 100644 --- a/src/DnsHelper.php +++ b/src/DnsHelper.php @@ -20,15 +20,13 @@ final class DnsHelper */ public static function existsMx(string $hostname): bool { - /** @psalm-suppress InvalidArgument, MixedArgumentTypeCoercion */ - set_error_handler( - static function (int $errorNumber, string $errorString) use ($hostname): ?bool { - throw new RuntimeException( - sprintf('Failed to get DNS record "%s". ', $hostname) . $errorString, - $errorNumber - ); - } - ); + set_error_handler(static function (int $errorNumber, string $errorString) use ($hostname): bool { + throw new RuntimeException( + sprintf('Failed to get DNS record "%s". ', $hostname) . $errorString, + $errorNumber + ); + }); + $hostname = rtrim($hostname, '.') . '.'; $result = dns_get_record($hostname, DNS_MX); @@ -46,15 +44,12 @@ static function (int $errorNumber, string $errorString) use ($hostname): ?bool { */ public static function existsA(string $hostname): bool { - /** @psalm-suppress InvalidArgument, MixedArgumentTypeCoercion */ - set_error_handler( - static function (int $errorNumber, string $errorString) use ($hostname): ?bool { - throw new RuntimeException( - sprintf('Failed to get DNS record "%s". ', $hostname) . $errorString, - $errorNumber - ); - } - ); + set_error_handler(static function (int $errorNumber, string $errorString) use ($hostname): bool { + throw new RuntimeException( + sprintf('Failed to get DNS record "%s". ', $hostname) . $errorString, + $errorNumber + ); + }); $result = dns_get_record($hostname, DNS_A);