diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fad677a19..72557b042 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -27,8 +27,5 @@ parameters: - '#Property Workerman\\Events\\Swow::.* has unknown class Swow\\Coroutine as its type.#' - path: src/Timer.php message: '#Call to static method getSuspension\(\) on an unknown class Revolt\\EventLoop.#' - - path: tests/Pest.php - message: '#Undefined variable: \$this#' - path: src/Worker.php message: '#Constant LINE_VERSION_LENGTH not found.#' - - message: '#Parameter \#1 \$callback of function set_error_handler expects \(callable\(int, string, string, int\): bool\)\|null,.*#' \ No newline at end of file diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index 6556a1fe3..b38937198 100644 --- a/src/Connection/TcpConnection.php +++ b/src/Connection/TcpConnection.php @@ -816,10 +816,11 @@ public function doSslHandshake($socket): bool|int } // Hidden error. - set_error_handler(function ($errno, $err_str) { + set_error_handler(function (int $code, string $msg): bool { if (!Worker::$daemonize) { - Worker::safeEcho("SSL handshake error: $err_str \n"); + Worker::safeEcho(sprintf("SSL handshake error: %s\n", $msg)); } + return true; }); $ret = stream_socket_enable_crypto($socket, true, $type); restore_error_handler(); diff --git a/src/Worker.php b/src/Worker.php index b9e22fa5c..ed10ed897 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -598,8 +598,9 @@ protected static function checkSapiEnv(): void */ protected static function init(): void { - set_error_handler(function ($code, $msg, $file, $line) { - static::safeEcho("$msg in file $file on line $line\n"); + set_error_handler(function (int $code, string $msg, string $file, int $line): bool { + static::safeEcho(sprintf("%s \"%s\" in file %s on line %d\n", static::getErrorType($code), $msg, $file, $line)); + return true; }); // Start file. @@ -1280,7 +1281,7 @@ public static function resetStd(bool $throwException = true): void $handle = fopen(static::$stdoutFile, "a"); if ($handle) { unset($handle); - set_error_handler(function () {}); + set_error_handler(static fn (): bool => true); if ($STDOUT) { fclose($STDOUT); } @@ -1675,7 +1676,7 @@ public function setUserAndGroup(): void */ protected static function setProcessTitle(string $title): void { - set_error_handler(function (){}); + set_error_handler(static fn (): bool => true); cli_set_process_title($title); restore_error_handler(); } @@ -2273,7 +2274,7 @@ public function __construct(string $socketName = null, array $socketContext = [] $address = \parse_url($socketName); if (isset($address['host']) && isset($address['port'])) { try { - \set_error_handler(function(){}); + \set_error_handler(static fn (): bool => true); // If address not in use, turn reusePort on automatically. $server = stream_socket_server("tcp://{$address['host']}:{$address['port']}"); if ($server) { @@ -2330,7 +2331,7 @@ public function listen(): void // Try to open keepalive for tcp and disable Nagle algorithm. if (function_exists('socket_import_stream') && self::BUILD_IN_TRANSPORTS[$this->transport] === 'tcp') { - set_error_handler(function () {}); + set_error_handler(static fn (): bool => true); $socket = socket_import_stream($this->mainSocket); socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, 1); socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1); @@ -2353,7 +2354,7 @@ public function unlisten(): void { $this->pauseAccept(); if ($this->mainSocket) { - set_error_handler(function () {}); + set_error_handler(static fn (): bool => true); fclose($this->mainSocket); restore_error_handler(); $this->mainSocket = null; @@ -2504,7 +2505,7 @@ public function stop(): void protected function acceptTcpConnection(mixed $socket): void { // Accept a connection on server socket. - set_error_handler(function () {}); + set_error_handler(static fn (): bool => true); $newSocket = stream_socket_accept($socket, 0, $remoteAddress); restore_error_handler(); @@ -2544,7 +2545,7 @@ protected function acceptTcpConnection(mixed $socket): void */ protected function acceptUdpConnection(mixed $socket): bool { - set_error_handler(function () {}); + set_error_handler(static fn (): bool => true); $recvBuffer = stream_socket_recvfrom($socket, UdpConnection::MAX_UDP_PACKAGE_SIZE, 0, $remoteAddress); restore_error_handler(); if (false === $recvBuffer || empty($remoteAddress)) { diff --git a/tests/Pest.php b/tests/Pest.php index 19f6fad10..7db6ab1bc 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -26,10 +26,6 @@ use Workerman\Connection\TcpConnection; -expect()->extend('toBeOne', function () { - return $this->toBe(1); -}); - /* |-------------------------------------------------------------------------- | Functions