From 032eab67bc118c4f7a6f8ead2020fe04517ef8ed Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 10 Mar 2025 10:24:48 +0800 Subject: [PATCH 1/2] Update all things to PHP 8.4 --- choir-test.php | 6 ++-- composer.json | 4 +-- demo/repl.php | 9 ++++-- demo/weixin.php | 5 +-- .../Config/Loader/AbstractFileLoader.php | 3 -- src/OneBot/Config/Loader/DelegateLoader.php | 5 +-- src/OneBot/Config/Loader/JsonFileLoader.php | 3 -- src/OneBot/Config/Loader/LoadException.php | 4 +-- src/OneBot/Config/Repository.php | 12 ------- src/OneBot/Driver/Event/DriverEvent.php | 3 -- src/OneBot/Driver/Event/Event.php | 4 +-- .../Event/Process/ManagerStartEvent.php | 4 +-- .../Driver/Event/Process/ManagerStopEvent.php | 4 +-- .../Driver/Event/Process/WorkerExitEvent.php | 4 +-- .../Driver/Event/Process/WorkerStartEvent.php | 4 +-- .../Driver/Event/Process/WorkerStopEvent.php | 4 +-- src/OneBot/Driver/Event/StopException.php | 2 +- src/OneBot/Driver/Swoole/EventLoop.php | 15 --------- .../Driver/Swoole/Socket/HttpClientSocket.php | 4 +-- .../Driver/Swoole/Socket/WSClientSocket.php | 4 +-- .../Driver/Swoole/Socket/WSServerSocket.php | 3 -- src/OneBot/Driver/Swoole/SwooleDriver.php | 3 -- src/OneBot/Driver/Workerman/EventLoop.php | 21 ------------ .../Workerman/Socket/HttpClientSocket.php | 4 +-- .../Workerman/Socket/WSClientSocket.php | 4 +-- src/OneBot/Driver/Workerman/Worker.php | 11 ++++--- .../Driver/Workerman/WorkermanDriver.php | 5 --- .../V12/Action/DefaultActionHandler.php | 4 +-- src/OneBot/V12/EventBuilder.php | 2 +- src/OneBot/V12/Exception/OneBotException.php | 4 +-- .../V12/Exception/OneBotFailureException.php | 2 +- src/OneBot/V12/OneBot.php | 3 +- src/OneBot/V12/OneBotBuilder.php | 3 +- src/OneBot/global_defines.php | 15 +++++---- .../Config/Loader/AbstractFileLoaderTest.php | 12 +++---- tests/OneBot/Config/RepositoryTest.php | 32 +++++++++---------- .../OneBot/Exception/ExceptionHandlerTest.php | 3 +- tests/bootstrap.php | 3 +- 38 files changed, 75 insertions(+), 162 deletions(-) diff --git a/choir-test.php b/choir-test.php index 6b2956c..dbfdc9a 100644 --- a/choir-test.php +++ b/choir-test.php @@ -3,10 +3,12 @@ /** @noinspection PhpComposerExtensionStubsInspection */ declare(strict_types=1); +use Choir\Http\Server; +use Choir\Protocol\HttpConnection; require_once 'vendor/autoload.php'; -$server = new \Choir\Http\Server('0.0.0.0', 20001, false, [ +$server = new Server('0.0.0.0', 20001, false, [ 'worker-num' => 8, // 'logger-level' => 'debug', ]); @@ -22,7 +24,7 @@ // echo "http://127.0.0.1:8080/index.php?run={$id}&source=xhprof_testing\n"; }); -$server->on('request', function (Choir\Protocol\HttpConnection $connection) { +$server->on('request', function (HttpConnection $connection) { $connection->end('hello world'); }); diff --git a/composer.json b/composer.json index ca40a2a..3275a13 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "wiki": "https://github.com/botuniverse/php-libonebot/wiki" }, "require": { - "php": "^7.4 || ^8.0 || ^8.1 || ^8.2", + "php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4", "ext-json": "*", "psr/cache": "^1.0", "psr/event-dispatcher": "^1.0", @@ -84,7 +84,7 @@ "[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add" ], "analyse": "phpstan analyse --memory-limit 300M", - "cs-fix": "php-cs-fixer fix", + "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix", "test": "phpunit --no-coverage" } } diff --git a/demo/repl.php b/demo/repl.php index 2157140..0b193bf 100644 --- a/demo/repl.php +++ b/demo/repl.php @@ -3,12 +3,15 @@ declare(strict_types=1); use OneBot\Driver\Event\DriverInitEvent; +use OneBot\Driver\Swoole\SwooleDriver; use OneBot\Util\Utils; +use OneBot\V12\EventBuilder; use OneBot\V12\Object\Action; use OneBot\V12\Object\ActionResponse; use OneBot\V12\OneBot; use OneBot\V12\OneBotBuilder; use OneBot\V12\Validator; +use ZM\Logger\ConsoleLogger; require_once __DIR__ . '/../vendor/autoload.php'; @@ -23,11 +26,11 @@ function message_id(): string 'self_id' => 'REPL-1', 'db' => true, 'logger' => [ - 'class' => \ZM\Logger\ConsoleLogger::class, + 'class' => ConsoleLogger::class, 'level' => 'info', ], 'driver' => [ - 'class' => \OneBot\Driver\Swoole\SwooleDriver::class, + 'class' => SwooleDriver::class, 'config' => [ 'init_in_user_process_block' => true, ], @@ -81,7 +84,7 @@ function message_id(): string $event->getDriver()->getEventLoop()->delReadEvent($x); return; } - $event = (new \OneBot\V12\EventBuilder('message', 'private')) + $event = (new EventBuilder('message', 'private')) ->feed('message', trim($s)) ->feed('alt_message', trim($s)) ->feed('message_id', message_id()) diff --git a/demo/weixin.php b/demo/weixin.php index c2bb53a..3731aa6 100644 --- a/demo/weixin.php +++ b/demo/weixin.php @@ -15,6 +15,7 @@ use OneBot\V12\RetCode; use OneBot\V12\Validator; use Swoole\Coroutine\Channel; +use ZM\Logger\ConsoleLogger; require_once __DIR__ . '/../vendor/autoload.php'; @@ -24,7 +25,7 @@ 'self_id' => '', // 后续会自动获取 'db' => true, 'logger' => [ - 'class' => \ZM\Logger\ConsoleLogger::class, + 'class' => ConsoleLogger::class, 'level' => 'info', ], 'driver' => [ @@ -118,7 +119,7 @@ function wx_make_xml_reply(Action $action, string $self_id): string return str_replace('{content}', '', $xml_template); } -function swoole_channel(string $name, int $size = 1): Swoole\Coroutine\Channel +function swoole_channel(string $name, int $size = 1): Channel { global $channel; if (!isset($channel[$name])) { diff --git a/src/OneBot/Config/Loader/AbstractFileLoader.php b/src/OneBot/Config/Loader/AbstractFileLoader.php index 148dadb..72cc6a4 100644 --- a/src/OneBot/Config/Loader/AbstractFileLoader.php +++ b/src/OneBot/Config/Loader/AbstractFileLoader.php @@ -9,9 +9,6 @@ abstract class AbstractFileLoader implements LoaderInterface { - /** - * {@inheritDoc} - */ public function load($source): array { // TODO: flexible base path diff --git a/src/OneBot/Config/Loader/DelegateLoader.php b/src/OneBot/Config/Loader/DelegateLoader.php index 071af74..2f1c9cc 100644 --- a/src/OneBot/Config/Loader/DelegateLoader.php +++ b/src/OneBot/Config/Loader/DelegateLoader.php @@ -14,7 +14,7 @@ class DelegateLoader implements LoaderInterface /** * @param null|array{string: LoaderInterface} $loaders 加载器列表,null则使用默认列表 */ - public function __construct(array $loaders = null) + public function __construct(?array $loaders = null) { foreach ((array) $loaders as $key => $loader) { if (!$loader instanceof LoaderInterface) { @@ -25,9 +25,6 @@ public function __construct(array $loaders = null) $this->loaders = $loaders ?? self::getDefaultLoaders(); } - /** - * {@inheritDoc} - */ public function load($source): array { return $this->determineLoader($source)->load($source); diff --git a/src/OneBot/Config/Loader/JsonFileLoader.php b/src/OneBot/Config/Loader/JsonFileLoader.php index b55f475..130ecca 100644 --- a/src/OneBot/Config/Loader/JsonFileLoader.php +++ b/src/OneBot/Config/Loader/JsonFileLoader.php @@ -6,9 +6,6 @@ class JsonFileLoader extends AbstractFileLoader { - /** - * {@inheritDoc} - */ protected function loadFile(string $file) { try { diff --git a/src/OneBot/Config/Loader/LoadException.php b/src/OneBot/Config/Loader/LoadException.php index 38f00b0..d63e262 100644 --- a/src/OneBot/Config/Loader/LoadException.php +++ b/src/OneBot/Config/Loader/LoadException.php @@ -4,6 +4,4 @@ namespace OneBot\Config\Loader; -class LoadException extends \RuntimeException -{ -} +class LoadException extends \RuntimeException {} diff --git a/src/OneBot/Config/Repository.php b/src/OneBot/Config/Repository.php index f60bcfb..c3dcd8f 100644 --- a/src/OneBot/Config/Repository.php +++ b/src/OneBot/Config/Repository.php @@ -21,9 +21,6 @@ public function __construct(array $config = []) $this->config = $config; } - /** - * {@inheritDoc} - */ public function get(string $key, $default = null) { // 在表层直接查找,找到就直接返回 @@ -51,9 +48,6 @@ public function get(string $key, $default = null) return $data; } - /** - * {@inheritDoc} - */ public function set(string $key, $value): void { if ($value === null) { @@ -75,17 +69,11 @@ public function set(string $key, $value): void $data = $value; } - /** - * {@inheritDoc} - */ public function has(string $key): bool { return $this->get($key) !== null; } - /** - * {@inheritDoc} - */ public function all(): array { return $this->config; diff --git a/src/OneBot/Driver/Event/DriverEvent.php b/src/OneBot/Driver/Event/DriverEvent.php index f46f999..cf5d87d 100644 --- a/src/OneBot/Driver/Event/DriverEvent.php +++ b/src/OneBot/Driver/Event/DriverEvent.php @@ -24,9 +24,6 @@ public static function getName(): string return static::$custom_name ?? static::class; } - /** - * {@inheritDoc} - */ public function isPropagationStopped(): bool { return $this->propagation_stopped; diff --git a/src/OneBot/Driver/Event/Event.php b/src/OneBot/Driver/Event/Event.php index 9c7c3b9..75943d4 100644 --- a/src/OneBot/Driver/Event/Event.php +++ b/src/OneBot/Driver/Event/Event.php @@ -4,6 +4,4 @@ namespace OneBot\Driver\Event; -interface Event -{ -} +interface Event {} diff --git a/src/OneBot/Driver/Event/Process/ManagerStartEvent.php b/src/OneBot/Driver/Event/Process/ManagerStartEvent.php index 028b368..4d2c443 100644 --- a/src/OneBot/Driver/Event/Process/ManagerStartEvent.php +++ b/src/OneBot/Driver/Event/Process/ManagerStartEvent.php @@ -6,6 +6,4 @@ use OneBot\Driver\Event\DriverEvent; -class ManagerStartEvent extends DriverEvent -{ -} +class ManagerStartEvent extends DriverEvent {} diff --git a/src/OneBot/Driver/Event/Process/ManagerStopEvent.php b/src/OneBot/Driver/Event/Process/ManagerStopEvent.php index aa83bd2..212c9b5 100644 --- a/src/OneBot/Driver/Event/Process/ManagerStopEvent.php +++ b/src/OneBot/Driver/Event/Process/ManagerStopEvent.php @@ -6,6 +6,4 @@ use OneBot\Driver\Event\DriverEvent; -class ManagerStopEvent extends DriverEvent -{ -} +class ManagerStopEvent extends DriverEvent {} diff --git a/src/OneBot/Driver/Event/Process/WorkerExitEvent.php b/src/OneBot/Driver/Event/Process/WorkerExitEvent.php index 3b26fd4..80098d8 100644 --- a/src/OneBot/Driver/Event/Process/WorkerExitEvent.php +++ b/src/OneBot/Driver/Event/Process/WorkerExitEvent.php @@ -6,6 +6,4 @@ use OneBot\Driver\Event\DriverEvent; -class WorkerExitEvent extends DriverEvent -{ -} +class WorkerExitEvent extends DriverEvent {} diff --git a/src/OneBot/Driver/Event/Process/WorkerStartEvent.php b/src/OneBot/Driver/Event/Process/WorkerStartEvent.php index 318a704..b5e8111 100644 --- a/src/OneBot/Driver/Event/Process/WorkerStartEvent.php +++ b/src/OneBot/Driver/Event/Process/WorkerStartEvent.php @@ -6,6 +6,4 @@ use OneBot\Driver\Event\DriverEvent; -class WorkerStartEvent extends DriverEvent -{ -} +class WorkerStartEvent extends DriverEvent {} diff --git a/src/OneBot/Driver/Event/Process/WorkerStopEvent.php b/src/OneBot/Driver/Event/Process/WorkerStopEvent.php index 931ba4d..80c826c 100644 --- a/src/OneBot/Driver/Event/Process/WorkerStopEvent.php +++ b/src/OneBot/Driver/Event/Process/WorkerStopEvent.php @@ -6,6 +6,4 @@ use OneBot\Driver\Event\DriverEvent; -class WorkerStopEvent extends DriverEvent -{ -} +class WorkerStopEvent extends DriverEvent {} diff --git a/src/OneBot/Driver/Event/StopException.php b/src/OneBot/Driver/Event/StopException.php index b5014aa..029e874 100644 --- a/src/OneBot/Driver/Event/StopException.php +++ b/src/OneBot/Driver/Event/StopException.php @@ -8,7 +8,7 @@ class StopException extends \Exception { private DriverEvent $event; - public function __construct(DriverEvent $event, $message = '', $code = 0, \Throwable $previous = null) + public function __construct(DriverEvent $event, $message = '', $code = 0, ?\Throwable $previous = null) { $this->event = $event; parent::__construct($message, $code, $previous); diff --git a/src/OneBot/Driver/Swoole/EventLoop.php b/src/OneBot/Driver/Swoole/EventLoop.php index 498d44f..109b43e 100644 --- a/src/OneBot/Driver/Swoole/EventLoop.php +++ b/src/OneBot/Driver/Swoole/EventLoop.php @@ -10,17 +10,11 @@ class EventLoop extends DriverEventLoopBase { - /** - * {@inheritDoc} - */ public function addReadEvent($fd, callable $callable) { Event::add($fd, $callable); } - /** - * {@inheritDoc} - */ public function delReadEvent($fd) { Event::del($fd); @@ -36,9 +30,6 @@ public function delWriteEvent($fd) Event::del($fd); } - /** - * {@inheritDoc} - */ public function addTimer(int $ms, callable $callable, int $times = 1, array $arguments = []): int { $timer_count = 0; @@ -54,17 +45,11 @@ public function addTimer(int $ms, callable $callable, int $times = 1, array $arg }, ...$arguments); } - /** - * {@inheritDoc} - */ public function clearTimer(int $timer_id) { Timer::clear($timer_id); } - /** - * {@inheritDoc} - */ public function clearAllTimer() { Timer::clearAll(); diff --git a/src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php b/src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php index da68b22..4e13117 100644 --- a/src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php +++ b/src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php @@ -6,6 +6,4 @@ use OneBot\Driver\Socket\HttpClientSocketBase; -class HttpClientSocket extends HttpClientSocketBase -{ -} +class HttpClientSocket extends HttpClientSocketBase {} diff --git a/src/OneBot/Driver/Swoole/Socket/WSClientSocket.php b/src/OneBot/Driver/Swoole/Socket/WSClientSocket.php index c61a383..4ff0876 100644 --- a/src/OneBot/Driver/Swoole/Socket/WSClientSocket.php +++ b/src/OneBot/Driver/Swoole/Socket/WSClientSocket.php @@ -6,6 +6,4 @@ use OneBot\Driver\Socket\WSClientSocketBase; -class WSClientSocket extends WSClientSocketBase -{ -} +class WSClientSocket extends WSClientSocketBase {} diff --git a/src/OneBot/Driver/Swoole/Socket/WSServerSocket.php b/src/OneBot/Driver/Swoole/Socket/WSServerSocket.php index bc87bcd..272d6af 100644 --- a/src/OneBot/Driver/Swoole/Socket/WSServerSocket.php +++ b/src/OneBot/Driver/Swoole/Socket/WSServerSocket.php @@ -27,9 +27,6 @@ public function close($fd): bool return false; } - /** - * {@inheritDoc} - */ public function send($data, $fd): bool { if ($data instanceof FrameInterface) { diff --git a/src/OneBot/Driver/Swoole/SwooleDriver.php b/src/OneBot/Driver/Swoole/SwooleDriver.php index c9ad016..85a17bc 100644 --- a/src/OneBot/Driver/Swoole/SwooleDriver.php +++ b/src/OneBot/Driver/Swoole/SwooleDriver.php @@ -59,9 +59,6 @@ public function getEventLoop(): DriverEventLoopBase return EventLoop::getInstance(); } - /** - * {@inheritDoc} - */ public function initInternalDriverClasses(?array $http, ?array $http_webhook, ?array $ws, ?array $ws_reverse): array { if (!empty($ws)) { diff --git a/src/OneBot/Driver/Workerman/EventLoop.php b/src/OneBot/Driver/Workerman/EventLoop.php index 2f7193b..623ceea 100644 --- a/src/OneBot/Driver/Workerman/EventLoop.php +++ b/src/OneBot/Driver/Workerman/EventLoop.php @@ -10,9 +10,6 @@ class EventLoop extends DriverEventLoopBase { - /** - * {@inheritDoc} - */ public function addTimer(int $ms, callable $callable, int $times = 1, array $arguments = []): int { $timer_count = 0; @@ -28,49 +25,31 @@ public function addTimer(int $ms, callable $callable, int $times = 1, array $arg }, $arguments); } - /** - * {@inheritDoc} - */ public function clearTimer(int $timer_id) { Timer::del($timer_id); } - /** - * {@inheritDoc} - */ public function addReadEvent($fd, callable $callable) { Worker::getEventLoop()->add($fd, EventInterface::EV_READ, $callable); } - /** - * {@inheritDoc} - */ public function delReadEvent($fd) { Worker::getEventLoop()->del($fd, EventInterface::EV_READ); } - /** - * {@inheritDoc} - */ public function addWriteEvent($fd, callable $callable) { Worker::getEventLoop()->add($fd, EventInterface::EV_WRITE, $callable); } - /** - * {@inheritDoc} - */ public function delWriteEvent($fd) { Worker::getEventLoop()->del($fd, EventInterface::EV_WRITE); } - /** - * {@inheritDoc} - */ public function clearAllTimer() { Timer::delAll(); diff --git a/src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php b/src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php index 6e21cdf..15cf0d1 100644 --- a/src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php +++ b/src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php @@ -6,6 +6,4 @@ use OneBot\Driver\Socket\HttpClientSocketBase; -class HttpClientSocket extends HttpClientSocketBase -{ -} +class HttpClientSocket extends HttpClientSocketBase {} diff --git a/src/OneBot/Driver/Workerman/Socket/WSClientSocket.php b/src/OneBot/Driver/Workerman/Socket/WSClientSocket.php index ca62466..e8540e9 100644 --- a/src/OneBot/Driver/Workerman/Socket/WSClientSocket.php +++ b/src/OneBot/Driver/Workerman/Socket/WSClientSocket.php @@ -6,6 +6,4 @@ use OneBot\Driver\Socket\WSClientSocketBase; -class WSClientSocket extends WSClientSocketBase -{ -} +class WSClientSocket extends WSClientSocketBase {} diff --git a/src/OneBot/Driver/Workerman/Worker.php b/src/OneBot/Driver/Workerman/Worker.php index 73c58e3..09a5db9 100644 --- a/src/OneBot/Driver/Workerman/Worker.php +++ b/src/OneBot/Driver/Workerman/Worker.php @@ -117,11 +117,11 @@ public static function stopAll($code = 0, $log = '') } foreach ($worker_pid_array as $worker_pid) { \posix_kill($worker_pid, $sig); - if (!static::$_gracefulStop){ + if (!static::$_gracefulStop) { Timer::add(static::$stopTimeout, '\posix_kill', [$worker_pid, \SIGKILL], false); } } - Timer::add(1, '\\Workerman\\Worker::checkIfChildRunning'); + Timer::add(1, '\Workerman\Worker::checkIfChildRunning'); // Remove statistics file. if (\is_file(static::$_statisticsFile)) { @\unlink(static::$_statisticsFile); @@ -130,7 +130,7 @@ public static function stopAll($code = 0, $log = '') else { // Execute exit. foreach (static::$_workers as $worker) { - if (!$worker->stopping){ + if (!$worker->stopping) { $worker->stop(); $worker->stopping = true; } @@ -156,7 +156,8 @@ public static function stopAll($code = 0, $log = '') * * @return array */ - public static function getStartFilesForWindows() { + public static function getStartFilesForWindows() + { return ['']; } @@ -303,7 +304,7 @@ protected static function parseCommand(): void } static::safeEcho("\nPress Ctrl+C to quit.\n\n"); } - // no break + // no break case 'connections': if (\is_file($statistics_file) && is_writable($statistics_file)) { \unlink($statistics_file); diff --git a/src/OneBot/Driver/Workerman/WorkermanDriver.php b/src/OneBot/Driver/Workerman/WorkermanDriver.php index deb37c4..9c82ea7 100644 --- a/src/OneBot/Driver/Workerman/WorkermanDriver.php +++ b/src/OneBot/Driver/Workerman/WorkermanDriver.php @@ -58,9 +58,6 @@ public function getWSServerSocketByWorker(Worker $worker): ?WSServerSocket return null; } - /** - * {@inheritDoc} - */ public function run(): void { try { @@ -121,8 +118,6 @@ public function getName(): string } /** - * {@inheritDoc} - * * @throws \Exception */ public function initWSReverseClients(array $headers = []) diff --git a/src/OneBot/V12/Action/DefaultActionHandler.php b/src/OneBot/V12/Action/DefaultActionHandler.php index a8ee336..39c38b9 100644 --- a/src/OneBot/V12/Action/DefaultActionHandler.php +++ b/src/OneBot/V12/Action/DefaultActionHandler.php @@ -7,6 +7,4 @@ /** * 当未设置 Action 基础处理类时,将默认使用 ActionBase 级别的所有 Not Implemented Action */ -class DefaultActionHandler extends ActionHandlerBase -{ -} +class DefaultActionHandler extends ActionHandlerBase {} diff --git a/src/OneBot/V12/EventBuilder.php b/src/OneBot/V12/EventBuilder.php index 1da622f..8ace3e9 100644 --- a/src/OneBot/V12/EventBuilder.php +++ b/src/OneBot/V12/EventBuilder.php @@ -36,7 +36,7 @@ public function valid(): bool try { $this->event = new OneBotEvent($this->data); return true; - }catch (OneBotException $e) { + } catch (OneBotException $e) { return false; } } diff --git a/src/OneBot/V12/Exception/OneBotException.php b/src/OneBot/V12/Exception/OneBotException.php index 91d7b50..88860f9 100644 --- a/src/OneBot/V12/Exception/OneBotException.php +++ b/src/OneBot/V12/Exception/OneBotException.php @@ -4,6 +4,4 @@ namespace OneBot\V12\Exception; -class OneBotException extends \Exception -{ -} +class OneBotException extends \Exception {} diff --git a/src/OneBot/V12/Exception/OneBotFailureException.php b/src/OneBot/V12/Exception/OneBotFailureException.php index 89576f6..85efc12 100644 --- a/src/OneBot/V12/Exception/OneBotFailureException.php +++ b/src/OneBot/V12/Exception/OneBotFailureException.php @@ -20,7 +20,7 @@ public function __construct( $retcode = RetCode::INTERNAL_HANDLER_ERROR, ?Action $action_object = null, $message = null, - \Exception $previous = null + ?\Exception $previous = null ) { $this->retcode = $retcode; $this->action_object = $action_object; diff --git a/src/OneBot/V12/OneBot.php b/src/OneBot/V12/OneBot.php index ecc8a81..b57e038 100644 --- a/src/OneBot/V12/OneBot.php +++ b/src/OneBot/V12/OneBot.php @@ -250,8 +250,7 @@ public function dispatchEvent(OneBotEvent $event): void } $socket->post(json_encode($event->jsonSerialize()), $this->getRequestHeaders(), function (ResponseInterface $response) { // TODO:编写 HTTP Webhook 响应的处理逻辑 - }, function (RequestInterface $request) { - }); + }, function (RequestInterface $request) {}); } $frame_str = FrameFactory::createTextFrame(json_encode($event->jsonSerialize())); // 创建文本帧 foreach ($this->driver->getWSServerSockets() as $socket) { diff --git a/src/OneBot/V12/OneBotBuilder.php b/src/OneBot/V12/OneBotBuilder.php index 767d881..244ee9d 100644 --- a/src/OneBot/V12/OneBotBuilder.php +++ b/src/OneBot/V12/OneBotBuilder.php @@ -5,6 +5,7 @@ namespace OneBot\V12; use OneBot\Config\Config; +use OneBot\Config\Repository; use OneBot\Config\RepositoryInterface; use OneBot\Driver\Driver; use Psr\Log\LoggerInterface; @@ -136,7 +137,7 @@ public function build(): OneBot */ public static function buildFromArray(array $array): OneBot { - $config = new \OneBot\Config\Repository($array); + $config = new Repository($array); return self::buildFromConfig($config); } diff --git a/src/OneBot/global_defines.php b/src/OneBot/global_defines.php index da0ea84..ab224ff 100644 --- a/src/OneBot/global_defines.php +++ b/src/OneBot/global_defines.php @@ -10,10 +10,11 @@ use OneBot\V12\Object\MessageSegment; use OneBot\V12\OneBot; use Psr\Log\LoggerInterface; +use Symfony\Component\VarDumper\VarDumper; use ZM\Logger\ConsoleLogger; const ONEBOT_VERSION = '12'; -const ONEBOT_LIBOB_VERSION = '0.6.6'; +const ONEBOT_LIBOB_VERSION = '0.6.7'; const ONEBOT_JSON = 1; const ONEBOT_MSGPACK = 2; @@ -38,7 +39,7 @@ class_alias(MessageSegment::class, 'MessageSegment'); if (DIRECTORY_SEPARATOR === '\\') { - define('ONEBOT_TMP_DIR', 'C:\\Windows\\Temp'); + define('ONEBOT_TMP_DIR', 'C:\Windows\Temp'); } elseif (!empty(getenv('TMPDIR'))) { define('ONEBOT_TMP_DIR', getenv('TMPDIR')); } elseif (is_writable('/tmp')) { @@ -56,9 +57,9 @@ class_alias(MessageSegment::class, 'MessageSegment'); function ob_dump($var, ...$moreVars) { if (class_exists('\Symfony\Component\VarDumper\VarDumper')) { - Symfony\Component\VarDumper\VarDumper::dump($var); + VarDumper::dump($var); foreach ($moreVars as $v) { - Symfony\Component\VarDumper\VarDumper::dump($v); + VarDumper::dump($v); } } elseif (PHP_VERSION >= 8.0) { var_dump($var, ...$moreVars); @@ -121,7 +122,7 @@ function ob_logger_register(LoggerInterface $logger): void * @param null|mixed $default * @return mixed */ -function ob_config(string $key = null, $default = null) +function ob_config(?string $key = null, $default = null) { $config = OneBot::getInstance()->getConfig(); if (!is_null($key)) { @@ -144,8 +145,8 @@ function ob_uuidgen(bool $uppercase = false): string } $data[6] = chr(ord($data[6]) & 0x0F | 0x40); $data[8] = chr(ord($data[8]) & 0x3F | 0x80); - return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4))) : - vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4))) + : vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } function ob_event_dispatcher(): HandledDispatcherInterface diff --git a/tests/OneBot/Config/Loader/AbstractFileLoaderTest.php b/tests/OneBot/Config/Loader/AbstractFileLoaderTest.php index b5c9697..dd62e00 100644 --- a/tests/OneBot/Config/Loader/AbstractFileLoaderTest.php +++ b/tests/OneBot/Config/Loader/AbstractFileLoaderTest.php @@ -45,15 +45,15 @@ public function providerTestGetAbsolutePath(): array 'Linux', ], 'windows absolute path' => [ - 'C:\\Windows\\System32\\drivers\\etc\\hosts', - 'C:\\Windows\\System32', - 'C:\\Windows\\System32\\drivers\\etc\\hosts', + 'C:\Windows\System32\drivers\etc\hosts', + 'C:\Windows\System32', + 'C:\Windows\System32\drivers\etc\hosts', 'Windows', ], 'windows relative path' => [ - 'drivers\\etc\\hosts', - 'C:\\Windows\\System32', - 'C:\\Windows\\System32\\drivers\\etc\\hosts', + 'drivers\etc\hosts', + 'C:\Windows\System32', + 'C:\Windows\System32\drivers\etc\hosts', 'Windows', ], ]; diff --git a/tests/OneBot/Config/RepositoryTest.php b/tests/OneBot/Config/RepositoryTest.php index 3b09082..e9770c6 100644 --- a/tests/OneBot/Config/RepositoryTest.php +++ b/tests/OneBot/Config/RepositoryTest.php @@ -49,12 +49,12 @@ protected function setUp(): void ); } -// 尚未确定是否应该支持 -// public function testGetValueWhenKeyContainsDot(): void -// { -// $this->assertEquals('c', $this->repository->get('a.b')); -// $this->assertEquals('d', $this->repository->get('a.b.c')); -// } + // 尚未确定是否应该支持 + // public function testGetValueWhenKeyContainsDot(): void + // { + // $this->assertEquals('c', $this->repository->get('a.b')); + // $this->assertEquals('d', $this->repository->get('a.b.c')); + // } public function testGetBooleanValue(): void { @@ -109,6 +109,16 @@ public function testDeleteValue(string $key): void $this->assertNull($this->repository->get($key)); } + public function providerTestDeleteValue(): array + { + return [ + 'shallow' => ['foo'], + 'deep' => ['associate.x'], + 'not exists' => ['not_exists'], + 'not exists deep' => ['deep.not_exists'], + ]; + } + public function testHas(): void { $this->assertTrue($this->repository->has('foo')); @@ -119,14 +129,4 @@ public function testAll(): void { $this->assertSame($this->config, $this->repository->all()); } - - public function providerTestDeleteValue(): array - { - return [ - 'shallow' => ['foo'], - 'deep' => ['associate.x'], - 'not exists' => ['not_exists'], - 'not exists deep' => ['deep.not_exists'], - ]; - } } diff --git a/tests/OneBot/Exception/ExceptionHandlerTest.php b/tests/OneBot/Exception/ExceptionHandlerTest.php index c7261d6..f074a5b 100644 --- a/tests/OneBot/Exception/ExceptionHandlerTest.php +++ b/tests/OneBot/Exception/ExceptionHandlerTest.php @@ -4,6 +4,7 @@ namespace Tests\OneBot\Exception; +use OneBot\Exception\ExceptionHandler; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; @@ -20,7 +21,7 @@ public function testCanHandleWithoutOverriding(): void ob_logger_register(new NullLogger()); // we want fresh instance here, since it's a singleton, we use reflection to get a new instance - $reflection = new \ReflectionClass(\OneBot\Exception\ExceptionHandler::class); + $reflection = new \ReflectionClass(ExceptionHandler::class); $instance = $reflection->newInstanceWithoutConstructor(); // expect handle() to not throw any exception $this->expectNotToPerformAssertions(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4e80822..b49071e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,6 +3,7 @@ declare(strict_types=1); use OneBot\Driver\Workerman\WorkermanDriver; +use OneBot\Util\FileUtil; use OneBot\V12\OneBotBuilder; use ZM\Logger\ConsoleLogger; @@ -17,4 +18,4 @@ ->setCommunicationsProtocol([['http' => ['host' => '0.0.0.0', 'port' => 20001]]]) ->build(); -$ob->getConfig()->set('file_upload.path', \OneBot\Util\FileUtil::getRealPath(__DIR__ . '/../data/files')); +$ob->getConfig()->set('file_upload.path', FileUtil::getRealPath(__DIR__ . '/../data/files')); From f4bd4c1ff67f059b52a93bfac44ec0b9987972c5 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 10 Mar 2025 10:43:49 +0800 Subject: [PATCH 2/2] Abandon develop --- .github/dependabot.yml | 2 +- .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b5cacc0..377121a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,6 +4,6 @@ updates: directory: "/" schedule: interval: "daily" - target-branch: "develop" + target-branch: "master" labels: - "area/dependency" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aaf76a7..647e4ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ name: Test on: push: branches: + - master - main - develop - '*-dev*'