Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed some ignoreErrors from phpstan and resolve those errors #979

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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,.*#'
5 changes: 3 additions & 2 deletions src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,11 @@ public function doSslHandshake($socket): bool|int
}

// Hidden error.
set_error_handler(function ($errno, $err_str) {
set_error_handler(static 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();
Expand Down
19 changes: 10 additions & 9 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(static 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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 0 additions & 4 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

use Workerman\Connection\TcpConnection;

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});

/*
|--------------------------------------------------------------------------
| Functions
Expand Down