From a64b7ac8162689995efbec3774f0e80f79a54661 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 16 Dec 2023 15:55:38 +0200 Subject: [PATCH] fix validation --- src/Socket.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Socket.php b/src/Socket.php index 3fe5ecd..b54a7fb 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -21,11 +21,15 @@ class Socket public static function isPort(mixed $value): bool { - $length = strlen( - $value - ); + if (false === filter_var($value, FILTER_VALIDATE_INT)) + { + return false; + } - return false !== filter_var($value, FILTER_VALIDATE_INT) && 0 < $length && 65536 > $length; + return + ( + 0 < $value && 65536 > $value + ); } public static function isOpen(string $host, int $port = -1, ?float $timeout = null, int &$error_code = null, string &$error_message = null): bool