diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index b336ed07c..6dda3026a 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -66,6 +66,8 @@ 'multiline_comment_opening_closing' => true, 'phpdoc_summary' => false, 'php_unit_test_class_requires_covers' => false, + 'fully_qualified_strict_types' => false, + 'new_with_parentheses' => false, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/src/Globals/global_defines_app.php b/src/Globals/global_defines_app.php index 4e9016087..ab9e50c2c 100644 --- a/src/Globals/global_defines_app.php +++ b/src/Globals/global_defines_app.php @@ -65,7 +65,7 @@ define('SOURCE_ROOT_DIR', Phar::running() !== '' ? Phar::running() : WORKING_DIR); if (DIRECTORY_SEPARATOR === '\\') { - define('TMP_DIR', 'C:\\Windows\\Temp'); + define('TMP_DIR', 'C:\Windows\Temp'); } elseif (!empty(getenv('TMPDIR'))) { define('TMP_DIR', getenv('TMPDIR')); } elseif (is_writable('/tmp')) { diff --git a/src/Globals/global_functions.php b/src/Globals/global_functions.php index ea1404ba4..3971044d7 100644 --- a/src/Globals/global_functions.php +++ b/src/Globals/global_functions.php @@ -13,7 +13,6 @@ use OneBot\V12\Object\MessageSegment; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; -use Psr\SimpleCache\CacheInterface; use ZM\Config\Environment; use ZM\Config\ZMConfig; use ZM\Container\ContainerHolder; @@ -148,7 +147,7 @@ function is_assoc_array(array $array): bool */ function match_pattern(string $pattern, string $subject): bool { - $pattern = str_replace(['\*', '\\\\.*'], ['.*', '\*'], preg_quote($pattern, '/')); + $pattern = str_replace(['\*', '\\\.*'], ['.*', '\*'], preg_quote($pattern, '/')); $pattern = '/^' . $pattern . '$/i'; return preg_match($pattern, $subject) === 1; } @@ -302,7 +301,7 @@ function redis(string $name = 'default'): RedisWrapper * @param null|mixed $default 默认值 * @return mixed|void|ZMConfig */ -function config(array|string $key = null, mixed $default = null) +function config(null|array|string $key = null, mixed $default = null) { $config = ZMConfig::getInstance(); if (is_null($key)) { @@ -328,8 +327,7 @@ function bot_connect(int $flag, int $fd) /** * 获取一个 KV 库实例 * - * @param string $name KV 库名称 - * @return CacheInterface + * @param string $name KV 库名称 */ function kv(string $name = ''): Psr\SimpleCache\CacheInterface { diff --git a/src/Globals/script_setup_loader.php b/src/Globals/script_setup_loader.php index e3aaa997b..9060425c4 100644 --- a/src/Globals/script_setup_loader.php +++ b/src/Globals/script_setup_loader.php @@ -49,6 +49,6 @@ function _zm_setup_loader() // 在*nix等支持多进程环境的情况,可直接运行此文件,那么就执行 if (debug_backtrace() === []) { - require((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php'; + require ((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php'; echo _zm_setup_loader(); } diff --git a/src/ZM/Annotation/AnnotationBase.php b/src/ZM/Annotation/AnnotationBase.php index d73fc1919..d45179d06 100644 --- a/src/ZM/Annotation/AnnotationBase.php +++ b/src/ZM/Annotation/AnnotationBase.php @@ -7,7 +7,7 @@ abstract class AnnotationBase implements \IteratorAggregate, \Stringable { /** @var array|\Closure|string 方法名或闭包 */ - public \Closure|string|array $method = ''; + public array|\Closure|string $method = ''; public $class = ''; @@ -40,7 +40,7 @@ public function __toString(): string /** * 在 InstantPlugin 下调用,设置回调或匿名函数 */ - public function on(\Closure|callable|string $method): AnnotationBase + public function on(callable|\Closure|string $method): AnnotationBase { $this->method = $method; return $this; diff --git a/src/ZM/Annotation/AnnotationHandler.php b/src/ZM/Annotation/AnnotationHandler.php index 0b55fe66d..24c6e0012 100644 --- a/src/ZM/Annotation/AnnotationHandler.php +++ b/src/ZM/Annotation/AnnotationHandler.php @@ -21,7 +21,7 @@ class AnnotationHandler public const STATUS_RULE_FAILED = 4; // 判断事件执行的规则函数判定为false,所以不执行此方法 - private string|AnnotationBase $annotation_class; + private AnnotationBase|string $annotation_class; /** @var callable */ private $rule_callback; diff --git a/src/ZM/Annotation/Closed.php b/src/ZM/Annotation/Closed.php index cb2768017..792e0f445 100644 --- a/src/ZM/Annotation/Closed.php +++ b/src/ZM/Annotation/Closed.php @@ -4,7 +4,6 @@ namespace ZM\Annotation; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Target; @@ -15,6 +14,4 @@ * @Target("ALL") */ #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)] -class Closed extends AnnotationBase -{ -} +class Closed extends AnnotationBase {} diff --git a/src/ZM/Annotation/Framework/BindEvent.php b/src/ZM/Annotation/Framework/BindEvent.php index f2db5ca1f..257dcec5e 100644 --- a/src/ZM/Annotation/Framework/BindEvent.php +++ b/src/ZM/Annotation/Framework/BindEvent.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Framework; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; @@ -32,8 +31,7 @@ public function __construct( */ public string $event_class, public int $level = 800 - ) { - } + ) {} public function getLevel(): int { diff --git a/src/ZM/Annotation/Framework/Init.php b/src/ZM/Annotation/Framework/Init.php index ad4c82964..39ddd9b9f 100644 --- a/src/ZM/Annotation/Framework/Init.php +++ b/src/ZM/Annotation/Framework/Init.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Framework; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Target; use ZM\Annotation\AnnotationBase; @@ -20,9 +19,7 @@ #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] class Init extends AnnotationBase implements Level { - public function __construct(public int $worker = 0, public int $level = 20) - { - } + public function __construct(public int $worker = 0, public int $level = 20) {} public function getLevel() { diff --git a/src/ZM/Annotation/Framework/Setup.php b/src/ZM/Annotation/Framework/Setup.php index 9cff1246f..d991c4dbf 100644 --- a/src/ZM/Annotation/Framework/Setup.php +++ b/src/ZM/Annotation/Framework/Setup.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Framework; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Target; use ZM\Annotation\AnnotationBase; @@ -17,6 +16,4 @@ * @since 3.0.0 */ #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] -class Setup extends AnnotationBase -{ -} +class Setup extends AnnotationBase {} diff --git a/src/ZM/Annotation/Http/Controller.php b/src/ZM/Annotation/Http/Controller.php index 087fe5f9c..6d959867d 100644 --- a/src/ZM/Annotation/Http/Controller.php +++ b/src/ZM/Annotation/Http/Controller.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Http; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; @@ -25,6 +24,5 @@ public function __construct( * @Required() */ public string $prefix - ) { - } + ) {} } diff --git a/src/ZM/Annotation/Http/Route.php b/src/ZM/Annotation/Http/Route.php index 21c7f0c9a..4f0d88cb7 100644 --- a/src/ZM/Annotation/Http/Route.php +++ b/src/ZM/Annotation/Http/Route.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Http; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; @@ -30,8 +29,7 @@ public function __construct( * Routing path params binding. eg. {"id"="\d+"} */ public $params = [] - ) { - } + ) {} public static function make($route, $name = '', $request_method = ['GET', 'POST'], $params = []): static { diff --git a/src/ZM/Annotation/Interfaces/CustomAnnotation.php b/src/ZM/Annotation/Interfaces/CustomAnnotation.php index 1423f8ed2..60a0fcbc4 100644 --- a/src/ZM/Annotation/Interfaces/CustomAnnotation.php +++ b/src/ZM/Annotation/Interfaces/CustomAnnotation.php @@ -4,6 +4,4 @@ namespace ZM\Annotation\Interfaces; -interface CustomAnnotation -{ -} +interface CustomAnnotation {} diff --git a/src/ZM/Annotation/Interfaces/ErgodicAnnotation.php b/src/ZM/Annotation/Interfaces/ErgodicAnnotation.php index 1d9f92a9c..88f261631 100644 --- a/src/ZM/Annotation/Interfaces/ErgodicAnnotation.php +++ b/src/ZM/Annotation/Interfaces/ErgodicAnnotation.php @@ -4,6 +4,4 @@ namespace ZM\Annotation\Interfaces; -interface ErgodicAnnotation -{ -} +interface ErgodicAnnotation {} diff --git a/src/ZM/Annotation/Middleware/Middleware.php b/src/ZM/Annotation/Middleware/Middleware.php index 3269c62b7..5de9cda7a 100644 --- a/src/ZM/Annotation/Middleware/Middleware.php +++ b/src/ZM/Annotation/Middleware/Middleware.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\Middleware; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\Common\Annotations\Annotation\Target; @@ -22,6 +21,7 @@ class Middleware extends AnnotationBase implements ErgodicAnnotation { /** * @param string[] $args + * @param mixed $name */ public function __construct( /** @@ -29,6 +29,5 @@ public function __construct( */ public $name, public array $args = [] - ) { - } + ) {} } diff --git a/src/ZM/Annotation/OneBot/BotAction.php b/src/ZM/Annotation/OneBot/BotAction.php index 852ca2c1e..da3c5091e 100644 --- a/src/ZM/Annotation/OneBot/BotAction.php +++ b/src/ZM/Annotation/OneBot/BotAction.php @@ -17,9 +17,7 @@ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class BotAction extends AnnotationBase implements Level { - public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20) - { - } + public function __construct(public string $action = '', public bool $need_response = false, public int $level = 20) {} public static function make(callable $callback, string $action, bool $need_response = false, int $level = 20): BotAction { diff --git a/src/ZM/Annotation/OneBot/BotActionResponse.php b/src/ZM/Annotation/OneBot/BotActionResponse.php index 1cec6766c..58b769de1 100644 --- a/src/ZM/Annotation/OneBot/BotActionResponse.php +++ b/src/ZM/Annotation/OneBot/BotActionResponse.php @@ -20,9 +20,7 @@ #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] class BotActionResponse extends AnnotationBase implements Level { - public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20) - { - } + public function __construct(public ?string $status = null, public ?int $retcode = null, public int $level = 20) {} public function getLevel() { diff --git a/src/ZM/Annotation/OneBot/BotCommand.php b/src/ZM/Annotation/OneBot/BotCommand.php index ae2754724..ef6c9ac0f 100644 --- a/src/ZM/Annotation/OneBot/BotCommand.php +++ b/src/ZM/Annotation/OneBot/BotCommand.php @@ -39,8 +39,7 @@ public function __construct( public string $detail_type = '', public string $prefix = '', public int $level = 20 - ) { - } + ) {} public static function make( string $name = '', diff --git a/src/ZM/Annotation/OneBot/BotEvent.php b/src/ZM/Annotation/OneBot/BotEvent.php index e1dd8e996..6f4561cc5 100644 --- a/src/ZM/Annotation/OneBot/BotEvent.php +++ b/src/ZM/Annotation/OneBot/BotEvent.php @@ -4,7 +4,6 @@ namespace ZM\Annotation\OneBot; -use Attribute; use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; use Doctrine\Common\Annotations\Annotation\Target; use ZM\Annotation\AnnotationBase; @@ -20,9 +19,7 @@ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class BotEvent extends AnnotationBase implements Level { - public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20) - { - } + public function __construct(public ?string $type = null, public ?string $detail_type = null, public ?string $sub_type = null, public int $level = 20) {} public static function make( ?string $type = null, diff --git a/src/ZM/Annotation/OneBot/CommandArgument.php b/src/ZM/Annotation/OneBot/CommandArgument.php index 43684644c..7b50efbe6 100644 --- a/src/ZM/Annotation/OneBot/CommandArgument.php +++ b/src/ZM/Annotation/OneBot/CommandArgument.php @@ -41,7 +41,7 @@ public function __construct( string $type = 'string', public bool $required = false, public string $prompt = '', - public string|\Closure|array|int|float|null $default = '', + public null|array|\Closure|float|int|string $default = '', public int $timeout = 60, public int $error_prompt_policy = 1 ) { diff --git a/src/ZM/Annotation/OneBot/CommandHelp.php b/src/ZM/Annotation/OneBot/CommandHelp.php index d2cdc8ac8..83b8e619a 100644 --- a/src/ZM/Annotation/OneBot/CommandHelp.php +++ b/src/ZM/Annotation/OneBot/CommandHelp.php @@ -22,8 +22,7 @@ public function __construct( public string $description, public string $usage, public string $example, - ) { - } + ) {} public static function make( string $description, diff --git a/src/ZM/Command/BuildCommand.php b/src/ZM/Command/BuildCommand.php index 17d540e75..551f70987 100644 --- a/src/ZM/Command/BuildCommand.php +++ b/src/ZM/Command/BuildCommand.php @@ -83,7 +83,7 @@ private function build(string $target, string $entry): void $separator = '\\' . DIRECTORY_SEPARATOR; // 只打包 bin / config / resources / src / vendor 目录以及 composer.json / composer.lock / entry.php $files = array_filter($files, function ($file) use ($separator) { - return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\\.json|README\\.md)$/', $file); + return preg_match('/^(bin|config|resources|src|vendor)' . $separator . '|^(composer\.json|README\.md)$/', $file); }); sort($files); diff --git a/src/ZM/Command/Command.php b/src/ZM/Command/Command.php index 1152a0afd..dbd984b81 100644 --- a/src/ZM/Command/Command.php +++ b/src/ZM/Command/Command.php @@ -26,7 +26,6 @@ abstract class Command extends \Symfony\Component\Console\Command\Command implem protected OutputInterface $output; /** - * {@inheritdoc} * @internal 不建议覆写此方法,建议使用 {@see handle()} 方法 */ protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/ZM/Command/Generate/TextGenerateCommand.php b/src/ZM/Command/Generate/TextGenerateCommand.php index 4434f1d1c..70b1aec8b 100644 --- a/src/ZM/Command/Generate/TextGenerateCommand.php +++ b/src/ZM/Command/Generate/TextGenerateCommand.php @@ -18,9 +18,6 @@ protected function configure() $this->setDescription('生成一些框架本身的文本(内部' . PHP_EOL . '当前包含:class-alias-md,update-log-md'); } - /** - * {@inheritDoc} - */ protected function handle(): int { return match ($this->input->getArgument('name')) { diff --git a/src/ZM/Command/Plugin/PluginCommand.php b/src/ZM/Command/Plugin/PluginCommand.php index 27b54fdc3..95d72de0c 100644 --- a/src/ZM/Command/Plugin/PluginCommand.php +++ b/src/ZM/Command/Plugin/PluginCommand.php @@ -18,7 +18,7 @@ abstract class PluginCommand extends Command private static bool $loaded = false; - public function __construct(string $name = null) + public function __construct(?string $name = null) { parent::__construct($name); if (!self::$loaded) { @@ -30,7 +30,7 @@ public function __construct(string $name = null) /** * 插件名称合规验证器 */ - public function validatePluginName(string $answer): string + public function validatePluginName(?string $answer): string { if (empty($answer)) { throw new \RuntimeException('插件名称不能为空'); @@ -38,8 +38,8 @@ public function validatePluginName(string $answer): string if (is_numeric(mb_substr($answer, 0, 1))) { throw new \RuntimeException('插件名称不能以数字开头,且只能包含字母、数字、下划线、短横线'); } - if (!preg_match('/^[\/a-zA-Z0-9_-]+$/', $answer)) { - throw new \RuntimeException('插件名称只能包含字母、数字、下划线、短横线'); + if (!preg_match('/^[\/a-z0-9_-]+$/', $answer)) { + throw new \RuntimeException('插件名称只能包含小写字母、数字、下划线、短横线'); } $exp = explode('/', $answer); if (count($exp) !== 2) { @@ -72,7 +72,7 @@ public function validateNamespace(string $answer): string throw new \RuntimeException('插件命名空间不能以数字开头,且只能包含字母、数字、反斜线'); } // 只能包含字母、数字和反斜线 - if (!preg_match('/^[a-zA-Z0-9\\\\]+$/', $answer)) { + if (!preg_match('/^[a-zA-Z0-9\\\]+$/', $answer)) { throw new \RuntimeException('插件命名空间只能包含字母、数字、反斜线'); } return $answer; @@ -101,7 +101,7 @@ protected function questionWithArgument(string $name, string $question, callable * @param string $question 问题 * @param callable $validator 验证器 */ - protected function questionWithOption(string $name, string $question, callable $validator, string $default = null): void + protected function questionWithOption(string $name, string $question, callable $validator, ?string $default = null): void { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); diff --git a/src/ZM/Command/Plugin/PluginInstallCommand.php b/src/ZM/Command/Plugin/PluginInstallCommand.php index 802e38a2f..1212e606e 100644 --- a/src/ZM/Command/Plugin/PluginInstallCommand.php +++ b/src/ZM/Command/Plugin/PluginInstallCommand.php @@ -20,9 +20,6 @@ protected function configure() $this->addOption('github-token', null, InputOption::VALUE_REQUIRED, '提供的 GitHub Token'); } - /** - * {@inheritDoc} - */ protected function handle(): int { $addr = $this->input->getArgument('address'); diff --git a/src/ZM/Command/Plugin/PluginMakeCommand.php b/src/ZM/Command/Plugin/PluginMakeCommand.php index f02228cf8..2160e788e 100644 --- a/src/ZM/Command/Plugin/PluginMakeCommand.php +++ b/src/ZM/Command/Plugin/PluginMakeCommand.php @@ -27,7 +27,6 @@ protected function configure() } /** - * {@inheritDoc} * @throws FileSystemException */ protected function handle(): int diff --git a/src/ZM/Command/Plugin/PluginPackCommand.php b/src/ZM/Command/Plugin/PluginPackCommand.php index c95496d71..a163da848 100644 --- a/src/ZM/Command/Plugin/PluginPackCommand.php +++ b/src/ZM/Command/Plugin/PluginPackCommand.php @@ -19,9 +19,6 @@ protected function configure() $this->addOption('build-dir', 'D', InputOption::VALUE_REQUIRED, '指定输出文件位置', WORKING_DIR . '/build'); } - /** - * {@inheritDoc} - */ protected function handle(): int { try { diff --git a/src/ZM/Command/Plugin/PluginRemoveCommand.php b/src/ZM/Command/Plugin/PluginRemoveCommand.php index d76ece147..063ca8218 100644 --- a/src/ZM/Command/Plugin/PluginRemoveCommand.php +++ b/src/ZM/Command/Plugin/PluginRemoveCommand.php @@ -17,9 +17,6 @@ protected function configure() $this->addArgument('name', InputArgument::REQUIRED, '插件名称'); } - /** - * {@inheritDoc} - */ protected function handle(): int { $plugin_name = $this->input->getArgument('name'); diff --git a/src/ZM/Config/Environment.php b/src/ZM/Config/Environment.php index d78de1446..44be72858 100644 --- a/src/ZM/Config/Environment.php +++ b/src/ZM/Config/Environment.php @@ -29,9 +29,6 @@ public function __construct( $this->values = $values + $_ENV + $_SERVER; } - /** - * {@inheritdoc} - */ public function set(string $name, mixed $value): self { if (array_key_exists($name, $this->values) && !$this->overwrite) { @@ -45,9 +42,6 @@ public function set(string $name, mixed $value): self return $this; } - /** - * {@inheritdoc} - */ public function get(string $name, mixed $default = null): mixed { if (isset($this->values[$name])) { @@ -57,9 +51,6 @@ public function get(string $name, mixed $default = null): mixed return $default; } - /** - * {@inheritdoc} - */ public function getAll(): array { $result = []; diff --git a/src/ZM/Config/RuntimePreferences.php b/src/ZM/Config/RuntimePreferences.php index a1ea44553..134609e02 100644 --- a/src/ZM/Config/RuntimePreferences.php +++ b/src/ZM/Config/RuntimePreferences.php @@ -14,7 +14,7 @@ class RuntimePreferences protected string $config_dir = SOURCE_ROOT_DIR . '/config'; - public function environment(...$environments): string|bool + public function environment(...$environments): bool|string { if (empty($environments)) { return $this->environment; diff --git a/src/ZM/Config/ZMConfig.php b/src/ZM/Config/ZMConfig.php index f213a7c4e..6e3d37107 100644 --- a/src/ZM/Config/ZMConfig.php +++ b/src/ZM/Config/ZMConfig.php @@ -64,7 +64,7 @@ class ZMConfig * * @throws ConfigException 配置文件加载出错 */ - public function __construct(array $init_config = null) + public function __construct(?array $init_config = null) { // 合并初始化配置,构造传入优先 $conf = array_merge_recursive($this->loadInitConfig(), $init_config ?? []); @@ -332,7 +332,7 @@ private function loadConfigFromPath(string $path): void // 读取并解析配置 $content = file_get_contents($path); // TODO: 使用 Loader 替代 -// $config = $this->loader->load($path); + // $config = $this->loader->load($path); $config = []; switch ($ext) { case 'php': diff --git a/src/ZM/ConsoleApplication.php b/src/ZM/ConsoleApplication.php index 30c42cd0e..9c0a6308e 100644 --- a/src/ZM/ConsoleApplication.php +++ b/src/ZM/ConsoleApplication.php @@ -46,9 +46,6 @@ public function __construct(string $name = 'zhamao-framework') self::$obj = $this; } - /** - * {@inheritdoc} - */ public function doRun(InputInterface $input, OutputInterface $output): int { try { @@ -73,9 +70,6 @@ public function registerGlobalOptions(): void ]); } - /** - * {@inheritdoc} - */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int { // 初始化内核 @@ -99,7 +93,7 @@ private function registerCommandLoader(): void // 先加载框架内置命令 $command_classes = array_merge( $command_classes, - FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\\Command') + FileSystem::getClassesPsr4(FRAMEWORK_ROOT_DIR . '/src/ZM/Command', 'ZM\Command') ); // 再加载用户自定义命令(如存在) if (is_dir(SOURCE_ROOT_DIR . '/src/Command')) { diff --git a/src/ZM/Container/ContainerBindingListener.php b/src/ZM/Container/ContainerBindingListener.php index c2379dced..5fadb772e 100644 --- a/src/ZM/Container/ContainerBindingListener.php +++ b/src/ZM/Container/ContainerBindingListener.php @@ -28,9 +28,7 @@ public static function listenForEvents(): void } } - public static function callback(): void - { - } + public static function callback(): void {} public static function cleanCallback(): void { diff --git a/src/ZM/Context/BotConnectContext.php b/src/ZM/Context/BotConnectContext.php index 5f00d0b63..3e9db73f1 100644 --- a/src/ZM/Context/BotConnectContext.php +++ b/src/ZM/Context/BotConnectContext.php @@ -15,9 +15,7 @@ class BotConnectContext protected ?array $self = null; - public function __construct(private int $flag, private int $fd) - { - } + public function __construct(private int $flag, private int $fd) {} public function getFd(): int { diff --git a/src/ZM/Context/BotContext.php b/src/ZM/Context/BotContext.php index 728b857d6..897d857be 100644 --- a/src/ZM/Context/BotContext.php +++ b/src/ZM/Context/BotContext.php @@ -54,7 +54,7 @@ public function getEvent(): OneBotEvent * @noinspection PhpDocMissingThrowsInspection * @noinspection PhpUnhandledExceptionInspection */ - public function reply(\Stringable|MessageSegment|array|string $message, int $reply_mode = ZM_REPLY_NONE): ActionResponse|bool + public function reply(array|MessageSegment|string|\Stringable $message, int $reply_mode = ZM_REPLY_NONE): ActionResponse|bool { if (container()->has('bot.event')) { // 这里直接使用当前上下文的事件里面的参数,不再重新挨个获取怎么发消息的参数 @@ -87,7 +87,7 @@ public function reply(\Stringable|MessageSegment|array|string $message, int $rep * @noinspection PhpDocMissingThrowsInspection * @noinspection PhpUnhandledExceptionInspection */ - public function prompt(string|\Stringable|MessageSegment|array $prompt = '', int $timeout = 600, string|\Stringable|MessageSegment|array $timeout_prompt = '', int $option = ZM_PROMPT_NONE): null|OneBotEvent|array|string + public function prompt(array|MessageSegment|string|\Stringable $prompt = '', int $timeout = 600, array|MessageSegment|string|\Stringable $timeout_prompt = '', int $option = ZM_PROMPT_NONE): null|array|OneBotEvent|string { if (!container()->has('bot.event')) { throw new OneBot12Exception('bot()->prompt() can only be used in message event'); @@ -135,7 +135,7 @@ public function prompt(string|\Stringable|MessageSegment|array $prompt = '', int * 如果是多级群组,则等待最小级下当前消息人的消息 * @noinspection PhpUnhandledExceptionInspection */ - public function promptString(string|\Stringable|MessageSegment|array $prompt = '', int $timeout = 600, string|\Stringable|MessageSegment|array $timeout_prompt = '', int $option = ZM_PROMPT_NONE): string + public function promptString(array|MessageSegment|string|\Stringable $prompt = '', int $timeout = 600, array|MessageSegment|string|\Stringable $timeout_prompt = '', int $option = ZM_PROMPT_NONE): string { return $this->prompt($prompt, $timeout, $timeout_prompt, $option | ZM_PROMPT_RETURN_STRING); } @@ -194,12 +194,12 @@ public function setParams(array $params): void * * @param int|string $name 参数名称或索引 */ - public function getParam(string|int $name): mixed + public function getParam(int|string $name): mixed { return $this->params[$name] ?? null; } - public function getParamString(string|int $name): ?string + public function getParamString(int|string $name): ?string { return MessageUtil::getAltMessage($this->params[$name] ?? null); } @@ -242,7 +242,7 @@ private function matchReplyMode(int $reply_mode, array &$message_segments, OneBo * @param OneBotEvent $event 事件对象 * @return array 消息段 */ - private function applyPromptMode(int $option, array|string|\Stringable|MessageSegment $prompt, OneBotEvent $event): array + private function applyPromptMode(int $option, array|MessageSegment|string|\Stringable $prompt, OneBotEvent $event): array { // 先格式化消息 if ($prompt instanceof MessageSegment) { @@ -268,7 +268,7 @@ private function applyPromptMode(int $option, array|string|\Stringable|MessageSe * @return null|array|OneBotEvent|string 根据不同匹配类型返回不同的东西 * @throws OneBot12Exception */ - private function applyPromptReturn(mixed $result, int $option): null|OneBotEvent|array|string + private function applyPromptReturn(mixed $result, int $option): null|array|OneBotEvent|string { // 必须是 OneBotEvent 且是消息类型 if (!$result instanceof OneBotEvent || $result->type !== 'message') { diff --git a/src/ZM/Context/ContextInterface.php b/src/ZM/Context/ContextInterface.php index 1003c56ad..d02ec8854 100644 --- a/src/ZM/Context/ContextInterface.php +++ b/src/ZM/Context/ContextInterface.php @@ -4,6 +4,4 @@ namespace ZM\Context; -interface ContextInterface -{ -} +interface ContextInterface {} diff --git a/src/ZM/Context/Trait/BotActionTrait.php b/src/ZM/Context/Trait/BotActionTrait.php index f5785622f..cbae750e7 100644 --- a/src/ZM/Context/Trait/BotActionTrait.php +++ b/src/ZM/Context/Trait/BotActionTrait.php @@ -35,7 +35,7 @@ public static function tryResume(ActionResponse $response): void * @param array|MessageSegment|string|\Stringable $message 消息内容,可以是消息段、字符串 * @throws \Throwable */ - public function sendMessage(\Stringable|array|MessageSegment|string $message, string $detail_type, array $params = []): ActionResponse|bool + public function sendMessage(array|MessageSegment|string|\Stringable $message, string $detail_type, array $params = []): ActionResponse|bool { $message = MessageUtil::convertToArr($message); $params['message'] = $message; @@ -48,7 +48,7 @@ public function sendMessage(\Stringable|array|MessageSegment|string $message, st * * @throws \Throwable */ - public function sendAction(string $action, array $params = [], ?array $self = null): bool|ActionResponse + public function sendAction(string $action, array $params = [], ?array $self = null): ActionResponse|bool { if ($self === null && $this->self !== null) { $self = $this->self; diff --git a/src/ZM/Event/Listener/WorkerEventListener.php b/src/ZM/Event/Listener/WorkerEventListener.php index 4debb73e8..1af391c62 100644 --- a/src/ZM/Event/Listener/WorkerEventListener.php +++ b/src/ZM/Event/Listener/WorkerEventListener.php @@ -110,8 +110,7 @@ public function onWorkerStart999(): void } // Windows 系统的 CtrlC 由于和 Select 有一定的冲突,如果没事件解析的话 CtrlC 会阻塞,所以必须添加一个空的计时器 if (PHP_OS_FAMILY === 'Windows') { - Framework::getInstance()->getDriver()->getEventLoop()->addTimer(1000, function () { - }, 0); + Framework::getInstance()->getDriver()->getEventLoop()->addTimer(1000, function () {}, 0); } // 回显 debug 日志:进程占用的内存 $memory_total = memory_get_usage() / 1024 / 1024; diff --git a/src/ZM/Exception/DriverException.php b/src/ZM/Exception/DriverException.php index 1cf0f03d0..8934f43d9 100644 --- a/src/ZM/Exception/DriverException.php +++ b/src/ZM/Exception/DriverException.php @@ -4,6 +4,4 @@ namespace ZM\Exception; -class DriverException extends ZMException -{ -} +class DriverException extends ZMException {} diff --git a/src/ZM/Exception/FileSystemException.php b/src/ZM/Exception/FileSystemException.php index 6c920b2e5..b07454e84 100644 --- a/src/ZM/Exception/FileSystemException.php +++ b/src/ZM/Exception/FileSystemException.php @@ -4,6 +4,4 @@ namespace ZM\Exception; -class FileSystemException extends ZMException -{ -} +class FileSystemException extends ZMException {} diff --git a/src/ZM/Exception/InitException.php b/src/ZM/Exception/InitException.php index 69849cba3..230644830 100644 --- a/src/ZM/Exception/InitException.php +++ b/src/ZM/Exception/InitException.php @@ -7,6 +7,4 @@ /** * 初始化命令(./zhamao init)出现的错误 */ -class InitException extends ZMException -{ -} +class InitException extends ZMException {} diff --git a/src/ZM/Exception/InterruptException.php b/src/ZM/Exception/InterruptException.php index f2afa810a..8d11f384a 100644 --- a/src/ZM/Exception/InterruptException.php +++ b/src/ZM/Exception/InterruptException.php @@ -6,7 +6,7 @@ class InterruptException extends ZMException { - public function __construct(public $return_var = null, $message = '', $code = 0, \Throwable $previous = null) + public function __construct(public $return_var = null, $message = '', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } diff --git a/src/ZM/Exception/InvalidArgumentException.php b/src/ZM/Exception/InvalidArgumentException.php index cb2f81901..d66e9d7af 100644 --- a/src/ZM/Exception/InvalidArgumentException.php +++ b/src/ZM/Exception/InvalidArgumentException.php @@ -4,6 +4,4 @@ namespace ZM\Exception; -class InvalidArgumentException extends ZMException -{ -} +class InvalidArgumentException extends ZMException {} diff --git a/src/ZM/Exception/OneBot12Exception.php b/src/ZM/Exception/OneBot12Exception.php index 85a9d7642..d7b130e03 100644 --- a/src/ZM/Exception/OneBot12Exception.php +++ b/src/ZM/Exception/OneBot12Exception.php @@ -4,6 +4,4 @@ namespace ZM\Exception; -class OneBot12Exception extends PluginException -{ -} +class OneBot12Exception extends PluginException {} diff --git a/src/ZM/Exception/PluginException.php b/src/ZM/Exception/PluginException.php index e18f7ce71..7b6ee4132 100644 --- a/src/ZM/Exception/PluginException.php +++ b/src/ZM/Exception/PluginException.php @@ -7,6 +7,4 @@ /** * 插件加载器出现的错误 */ -class PluginException extends ZMException -{ -} +class PluginException extends ZMException {} diff --git a/src/ZM/Exception/Solution/Solution.php b/src/ZM/Exception/Solution/Solution.php index be0bba295..872b40d79 100644 --- a/src/ZM/Exception/Solution/Solution.php +++ b/src/ZM/Exception/Solution/Solution.php @@ -10,8 +10,7 @@ public function __construct( private string $title, private string $description, private array $links, - ) { - } + ) {} public function getSolutionTitle(): string { diff --git a/src/ZM/Exception/WaitTimeoutException.php b/src/ZM/Exception/WaitTimeoutException.php index 3514a8d45..c4d9ca8cb 100644 --- a/src/ZM/Exception/WaitTimeoutException.php +++ b/src/ZM/Exception/WaitTimeoutException.php @@ -14,11 +14,11 @@ class WaitTimeoutException extends ZMException public function __construct( public mixed $module, - string|\MessageSegment|array|\Stringable $timeout_prompt = '', + array|\MessageSegment|string|\Stringable $timeout_prompt = '', private ?ActionResponse $prompt_response = null, private ?OneBotEvent $user_event = null, private int $prompt_option = ZM_PROMPT_NONE, - \Throwable $previous = null + ?\Throwable $previous = null ) { parent::__construct('wait timeout!', 0, $previous); if ($timeout_prompt === '') { diff --git a/src/ZM/Exception/ZMException.php b/src/ZM/Exception/ZMException.php index e5fef9a81..70ccc8707 100644 --- a/src/ZM/Exception/ZMException.php +++ b/src/ZM/Exception/ZMException.php @@ -4,6 +4,4 @@ namespace ZM\Exception; -abstract class ZMException extends \Exception -{ -} +abstract class ZMException extends \Exception {} diff --git a/src/ZM/Exception/ZMKnownException.php b/src/ZM/Exception/ZMKnownException.php index ade172855..d9a8b3ac0 100644 --- a/src/ZM/Exception/ZMKnownException.php +++ b/src/ZM/Exception/ZMKnownException.php @@ -9,7 +9,7 @@ #[Deprecated(reason: '建议使用具体的异常类')] class ZMKnownException extends ZMException { - public function __construct($err_code, $message = '', $code = 0, \Throwable $previous = null) + public function __construct($err_code, $message = '', $code = 0, ?\Throwable $previous = null) { parent::__construct(zm_internal_errcode($err_code) . $message, $code, $previous); if ($err_code === 'E99999') { diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index b49d7b496..a6a3e49da 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -61,7 +61,7 @@ class Framework protected array $argv; /** @var null|Driver|SwooleDriver|WorkermanDriver OneBot驱动 */ - protected SwooleDriver|Driver|WorkermanDriver|null $driver = null; + protected null|Driver|SwooleDriver|WorkermanDriver $driver = null; /** @var array> 启动注解列表 */ protected array $setup_annotations = []; @@ -399,6 +399,7 @@ private function translateProperties(array &$properties): void if (isset($translations[$k])) { $keys = array_keys($properties); $keys[array_search($k, $keys, false)] = $translations[$k]; + /* @phpstan-ignore-next-line */ $properties = ($t = array_combine($keys, $properties)) ? $t : $properties; } } diff --git a/src/ZM/Middleware/MiddlewareInterface.php b/src/ZM/Middleware/MiddlewareInterface.php index c37017933..a21ab1cc8 100644 --- a/src/ZM/Middleware/MiddlewareInterface.php +++ b/src/ZM/Middleware/MiddlewareInterface.php @@ -4,6 +4,4 @@ namespace ZM\Middleware; -interface MiddlewareInterface -{ -} +interface MiddlewareInterface {} diff --git a/src/ZM/Middleware/WebSocketFilter.php b/src/ZM/Middleware/WebSocketFilter.php index 86912642f..6a06e063f 100644 --- a/src/ZM/Middleware/WebSocketFilter.php +++ b/src/ZM/Middleware/WebSocketFilter.php @@ -41,7 +41,7 @@ private function filterOpen(WebSocketOpenEvent $event): bool return true; } - private function filterMessageAndClose(WebSocketMessageEvent|WebSocketCloseEvent $event): bool + private function filterMessageAndClose(WebSocketCloseEvent|WebSocketMessageEvent $event): bool { // 过滤存在 flag 设置的情况 if (($this->args['flag'] ?? null) !== null && $this->args['flag'] !== $event->getSocketFlag()) { diff --git a/src/ZM/Plugin/CommandManual/StaticManualFactory.php b/src/ZM/Plugin/CommandManual/StaticManualFactory.php index 7db0f5fde..f0ce41453 100644 --- a/src/ZM/Plugin/CommandManual/StaticManualFactory.php +++ b/src/ZM/Plugin/CommandManual/StaticManualFactory.php @@ -10,9 +10,7 @@ class StaticManualFactory { - public function __construct() - { - } + public function __construct() {} public function __invoke(BotCommand $command, array $template, array $adjacent_annotations): string { diff --git a/src/ZM/Plugin/OneBot/BotMap.php b/src/ZM/Plugin/OneBot/BotMap.php index ee260d6c8..c1f52e3c6 100644 --- a/src/ZM/Plugin/OneBot/BotMap.php +++ b/src/ZM/Plugin/OneBot/BotMap.php @@ -69,7 +69,7 @@ public static function getConnectContext(int $flag, int $fd): BotConnectContext * @param int $fd 绑定的反向 ws 连接的客户端对应 fd * @param int $flag fd 所在 server 监听端口 */ - public static function registerBotWithFd(string|int $bot_id, string $platform, bool $status, int $fd, int $flag): bool + public static function registerBotWithFd(int|string $bot_id, string $platform, bool $status, int $fd, int $flag): bool { logger()->debug('正在注册机器人:' . "{$platform}:{$bot_id}, fd:{$fd}, flag:{$flag}"); self::$bot_fds[$platform][strval($bot_id)] = [$flag, $fd]; @@ -87,12 +87,12 @@ public static function getBotFds(): array return self::$bot_fds; } - public static function getBotFd(string|int $bot_id, string $platform): ?array + public static function getBotFd(int|string $bot_id, string $platform): ?array { return self::$bot_fds[$platform][$bot_id] ?? null; } - public static function unregisterBot(string|int $bot_id, string $platform): void + public static function unregisterBot(int|string $bot_id, string $platform): void { logger()->debug('取消注册 bot: ' . $bot_id); unset(self::$bot_fds[$platform][$bot_id], self::$bot_status[$platform][$bot_id], self::$bot_ctx_cache[$platform][$bot_id]); @@ -117,7 +117,7 @@ public static function unregisterBotByFd(int $flag, int $fd): void } } - public static function getBotContext(string|int $bot_id = '', string $platform = ''): BotContext + public static function getBotContext(int|string $bot_id = '', string $platform = ''): BotContext { if (isset(self::$bot_ctx_cache[$platform][$bot_id])) { return self::$bot_ctx_cache[$platform][$bot_id]; @@ -152,7 +152,7 @@ public static function getBotContext(string|int $bot_id = '', string $platform = return self::$bot_ctx_cache[$platform][$bot_id] = new (self::$custom_contexts[$platform][$bot_id] ?? BotContext::class)($bot_id, $platform); } - public static function setCustomContext(string|int $bot_id, string $platform, string $context_class = BotContext::class): void + public static function setCustomContext(int|string $bot_id, string $platform, string $context_class = BotContext::class): void { self::$custom_contexts[$platform][$bot_id] = $context_class; } diff --git a/src/ZM/Process/ProcessStateManager.php b/src/ZM/Process/ProcessStateManager.php index 91b5e09ef..d9c3a036b 100644 --- a/src/ZM/Process/ProcessStateManager.php +++ b/src/ZM/Process/ProcessStateManager.php @@ -31,7 +31,7 @@ public static function isTaskWorker(): bool * @throws ZMKnownException * @internal */ - public static function removeProcessState(int $type, int|string $id_or_name = null): void + public static function removeProcessState(int $type, null|int|string $id_or_name = null): void { switch ($type) { case ZM_PROCESS_MASTER: diff --git a/src/ZM/Store/Database/DBStatement.php b/src/ZM/Store/Database/DBStatement.php index cb28c8734..72b01066c 100644 --- a/src/ZM/Store/Database/DBStatement.php +++ b/src/ZM/Store/Database/DBStatement.php @@ -13,9 +13,7 @@ class DBStatement implements \IteratorAggregate, Statement { - public function __construct(private \PDOStatement $statement) - { - } + public function __construct(private \PDOStatement $statement) {} public function closeCursor() { diff --git a/src/ZM/Store/Database/DBStatementWrapper.php b/src/ZM/Store/Database/DBStatementWrapper.php index 0fcecc617..363a3299f 100644 --- a/src/ZM/Store/Database/DBStatementWrapper.php +++ b/src/ZM/Store/Database/DBStatementWrapper.php @@ -14,9 +14,7 @@ class DBStatementWrapper { - public function __construct(public ?Result $stmt) - { - } + public function __construct(public ?Result $stmt) {} /** * 获取结果的迭代器 @@ -41,7 +39,7 @@ public function columnCount() /** * wrapper method * @return array|false|mixed - *@throws DBException + * @throws DBException */ public function fetchNumeric() { @@ -55,7 +53,7 @@ public function fetchNumeric() /** * wrapper method * @return array|false|mixed - *@throws DBException + * @throws DBException */ public function fetchAssociative() { @@ -69,7 +67,7 @@ public function fetchAssociative() /** * wrapper method * @return false|mixed - *@throws DBException + * @throws DBException */ public function fetchOne() { diff --git a/src/ZM/Store/KV/LightCache.php b/src/ZM/Store/KV/LightCache.php index 301bb1aba..743bdc0e6 100644 --- a/src/ZM/Store/KV/LightCache.php +++ b/src/ZM/Store/KV/LightCache.php @@ -104,7 +104,7 @@ public function get(string $key, mixed $default = null): mixed /** * @throws InvalidArgumentException */ - public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool + public function set(string $key, mixed $value, null|\DateInterval|int $ttl = null): bool { $this->validateKey($key); self::$caches[$this->name][$key] = $value; @@ -139,7 +139,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable } } - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool + public function setMultiple(iterable $values, null|\DateInterval|int $ttl = null): bool { foreach ($values as $k => $v) { if (!$this->set($k, $v, $ttl)) { diff --git a/src/ZM/Store/KV/Redis/KVRedis.php b/src/ZM/Store/KV/Redis/KVRedis.php index 6c1119cf9..56d39458e 100644 --- a/src/ZM/Store/KV/Redis/KVRedis.php +++ b/src/ZM/Store/KV/Redis/KVRedis.php @@ -21,9 +21,6 @@ public static function open(string $name = ''): CacheInterface return new KVRedis($name); } - /** - * {@inheritDoc} - */ public function get(string $key, mixed $default = null): mixed { /** @var ZMRedis $redis */ @@ -38,10 +35,7 @@ public function get(string $key, mixed $default = null): mixed return $ret; } - /** - * {@inheritDoc} - */ - public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool + public function set(string $key, mixed $value, null|\DateInterval|int $ttl = null): bool { /** @var ZMRedis $redis */ $redis = RedisPool::pool($this->pool_name)->get(); @@ -50,9 +44,6 @@ public function set(string $key, mixed $value, \DateInterval|int|null $ttl = nul return (bool) $ret; } - /** - * {@inheritDoc} - */ public function delete(string $key): bool { /** @var ZMRedis $redis */ @@ -62,9 +53,6 @@ public function delete(string $key): bool return (bool) $ret; } - /** - * {@inheritDoc} - */ public function clear(): bool { /** @var ZMRedis $redis */ @@ -74,9 +62,6 @@ public function clear(): bool return (bool) $ret; } - /** - * {@inheritDoc} - */ public function getMultiple(iterable $keys, mixed $default = null): iterable { /** @var ZMRedis $redis */ @@ -93,10 +78,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable RedisPool::pool($this->pool_name)->put($redis); } - /** - * {@inheritDoc} - */ - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool + public function setMultiple(iterable $values, null|\DateInterval|int $ttl = null): bool { /** @var ZMRedis $redis */ $redis = RedisPool::pool($this->pool_name)->get(); @@ -108,9 +90,6 @@ public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null return $ret; } - /** - * {@inheritDoc} - */ public function deleteMultiple(iterable $keys): bool { /** @var ZMRedis $redis */ @@ -123,9 +102,6 @@ public function deleteMultiple(iterable $keys): bool return $ret; } - /** - * {@inheritDoc} - */ public function has(string $key): bool { /** @var ZMRedis $redis */ diff --git a/src/ZM/Store/KV/Redis/RedisException.php b/src/ZM/Store/KV/Redis/RedisException.php index e2e32b253..a509b63f2 100644 --- a/src/ZM/Store/KV/Redis/RedisException.php +++ b/src/ZM/Store/KV/Redis/RedisException.php @@ -6,6 +6,4 @@ use ZM\Exception\ZMException; -class RedisException extends ZMException -{ -} +class RedisException extends ZMException {} diff --git a/src/ZM/Store/KV/Redis/RedisWrapper.php b/src/ZM/Store/KV/Redis/RedisWrapper.php index 9a55ce939..ccb662d69 100644 --- a/src/ZM/Store/KV/Redis/RedisWrapper.php +++ b/src/ZM/Store/KV/Redis/RedisWrapper.php @@ -241,9 +241,7 @@ */ class RedisWrapper { - public function __construct(private string $pool = 'default') - { - } + public function __construct(private string $pool = 'default') {} public function __call(string $name, array $arguments) { diff --git a/src/ZM/Utils/CatCode.php b/src/ZM/Utils/CatCode.php index c197a6d6a..5f1c88293 100644 --- a/src/ZM/Utils/CatCode.php +++ b/src/ZM/Utils/CatCode.php @@ -14,7 +14,7 @@ class CatCode * @param array|MessageSegment|string $message_segment MessageSegment 对象或数组 * @param bool $encode_text 是否对文本进行 CatCode 编码(默认为否) */ - public static function fromSegment(string|array|MessageSegment $message_segment, bool $encode_text = false): string + public static function fromSegment(array|MessageSegment|string $message_segment, bool $encode_text = false): string { // 传入的必须是段数组或段对象 if (is_array($message_segment)) { @@ -40,7 +40,7 @@ public static function fromSegment(string|array|MessageSegment $message_segment, * @param bool $is_param 如果是转义CatCode本体内容,则为false(默认),如果是参数内的字符串,则为true * @return string 转义后的CatCode */ - public static function encode(\Stringable|int|string $msg, bool $is_param = false): string + public static function encode(int|string|\Stringable $msg, bool $is_param = false): string { $msg = str_replace(['&', '[', ']'], ['&', '[', ']'], (string) $msg); if ($is_param) { @@ -56,7 +56,7 @@ public static function encode(\Stringable|int|string $msg, bool $is_param = fals * @param bool $is_param 如果是解码CatCode本体内容,则为false(默认),如果是参数内的字符串,则为true * @return string 转义后的CatCode */ - public static function decode(\Stringable|int|string $msg, bool $is_param = false): string + public static function decode(int|string|\Stringable $msg, bool $is_param = false): string { $msg = str_replace(['&', '[', ']'], ['&', '[', ']'], (string) $msg); if ($is_param) { diff --git a/src/ZM/Utils/CodeGenerator/PluginGenerator.php b/src/ZM/Utils/CodeGenerator/PluginGenerator.php index e60570500..a47d5af0b 100644 --- a/src/ZM/Utils/CodeGenerator/PluginGenerator.php +++ b/src/ZM/Utils/CodeGenerator/PluginGenerator.php @@ -14,9 +14,7 @@ */ class PluginGenerator { - public function __construct(private string $name, private string $plugin_dir) - { - } + public function __construct(private string $name, private string $plugin_dir) {} /** * 开始生成 diff --git a/src/ZM/Utils/MessageUtil.php b/src/ZM/Utils/MessageUtil.php index 3fffb2741..dcfb00b9f 100644 --- a/src/ZM/Utils/MessageUtil.php +++ b/src/ZM/Utils/MessageUtil.php @@ -61,7 +61,7 @@ public static function strToArray(string $msg, bool $assoc_result = false, bool return $arr; } - public static function convertToArr(MessageSegment|\Stringable|array|string $message): array + public static function convertToArr(array|MessageSegment|string|\Stringable $message): array { if (is_array($message)) { foreach ($message as $k => $v) { @@ -99,7 +99,7 @@ public static function splitMessage(string $msg, array $includes = [' ', "\t"]): return $ls; } - public static function getAltMessage(null|array|string|MessageSegment $message): string + public static function getAltMessage(null|array|MessageSegment|string $message): string { if ($message === null) { return ''; diff --git a/src/ZM/Utils/OneBot12FileDownloader.php b/src/ZM/Utils/OneBot12FileDownloader.php index 2405e97d9..8f0237888 100644 --- a/src/ZM/Utils/OneBot12FileDownloader.php +++ b/src/ZM/Utils/OneBot12FileDownloader.php @@ -59,10 +59,10 @@ public function downloadFile(string $file_id, bool $fragmented = true): bool|str $name = $obj->data['name']; $data = base64_decode($obj->data['data']); // TODO: Walle-Q 返回的 sha256 是空的 - /* if ($obj->data['sha256'] !== hash('sha256', $data)) { - $this->err = 'sha256 mismatch between ' . $obj->data['sha256'] . ' and ' . hash('sha256', $data) . "\n" . json_encode($obj); - return false; - }*/ + /* if ($obj->data['sha256'] !== hash('sha256', $data)) { + $this->err = 'sha256 mismatch between ' . $obj->data['sha256'] . ' and ' . hash('sha256', $data) . "\n" . json_encode($obj); + return false; + }*/ } else { $obj = $this->ctx->sendAction('get_file_fragmented', [ 'stage' => 'prepare', diff --git a/src/ZM/Utils/OneBot12FileUploader.php b/src/ZM/Utils/OneBot12FileUploader.php index e24817e5f..301ca1b88 100644 --- a/src/ZM/Utils/OneBot12FileUploader.php +++ b/src/ZM/Utils/OneBot12FileUploader.php @@ -20,9 +20,7 @@ class OneBot12FileUploader * @param BotContext $ctx 机器人上下文,用于调用发送动作 * @param int $buffer_size 分片传输的大小,默认为 65536 字节,建议调整小于 2MB */ - public function __construct(private BotContext $ctx, private int $buffer_size = 131072) - { - } + public function __construct(private BotContext $ctx, private int $buffer_size = 131072) {} /** * 通过文件内容上传一个文件 diff --git a/src/ZM/Utils/ReflectionUtil.php b/src/ZM/Utils/ReflectionUtil.php index 892b71171..9d5fe0e40 100644 --- a/src/ZM/Utils/ReflectionUtil.php +++ b/src/ZM/Utils/ReflectionUtil.php @@ -81,7 +81,7 @@ public static function variableToString(mixed $var): string * @param callable|string $callback 回调 * @throws \ReflectionException */ - public static function isNonStaticMethod(callable|array|string $callback): bool + public static function isNonStaticMethod(array|callable|string $callback): bool { if (is_array($callback) && is_string($callback[0])) { $reflection = new \ReflectionMethod($callback[0], $callback[1]); diff --git a/src/ZM/Utils/ZMRequest.php b/src/ZM/Utils/ZMRequest.php index 67b2ae42a..8bce746f0 100644 --- a/src/ZM/Utils/ZMRequest.php +++ b/src/ZM/Utils/ZMRequest.php @@ -22,7 +22,7 @@ class ZMRequest * @param bool $only_body 是否只返回 Response 的 body 部分,默认为 True * @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包 */ - public static function get(string|UriInterface|\Stringable $url, array $headers = [], array $config = [], bool $only_body = true): bool|ResponseInterface|string + public static function get(string|\Stringable|UriInterface $url, array $headers = [], array $config = [], bool $only_body = true): bool|ResponseInterface|string { $socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([ 'url' => ($url instanceof UriInterface ? $url->__toString() : $url), @@ -51,7 +51,7 @@ public static function get(string|UriInterface|\Stringable $url, array $headers * @param bool $only_body 是否只返回 Response 的 body 部分,默认为 True * @return bool|ResponseInterface|string 返回 False 代表请求失败,返回 string 为仅 Body 的内容,返回 Response 接口对象表明是回包 */ - public static function post(string|UriInterface|\Stringable $url, array $header, mixed $data, array $config = [], bool $only_body = true): bool|ResponseInterface|string + public static function post(string|\Stringable|UriInterface $url, array $header, mixed $data, array $config = [], bool $only_body = true): bool|ResponseInterface|string { $socket = Framework::getInstance()->getDriver()->createHttpClientSocket(array_merge_recursive([ 'url' => ($url instanceof UriInterface ? $url->__toString() : $url), diff --git a/tests/ZM/Config/ZMConfigTest.php b/tests/ZM/Config/ZMConfigTest.php index 9d46859e1..fe87c65e4 100644 --- a/tests/ZM/Config/ZMConfigTest.php +++ b/tests/ZM/Config/ZMConfigTest.php @@ -68,8 +68,8 @@ protected function setUp(): void public function testGetValueWhenKeyContainsDot(): void { $this->markTestSkipped('should it be supported?'); -// $this->assertEquals('c', $this->config->get('test.a.b')); -// $this->assertEquals('d', $this->config->get('test.a.b.c')); + // $this->assertEquals('c', $this->config->get('test.a.b')); + // $this->assertEquals('d', $this->config->get('test.a.b.c')); } public function testGetBooleanValue(): void diff --git a/tests/ZM/Event/Listener/HttpEventListenerTest.php b/tests/ZM/Event/Listener/HttpEventListenerTest.php index 760a888b3..f54670e2a 100644 --- a/tests/ZM/Event/Listener/HttpEventListenerTest.php +++ b/tests/ZM/Event/Listener/HttpEventListenerTest.php @@ -95,7 +95,7 @@ private function mockRequestEvent(ServerRequest $request, bool $should_have_resp return $event->reveal(); } - private function mockHandler(bool $should_be_called, callable $callback = null): self + private function mockHandler(bool $should_be_called, ?callable $callback = null): self { $handler = $this->prophesize(self::class); if ($should_be_called) { diff --git a/tests/ZM/Utils/ReflectionUtilTest.php b/tests/ZM/Utils/ReflectionUtilTest.php index c3ee23d4d..e6865b763 100644 --- a/tests/ZM/Utils/ReflectionUtilTest.php +++ b/tests/ZM/Utils/ReflectionUtilTest.php @@ -68,8 +68,7 @@ public function testGetCallReflector(mixed $callback, \ReflectionFunctionAbstrac public function provideTestGetCallReflector(): array { - $closure = function () { - }; + $closure = function () {}; return [ 'callable' => [[new ReflectionUtilTestClass(), 'method'], new \ReflectionMethod(ReflectionUtilTestClass::class, 'method')], @@ -83,18 +82,12 @@ public function provideTestGetCallReflector(): array class ReflectionUtilTestClass { - public function method(string $string, ReflectionUtilTestClass $class): void - { - } + public function method(string $string, ReflectionUtilTestClass $class): void {} - public static function staticMethod(string $string, ReflectionUtilTestClass $class): void - { - } + public static function staticMethod(string $string, ReflectionUtilTestClass $class): void {} } class InvokableClass { - public function __invoke(): void - { - } + public function __invoke(): void {} } diff --git a/tests/ZM/Utils/ZMRequestTest.php b/tests/ZM/Utils/ZMRequestTest.php index 2d38d32ce..28d70b689 100644 --- a/tests/ZM/Utils/ZMRequestTest.php +++ b/tests/ZM/Utils/ZMRequestTest.php @@ -16,19 +16,19 @@ class ZMRequestTest extends TestCase public function testPost() { $this->markTestIncomplete('Potential dead on Windows'); -// $r = ZMRequest::post('http://httpbin.org/post', [], 'niubi=123'); -// $this->assertStringContainsString('123', $r); -// $r2 = ZMRequest::post('http://httpbin.org/post', ['User-Agent' => 'test'], 'oijoij=ooo', [], false); -// $this->assertInstanceOf(ResponseInterface::class, $r2); -// $this->assertStringContainsString('ooo', $r2->getBody()->getContents()); + // $r = ZMRequest::post('http://httpbin.org/post', [], 'niubi=123'); + // $this->assertStringContainsString('123', $r); + // $r2 = ZMRequest::post('http://httpbin.org/post', ['User-Agent' => 'test'], 'oijoij=ooo', [], false); + // $this->assertInstanceOf(ResponseInterface::class, $r2); + // $this->assertStringContainsString('ooo', $r2->getBody()->getContents()); } public function testGet() { $this->markTestIncomplete('Potential dead on Windows'); -// $r = ZMRequest::get('http://httpbin.org/get', [ -// 'X-Test' => '123', -// ]); -// $this->assertStringContainsString('123', $r); + // $r = ZMRequest::get('http://httpbin.org/get', [ + // 'X-Test' => '123', + // ]); + // $this->assertStringContainsString('123', $r); } }