Skip to content

Commit db36e24

Browse files
authored
Update all things to PHP 8.4 (#112)
* Update all things to PHP 8.4 * Abandon develop
1 parent 3785a0d commit db36e24

30 files changed

+65
-81
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "daily"
7-
target-branch: "develop"
7+
target-branch: "master"
88
labels:
99
- "area/dependency"

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Test
33
on:
44
push:
55
branches:
6+
- master
67
- main
78
- develop
89
- '*-dev*'

choir-test.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
/** @noinspection PhpComposerExtensionStubsInspection */
44

55
declare(strict_types=1);
6+
use Choir\Http\Server;
7+
use Choir\Protocol\HttpConnection;
68

79
require_once 'vendor/autoload.php';
810

9-
$server = new \Choir\Http\Server('0.0.0.0', 20001, false, [
11+
$server = new Server('0.0.0.0', 20001, false, [
1012
'worker-num' => 8,
1113
// 'logger-level' => 'debug',
1214
]);
@@ -22,7 +24,7 @@
2224
// echo "http://127.0.0.1:8080/index.php?run={$id}&source=xhprof_testing\n";
2325
});
2426

25-
$server->on('request', function (Choir\Protocol\HttpConnection $connection) {
27+
$server->on('request', function (HttpConnection $connection) {
2628
$connection->end('hello world');
2729
});
2830

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"wiki": "https://github.com/botuniverse/php-libonebot/wiki"
2626
},
2727
"require": {
28-
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2",
28+
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4",
2929
"ext-json": "*",
3030
"psr/cache": "^1.0 || ^3.0",
3131
"psr/event-dispatcher": "^1.0",
@@ -85,7 +85,7 @@
8585
"[ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/cghooks add"
8686
],
8787
"analyse": "phpstan analyse --memory-limit 300M",
88-
"cs-fix": "php-cs-fixer fix",
88+
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
8989
"test": "phpunit --no-coverage"
9090
}
9191
}

demo/repl.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
declare(strict_types=1);
44

55
use OneBot\Driver\Event\DriverInitEvent;
6+
use OneBot\Driver\Swoole\SwooleDriver;
67
use OneBot\Util\Utils;
8+
use OneBot\V12\EventBuilder;
79
use OneBot\V12\Object\Action;
810
use OneBot\V12\Object\ActionResponse;
911
use OneBot\V12\OneBot;
1012
use OneBot\V12\OneBotBuilder;
1113
use OneBot\V12\Validator;
14+
use ZM\Logger\ConsoleLogger;
1215

1316
require_once __DIR__ . '/../vendor/autoload.php';
1417

@@ -23,11 +26,11 @@ function message_id(): string
2326
'self_id' => 'REPL-1',
2427
'db' => true,
2528
'logger' => [
26-
'class' => \ZM\Logger\ConsoleLogger::class,
29+
'class' => ConsoleLogger::class,
2730
'level' => 'info',
2831
],
2932
'driver' => [
30-
'class' => \OneBot\Driver\Swoole\SwooleDriver::class,
33+
'class' => SwooleDriver::class,
3134
'config' => [
3235
'init_in_user_process_block' => true,
3336
],
@@ -81,7 +84,7 @@ function message_id(): string
8184
$event->getDriver()->getEventLoop()->delReadEvent($x);
8285
return;
8386
}
84-
$event = (new \OneBot\V12\EventBuilder('message', 'private'))
87+
$event = (new EventBuilder('message', 'private'))
8588
->feed('message', trim($s))
8689
->feed('alt_message', trim($s))
8790
->feed('message_id', message_id())

demo/weixin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OneBot\V12\RetCode;
1616
use OneBot\V12\Validator;
1717
use Swoole\Coroutine\Channel;
18+
use ZM\Logger\ConsoleLogger;
1819

1920
require_once __DIR__ . '/../vendor/autoload.php';
2021

