mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-02 14:25:38 +08:00
strict to phpstan-level-4
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
parameters:
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
level: 2
|
||||
level: 4
|
||||
paths:
|
||||
- ./src/
|
||||
ignoreErrors:
|
||||
- '#Used constant OS_TYPE_(LINUX|WINDOWS) not found#'
|
||||
- '#Constant .* not found#'
|
||||
dynamicConstantNames:
|
||||
- SWOOLE_VERSION
|
||||
|
||||
@@ -15,6 +15,7 @@ use ZM\Annotation\Swoole\OnRequestEvent;
|
||||
use ZM\API\CQ;
|
||||
use ZM\API\OneBotV11;
|
||||
use ZM\API\TuringAPI;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\ConnectionManager\ConnectionObject;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\EventDispatcher;
|
||||
@@ -95,11 +96,11 @@ class Hello
|
||||
public function turingAPI()
|
||||
{
|
||||
$user_id = ctx()->getUserId();
|
||||
$api = ''; // 请在这里填入你的图灵机器人的apikey
|
||||
$api = ZMConfig::get('global', 'custom.turing_apikey') ?? ''; // 请在这里填入你的图灵机器人的apikey
|
||||
if ($api === '') {
|
||||
return false;
|
||||
} // 如果没有填入apikey则此功能关闭
|
||||
if (($this->_running_annotation ?? null) instanceof CQCommand) {
|
||||
if (property_exists($this, '_running_annotation') && ($this->_running_annotation instanceof CQCommand)) {
|
||||
$msg = ctx()->getFullArg('我在!有什么事吗?');
|
||||
} else {
|
||||
$msg = ctx()->getMessage();
|
||||
|
||||
@@ -379,9 +379,9 @@ class CQ
|
||||
|
||||
/**
|
||||
* 获取消息中第一个CQ码
|
||||
* @param string $msg 消息内容
|
||||
* @param bool $is_object 是否以对象形式返回,如果为False的话,返回数组形式(默认为false)
|
||||
* @return array|CQObject 返回的CQ码(数组或对象)
|
||||
* @param string $msg 消息内容
|
||||
* @param bool $is_object 是否以对象形式返回,如果为False的话,返回数组形式(默认为false)
|
||||
* @return null|array|CQObject 返回的CQ码(数组或对象)
|
||||
*/
|
||||
public static function getCQ(string $msg, bool $is_object = false)
|
||||
{
|
||||
|
||||
@@ -4,9 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation;
|
||||
|
||||
use ArrayIterator;
|
||||
use Closure;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
abstract class AnnotationBase
|
||||
abstract class AnnotationBase implements IteratorAggregate
|
||||
{
|
||||
public $method = '';
|
||||
|
||||
@@ -35,4 +38,9 @@ abstract class AnnotationBase
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator($this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class AnnotationParser
|
||||
|
||||
private $middlewares = [];
|
||||
|
||||
/** @var null|AnnotationReader */
|
||||
/** @var null|AnnotationReader|DualReader */
|
||||
private $reader;
|
||||
|
||||
private $req_mapping = [];
|
||||
|
||||
@@ -9,8 +9,6 @@ declare(strict_types=1);
|
||||
namespace ZM\DB;
|
||||
|
||||
use PDOException;
|
||||
use PDOStatement;
|
||||
use Swoole\Database\PDOStatementProxy;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\DbException;
|
||||
use ZM\MySQL\MySQLManager;
|
||||
@@ -102,11 +100,6 @@ class DB
|
||||
SqlPoolStorage::$sql_pool->putConnection(null);
|
||||
throw new DbException('SQL语句查询错误,' . $line . ',错误信息:' . $conn->errorInfo()[2]);
|
||||
}
|
||||
if (!($ps instanceof PDOStatement) && !($ps instanceof PDOStatementProxy)) {
|
||||
var_dump($ps);
|
||||
SqlPoolStorage::$sql_pool->putConnection(null);
|
||||
throw new DbException('语句查询错误!返回的不是 PDOStatement' . $line);
|
||||
}
|
||||
if ($params == []) {
|
||||
$result = $ps->execute();
|
||||
} elseif (!is_array($params)) {
|
||||
|
||||
@@ -47,7 +47,7 @@ class SelectBody
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fetch_mode
|
||||
* @param mixed $fetch_mode
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAll($fetch_mode = ZM_DEFAULT_FETCH_MODE)
|
||||
@@ -66,7 +66,7 @@ class SelectBody
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $key
|
||||
* @param null|mixed $key
|
||||
* @throws DbException
|
||||
* @return null|mixed
|
||||
*/
|
||||
@@ -83,10 +83,9 @@ class SelectBody
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fetch_mode
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute($fetch_mode = ZM_DEFAULT_FETCH_MODE)
|
||||
public function execute(int $fetch_mode = ZM_DEFAULT_FETCH_MODE)
|
||||
{
|
||||
$str = $this->queryPrepare();
|
||||
$this->result = DB::rawQuery($str[0], $str[1], $fetch_mode);
|
||||
|
||||
@@ -145,10 +145,11 @@ class EventDispatcher
|
||||
|
||||
/**
|
||||
* @param mixed $v
|
||||
* @param null $rule_func
|
||||
* @param null|mixed $rule_func
|
||||
* @param mixed ...$params
|
||||
* @throws InterruptException
|
||||
* @throws AnnotationException
|
||||
* @throws Error
|
||||
* @return bool
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @noinspection PhpPropertyOnlyWrittenInspection
|
||||
* @noinspection PhpUnusedParameterInspection
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
@@ -34,7 +33,12 @@ class OnManagerStart implements SwooleEvent
|
||||
{
|
||||
private static $last_hash = '';
|
||||
|
||||
private static $watch = -1;
|
||||
private static $watch_tick_id = -1;
|
||||
|
||||
public static function getWatchTickId(): int
|
||||
{
|
||||
return self::$watch_tick_id;
|
||||
}
|
||||
|
||||
public function onCall(Server $server)
|
||||
{
|
||||
@@ -65,7 +69,7 @@ class OnManagerStart implements SwooleEvent
|
||||
}
|
||||
}
|
||||
if (Framework::$argv['polling-watch']) {
|
||||
self::$watch = swoole_timer_tick(3000, function () use ($server) {
|
||||
self::$watch_tick_id = swoole_timer_tick(3000, function () use ($server) {
|
||||
$data = (DataProvider::scanDirFiles(DataProvider::getSourceRootDir() . '/src/'));
|
||||
$hash = md5('');
|
||||
foreach ($data as $file) {
|
||||
|
||||
@@ -4,10 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Event\SwooleEvent;
|
||||
|
||||
use Error;
|
||||
use Exception;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\WebSocket\Frame;
|
||||
use Throwable;
|
||||
use ZM\Annotation\Swoole\OnMessageEvent;
|
||||
use ZM\Annotation\Swoole\OnSwooleEvent;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
@@ -53,11 +52,7 @@ class OnMessage implements SwooleEvent
|
||||
$dispatcher1->dispatchEvents($conn);
|
||||
$dispatcher->dispatchEvents($conn);
|
||||
// Console::success("Used ".round((microtime(true) - $starttime) * 1000, 3)." ms!");
|
||||
} catch (Exception $e) {
|
||||
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
|
||||
Console::error(zm_internal_errcode('E00017') . 'Uncaught exception ' . get_class($e) . ' when calling "message": ' . $error_msg);
|
||||
Console::trace();
|
||||
} catch (Error $e) {
|
||||
} catch (Throwable $e) {
|
||||
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
|
||||
Console::error(zm_internal_errcode('E00017') . 'Uncaught ' . get_class($e) . ' when calling "message": ' . $error_msg);
|
||||
Console::trace();
|
||||
|
||||
@@ -6,9 +6,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Event\SwooleEvent;
|
||||
|
||||
use Error;
|
||||
use Exception;
|
||||
use Swoole\Server;
|
||||
use Throwable;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Event\SwooleEvent;
|
||||
@@ -25,11 +24,7 @@ class OnPipeMessage implements SwooleEvent
|
||||
$data = json_decode($data, true);
|
||||
try {
|
||||
WorkerManager::workerAction($src_worker_id, $data);
|
||||
} catch (Exception $e) {
|
||||
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
|
||||
Console::error(zm_internal_errcode('E00021') . 'Uncaught exception ' . get_class($e) . ' when calling "pipeMessage": ' . $error_msg);
|
||||
Console::trace();
|
||||
} catch (Error $e) {
|
||||
} catch (Throwable $e) {
|
||||
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
|
||||
Console::error(zm_internal_errcode('E00021') . 'Uncaught ' . get_class($e) . ' when calling "pipeMessage": ' . $error_msg);
|
||||
Console::trace();
|
||||
|
||||
@@ -13,7 +13,7 @@ use ReflectionException;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Database\PDOConfig;
|
||||
use Swoole\Process;
|
||||
use Swoole\Server;
|
||||
use Swoole\WebSocket\Server;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\Swoole\OnMessageEvent;
|
||||
use ZM\Annotation\Swoole\OnStart;
|
||||
@@ -68,12 +68,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
return;
|
||||
}
|
||||
// DataProvider::saveBuffer();
|
||||
/* @var Server $server */
|
||||
if (server() === null) {
|
||||
$server->shutdown();
|
||||
} else {
|
||||
server()->shutdown();
|
||||
}
|
||||
$server->shutdown();
|
||||
});
|
||||
|
||||
Console::verbose("Worker #{$server->worker_id} starting");
|
||||
|
||||
@@ -447,7 +447,7 @@ class Framework
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id_or_name
|
||||
* @param null|int|string $id_or_name
|
||||
* @throws ZMKnownException
|
||||
* @internal
|
||||
*/
|
||||
|
||||
@@ -19,17 +19,16 @@ class StaticFileHandler
|
||||
if (strpos($full_path, $path) !== 0) {
|
||||
$response->status(403);
|
||||
$response->end('403 Forbidden');
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
if (is_file($full_path)) {
|
||||
$exp = strtolower(pathinfo($full_path)['extension'] ?? 'unknown');
|
||||
$response->setHeader('Content-Type', ZMConfig::get('file_header')[$exp] ?? 'application/octet-stream');
|
||||
$response->end(file_get_contents($full_path));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
$response->status(404);
|
||||
$response->end(HttpUtil::getHttpCodePage(404));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use PDOStatement;
|
||||
use Swoole\Database\PDOProxy;
|
||||
use Swoole\Database\PDOStatementProxy;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\DbException;
|
||||
use ZM\Store\MySQL\SqlPoolStorage;
|
||||
@@ -34,23 +32,31 @@ class MySQLConnection implements Connection
|
||||
SqlPoolStorage::$sql_pool->putConnection($this->conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sql
|
||||
* @param mixed $options
|
||||
* @throws DbException
|
||||
*/
|
||||
public function prepare($sql, $options = [])
|
||||
{
|
||||
try {
|
||||
Console::debug('Running SQL prepare: ' . $sql);
|
||||
$statement = $this->conn->prepare($sql, $options);
|
||||
assert(($statement instanceof PDOStatementProxy) || ($statement instanceof PDOStatement));
|
||||
assert($statement !== false);
|
||||
} catch (PDOException $exception) {
|
||||
throw new DbException($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
return new MySQLStatement($statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DbException
|
||||
*/
|
||||
public function query(...$args)
|
||||
{
|
||||
try {
|
||||
$statement = $this->conn->query(...$args);
|
||||
assert(($statement instanceof PDOStatementProxy) || ($statement instanceof PDOStatement));
|
||||
assert($statement !== false);
|
||||
} catch (PDOException $exception) {
|
||||
throw new DbException($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
@@ -62,6 +68,10 @@ class MySQLConnection implements Connection
|
||||
return $this->conn->quote($value, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sql
|
||||
* @throws DbException
|
||||
*/
|
||||
public function exec($sql)
|
||||
{
|
||||
try {
|
||||
@@ -74,6 +84,10 @@ class MySQLConnection implements Connection
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|mixed $name
|
||||
* @throws DbException
|
||||
*/
|
||||
public function lastInsertId($name = null)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -8,6 +8,6 @@ use ZM\MySQL\MySQLPool;
|
||||
|
||||
class SqlPoolStorage
|
||||
{
|
||||
/** @var MySQLPool */
|
||||
/** @var null|MySQLPool */
|
||||
public static $sql_pool;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
namespace ZM\Utils;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Error;
|
||||
use Exception;
|
||||
use ReflectionClass;
|
||||
use Swoole\Process;
|
||||
@@ -22,6 +23,7 @@ class Terminal
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws Error
|
||||
* @return bool
|
||||
* @noinspection PhpMissingReturnTypeInspection
|
||||
* @noinspection PhpUnused
|
||||
|
||||
@@ -76,13 +76,13 @@ class ZMUtil
|
||||
|
||||
/**
|
||||
* 使用Psr-4标准获取目录下的所有类
|
||||
* @param string $dir 目录
|
||||
* @param string $base_namespace 基础命名空间
|
||||
* @param null|mixed $rule 规则
|
||||
* @param bool $return_path_value 是否返回文件路径
|
||||
* @param string $dir 目录
|
||||
* @param string $base_namespace 基础命名空间
|
||||
* @param null|mixed $rule 规则
|
||||
* @param bool|string $return_path_value 是否返回文件路径,返回文件路径的话传入字符串
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getClassesPsr4(string $dir, string $base_namespace, $rule = null, bool $return_path_value = false): array
|
||||
public static function getClassesPsr4(string $dir, string $base_namespace, $rule = null, $return_path_value = false): array
|
||||
{
|
||||
// 预先读取下composer的file列表
|
||||
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
|
||||
|
||||
@@ -409,7 +409,7 @@ function hash_message(array $message): string
|
||||
*
|
||||
* 与 {@link Framework::$server} 一致
|
||||
*/
|
||||
function server(): ?Server
|
||||
function server(): Server
|
||||
{
|
||||
return Framework::$server;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user