add cs fixer and PHPStan and activate it (build 436)

This commit is contained in:
crazywhalecc
2022-03-15 18:05:33 +08:00
parent d01bd69aa5
commit 1706afbcd0
163 changed files with 4572 additions and 3588 deletions

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Event\SwooleEvent;
use Error;
use Exception;
use Swoole\Coroutine;
@@ -20,54 +20,55 @@ use ZM\Store\LightCacheInside;
/**
* Class OnClose
* @package ZM\Event\SwooleEvent
* @SwooleHandler("close")
*/
class OnClose implements SwooleEvent
{
/** @noinspection PhpUnreachableStatementInspection */
public function onCall($server, $fd) {
public function onCall($server, $fd)
{
unset(Context::$context[Coroutine::getCid()]);
Console::debug("Calling Swoole \"close\" event from fd=" . $fd);
Console::debug('Calling Swoole "close" event from fd=' . $fd);
$conn = ManagerGM::get($fd);
if ($conn === null) return;
set_coroutine_params(["server" => $server, "connection" => $conn, "fd" => $fd]);
if ($conn === null) {
return;
}
set_coroutine_params(['server' => $server, 'connection' => $conn, 'fd' => $fd]);
$dispatcher1 = new EventDispatcher(OnCloseEvent::class);
$dispatcher1->setRuleFunction(function ($v) {
return $v->connect_type == ctx()->getConnection()->getName() && eval("return " . $v->getRule() . ";");
return $v->connect_type == ctx()->getConnection()->getName() && eval('return ' . $v->getRule() . ';');
});
$dispatcher = new EventDispatcher(OnSwooleEvent::class);
$dispatcher->setRuleFunction(function ($v) {
if ($v->getRule() == '') {
return strtolower($v->type) == 'close';
} else {
/** @noinspection PhpUnreachableStatementInspection */
if (strtolower($v->type) == 'close' && eval("return " . $v->getRule() . ";")) return true;
else return false;
}
if (strtolower($v->type) == 'close' && eval('return ' . $v->getRule() . ';')) {
return true;
}
return false;
});
try {
$obb_onebot = ZMConfig::get("global", "onebot") ??
ZMConfig::get("global", "modules")["onebot"] ??
["status" => true, "single_bot_mode" => false, "message_level" => 99999];
if ($conn->getName() === 'qq' && $obb_onebot["status"] === true) {
if ($obb_onebot["single_bot_mode"]) {
LightCacheInside::set("connect", "conn_fd", -1);
$obb_onebot = ZMConfig::get('global', 'onebot') ??
ZMConfig::get('global', 'modules')['onebot'] ??
['status' => true, 'single_bot_mode' => false, 'message_level' => 99999];
if ($conn->getName() === 'qq' && $obb_onebot['status'] === true) {
if ($obb_onebot['single_bot_mode']) {
LightCacheInside::set('connect', 'conn_fd', -1);
}
}
$dispatcher1->dispatchEvents($conn);
$dispatcher->dispatchEvents($conn);
} catch (Exception $e) {
$error_msg = $e->getMessage() . " at " . $e->getFile() . "(" . $e->getLine() . ")";
Console::error(zm_internal_errcode("E00016") . "Uncaught exception " . get_class($e) . " when calling \"close\": " . $error_msg);
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
Console::error(zm_internal_errcode('E00016') . 'Uncaught exception ' . get_class($e) . ' when calling "close": ' . $error_msg);
Console::trace();
} catch (Error $e) {
$error_msg = $e->getMessage() . " at " . $e->getFile() . "(" . $e->getLine() . ")";
Console::error(zm_internal_errcode("E00016") . "Uncaught " . get_class($e) . " when calling \"close\": " . $error_msg);
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
Console::error(zm_internal_errcode('E00016') . 'Uncaught ' . get_class($e) . ' when calling "close": ' . $error_msg);
Console::trace();
}
ManagerGM::popConnect($fd);
}
}
}