@@ -24,7 +25,7 @@
2425
'self_id' => '', // 后续会自动获取
2526
'db' => true,
2627
'logger' => [
27-
'class' => \ZM\Logger\ConsoleLogger::class,
28+
'class' => ConsoleLogger::class,
2829
'level' => 'info',
2930
],
3031
'driver' => [
@@ -118,7 +119,7 @@ function wx_make_xml_reply(Action $action, string $self_id): string
118119
return str_replace('{content}', '<![CDATA[' . $content . ']]>', $xml_template);
119120
}
120121

121-
function swoole_channel(string $name, int $size = 1): Swoole\Coroutine\Channel
122+
function swoole_channel(string $name, int $size = 1): Channel
122123
{
123124
global $channel;
124125
if (!isset($channel[$name])) {

src/OneBot/Config/Loader/DelegateLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DelegateLoader implements LoaderInterface
1414
/**
1515
* @param null|array{string: LoaderInterface} $loaders 加载器列表,null则使用默认列表
1616
*/
17-
public function __construct(array $loaders = null)
17+
public function __construct(?array $loaders = null)
1818
{
1919
foreach ((array) $loaders as $key => $loader) {
2020
if (!$loader instanceof LoaderInterface) {

src/OneBot/Config/Loader/LoadException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace OneBot\Config\Loader;
66

7-
class LoadException extends \RuntimeException
8-
{
9-
}
7+
class LoadException extends \RuntimeException {}

src/OneBot/Driver/Event/Event.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace OneBot\Driver\Event;
66

7-
interface Event
8-
{
9-
}
7+
interface Event {}

src/OneBot/Driver/Event/Process/ManagerStartEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Event\DriverEvent;
88

9-
class ManagerStartEvent extends DriverEvent
10-
{
11-
}
9+
class ManagerStartEvent extends DriverEvent {}

src/OneBot/Driver/Event/Process/ManagerStopEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Event\DriverEvent;
88

9-
class ManagerStopEvent extends DriverEvent
10-
{
11-
}
9+
class ManagerStopEvent extends DriverEvent {}

src/OneBot/Driver/Event/Process/WorkerExitEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Event\DriverEvent;
88

9-
class WorkerExitEvent extends DriverEvent
10-
{
11-
}
9+
class WorkerExitEvent extends DriverEvent {}

src/OneBot/Driver/Event/Process/WorkerStartEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Event\DriverEvent;
88

9-
class WorkerStartEvent extends DriverEvent
10-
{
11-
}
9+
class WorkerStartEvent extends DriverEvent {}

src/OneBot/Driver/Event/Process/WorkerStopEvent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Event\DriverEvent;
88

9-
class WorkerStopEvent extends DriverEvent
10-
{
11-
}
9+
class WorkerStopEvent extends DriverEvent {}

src/OneBot/Driver/Event/StopException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class StopException extends \Exception
88
{
99
private DriverEvent $event;
1010

11-
public function __construct(DriverEvent $event, $message = '', $code = 0, \Throwable $previous = null)
11+
public function __construct(DriverEvent $event, $message = '', $code = 0, ?\Throwable $previous = null)
1212
{
1313
$this->event = $event;
1414
parent::__construct($message, $code, $previous);

src/OneBot/Driver/Swoole/Socket/HttpClientSocket.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Socket\HttpClientSocketBase;
88

9-
class HttpClientSocket extends HttpClientSocketBase
10-
{
11-
}
9+
class HttpClientSocket extends HttpClientSocketBase {}

src/OneBot/Driver/Swoole/Socket/WSClientSocket.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Socket\WSClientSocketBase;
88

9-
class WSClientSocket extends WSClientSocketBase
10-
{
11-
}
9+
class WSClientSocket extends WSClientSocketBase {}

src/OneBot/Driver/Workerman/Socket/HttpClientSocket.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Socket\HttpClientSocketBase;
88

9-
class HttpClientSocket extends HttpClientSocketBase
10-
{
11-
}
9+
class HttpClientSocket extends HttpClientSocketBase {}

src/OneBot/Driver/Workerman/Socket/WSClientSocket.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77
use OneBot\Driver\Socket\WSClientSocketBase;
88

9-
class WSClientSocket extends WSClientSocketBase
10-
{
11-
}
9+
class WSClientSocket extends WSClientSocketBase {}

src/OneBot/Driver/Workerman/Worker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static function stopAll($code = 0, $log = '')
121121
Timer::add(static::$stopTimeout, '\posix_kill', [$worker_pid, \SIGKILL], false);
122122
}
123123
}
124-
Timer::add(1, '\\Workerman\\Worker::checkIfChildRunning');
124+
Timer::add(1, '\Workerman\Worker::checkIfChildRunning');
125125
// Remove statistics file.
126126
if (\is_file(static::$_statisticsFile)) {
127127
@\unlink(static::$_statisticsFile);

src/OneBot/V12/Action/DefaultActionHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
/**
88
* 当未设置 Action 基础处理类时,将默认使用 ActionBase 级别的所有 Not Implemented Action
99
*/
10-
class DefaultActionHandler extends ActionHandlerBase
11-
{
12-
}
10+
class DefaultActionHandler extends ActionHandlerBase {}

src/OneBot/V12/Exception/OneBotException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
namespace OneBot\V12\Exception;
66

7-
class OneBotException extends \Exception
8-
{
9-
}
7+
class OneBotException extends \Exception {}

src/OneBot/V12/Exception/OneBotFailureException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
$retcode = RetCode::INTERNAL_HANDLER_ERROR,
2121
?Action $action_object = null,
2222
$message = null,
23-
\Exception $previous = null
23+
?\Exception $previous = null
2424
) {
2525
$this->retcode = $retcode;
2626
$this->action_object = $action_object;

src/OneBot/V12/OneBot.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ public function dispatchEvent(OneBotEvent $event): void
250250
}
251251
$socket->post(json_encode($event->jsonSerialize()), $this->getRequestHeaders(), function (ResponseInterface $response) {
252252
// TODO:编写 HTTP Webhook 响应的处理逻辑
253-
}, function (RequestInterface $request) {
254-
});
253+
}, function (RequestInterface $request) {});
255254
}
256255
$frame_str = FrameFactory::createTextFrame(json_encode($event->jsonSerialize())); // 创建文本帧
257256
foreach ($this->driver->getWSServerSockets() as $socket) {

src/OneBot/V12/OneBotBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace OneBot\V12;
66

77
use OneBot\Config\Config;
8+
use OneBot\Config\Repository;
89
use OneBot\Config\RepositoryInterface;
910
use OneBot\Driver\Driver;
1011
use Psr\Log\LoggerInterface;
@@ -136,7 +137,7 @@ public function build(): OneBot
136137
*/
137138
public static function buildFromArray(array $array): OneBot
138139
{
139-
$config = new \OneBot\Config\Repository($array);
140+
$config = new Repository($array);
140141
return self::buildFromConfig($config);
141142
}
142143

src/OneBot/global_defines.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
use OneBot\V12\Object\MessageSegment;
1111
use OneBot\V12\OneBot;
1212
use Psr\Log\LoggerInterface;
13+
use Symfony\Component\VarDumper\VarDumper;
1314
use ZM\Logger\ConsoleLogger;
1415

1516
const ONEBOT_VERSION = '12';
16-
const ONEBOT_LIBOB_VERSION = '0.6.8';
17+
const ONEBOT_LIBOB_VERSION = '0.6.9';
1718

1819
const ONEBOT_JSON = 1;
1920
const ONEBOT_MSGPACK = 2;
@@ -38,7 +39,7 @@
3839
class_alias(MessageSegment::class, 'MessageSegment');
3940

4041
if (DIRECTORY_SEPARATOR === '\\') {
41-
define('ONEBOT_TMP_DIR', 'C:\\Windows\\Temp');
42+
define('ONEBOT_TMP_DIR', 'C:\Windows\Temp');
4243
} elseif (!empty(getenv('TMPDIR'))) {
4344
define('ONEBOT_TMP_DIR', getenv('TMPDIR'));
4445
} elseif (is_writable('/tmp')) {
@@ -56,9 +57,9 @@ class_alias(MessageSegment::class, 'MessageSegment');
5657
function ob_dump($var, ...$moreVars)
5758
{
5859
if (class_exists('\Symfony\Component\VarDumper\VarDumper')) {
59-
Symfony\Component\VarDumper\VarDumper::dump($var);
60+
VarDumper::dump($var);
6061
foreach ($moreVars as $v) {
61-
Symfony\Component\VarDumper\VarDumper::dump($v);
62+
VarDumper::dump($v);
6263
}
6364
} elseif (PHP_VERSION >= 8.0) {
6465
var_dump($var, ...$moreVars);
@@ -121,7 +122,7 @@ function ob_logger_register(LoggerInterface $logger): void
121122
* @param null|mixed $default
122123
* @return mixed
123124
*/
124-
function ob_config(string $key = null, $default = null)
125+
function ob_config(?string $key = null, $default = null)
125126
{
126127
$config = OneBot::getInstance()->getConfig();
127128
if (!is_null($key)) {
@@ -144,8 +145,8 @@ function ob_uuidgen(bool $uppercase = false): string
144145
}
145146
$data[6] = chr(ord($data[6]) & 0x0F | 0x40);
146147
$data[8] = chr(ord($data[8]) & 0x3F | 0x80);
147-
return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4))) :
148-
vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
148+
return $uppercase ? strtoupper(vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)))
149+
: vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
149150
}
150151

151152
function ob_event_dispatcher(): HandledDispatcherInterface

tests/OneBot/Config/Loader/AbstractFileLoaderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function providerTestGetAbsolutePath(): array
4545
'Linux',
4646
],
4747
'windows absolute path' => [
48-
'C:\\Windows\\System32\\drivers\\etc\\hosts',
49-
'C:\\Windows\\System32',
50-
'C:\\Windows\\System32\\drivers\\etc\\hosts',
48+
'C:\Windows\System32\drivers\etc\hosts',
49+
'C:\Windows\System32',
50+
'C:\Windows\System32\drivers\etc\hosts',
5151
'Windows',
5252
],
5353
'windows relative path' => [
54-
'drivers\\etc\\hosts',
55-
'C:\\Windows\\System32',
56-
'C:\\Windows\\System32\\drivers\\etc\\hosts',
54+
'drivers\etc\hosts',
55+
'C:\Windows\System32',
56+
'C:\Windows\System32\drivers\etc\hosts',
5757
'Windows',
5858
],
5959
];

tests/OneBot/Config/RepositoryTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function testDeleteValue(string $key): void
109109
$this->assertNull($this->repository->get($key));
110110
}
111111

112+
public function providerTestDeleteValue(): array
113+
{
114+
return [
115+
'shallow' => ['foo'],
116+
'deep' => ['associate.x'],
117+
'not exists' => ['not_exists'],
118+
'not exists deep' => ['deep.not_exists'],
119+
];
120+
}
121+
112122
public function testHas(): void
113123
{
114124
$this->assertTrue($this->repository->has('foo'));
@@ -119,14 +129,4 @@ public function testAll(): void
119129
{
120130
$this->assertSame($this->config, $this->repository->all());
121131
}
122-
123-
public function providerTestDeleteValue(): array
124-
{
125-
return [
126-
'shallow' => ['foo'],
127-
'deep' => ['associate.x'],
128-
'not exists' => ['not_exists'],
129-
'not exists deep' => ['deep.not_exists'],
130-
];
131-
}
132132
}

0 commit comments

Comments
 (0)