mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
PHP80 小修 (#187)
* migrate-php80 fix styles fix static analyse * fix some bugs
This commit is contained in:
@@ -12,7 +12,7 @@ use Doctrine\DBAL\ParameterType;
|
||||
class DBConnection implements Connection
|
||||
{
|
||||
/** @var \PDO */
|
||||
private $conn;
|
||||
private object $conn;
|
||||
|
||||
private $pool_name;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class DBPool
|
||||
/**
|
||||
* @var array<string, SwooleObjectPool|WorkermanObjectPool> 连接池列表
|
||||
*/
|
||||
private static $pools = [];
|
||||
private static array $pools = [];
|
||||
|
||||
/**
|
||||
* 通过配置文件创建一个 MySQL 连接池
|
||||
@@ -68,10 +68,9 @@ class DBPool
|
||||
/**
|
||||
* 获取一个数据库连接池
|
||||
*
|
||||
* @param string $name 连接池名称
|
||||
* @return SwooleObjectPool|WorkermanObjectPool
|
||||
* @param string $name 连接池名称
|
||||
*/
|
||||
public static function pool(string $name)
|
||||
public static function pool(string $name): PoolInterface
|
||||
{
|
||||
if (!isset(self::$pools[$name]) && count(self::$pools) !== 1) {
|
||||
throw new \RuntimeException("Pool {$name} not found");
|
||||
|
||||
@@ -9,7 +9,7 @@ use ZM\Store\Database\DBException as DbException;
|
||||
|
||||
class DBQueryBuilder extends QueryBuilder
|
||||
{
|
||||
private $wrapper;
|
||||
private DBWrapper $wrapper;
|
||||
|
||||
public function __construct(DBWrapper $wrapper)
|
||||
{
|
||||
@@ -18,10 +18,9 @@ class DBQueryBuilder extends QueryBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DBStatementWrapper|int
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): DBStatementWrapper|int
|
||||
{
|
||||
if ($this->getType() === self::SELECT) {
|
||||
return $this->wrapper->executeQuery($this->getSQL(), $this->getParameters(), $this->getParameterTypes());
|
||||
|
||||
@@ -13,12 +13,8 @@ use Doctrine\DBAL\ParameterType;
|
||||
|
||||
class DBStatement implements \IteratorAggregate, Statement
|
||||
{
|
||||
/** @var \PDOStatement */
|
||||
private $statement;
|
||||
|
||||
public function __construct($obj)
|
||||
public function __construct(private \PDOStatement $statement)
|
||||
{
|
||||
$this->statement = $obj;
|
||||
}
|
||||
|
||||
public function closeCursor()
|
||||
|
||||
@@ -14,11 +14,8 @@ use Doctrine\DBAL\ForwardCompatibility\Result;
|
||||
|
||||
class DBStatementWrapper
|
||||
{
|
||||
public ?Result $stmt;
|
||||
|
||||
public function __construct(?Result $stmt)
|
||||
public function __construct(public ?Result $stmt)
|
||||
{
|
||||
$this->stmt = $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ class DBWrapper
|
||||
{
|
||||
try {
|
||||
$db_list = config()->get('global.database');
|
||||
if (isset($db_list[$name]) || count($db_list) === 1) {
|
||||
if (isset($db_list[$name]) || (is_countable($db_list) ? count($db_list) : 0) === 1) {
|
||||
if ($name === '') {
|
||||
$name = array_key_first($db_list);
|
||||
}
|
||||
@@ -66,10 +66,9 @@ class DBWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array|false
|
||||
* @throws DBException
|
||||
*/
|
||||
public function fetchAssociative(string $query, array $params = [], array $types = [])
|
||||
public function fetchAssociative(string $query, array $params = [], array $types = []): array|false
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAssociative($query, $params, $types);
|
||||
@@ -80,10 +79,9 @@ class DBWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array|false
|
||||
* @throws DBException
|
||||
*/
|
||||
public function fetchNumeric(string $query, array $params = [], array $types = [])
|
||||
public function fetchNumeric(string $query, array $params = [], array $types = []): array|false
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchNumeric($query, $params, $types);
|
||||
@@ -182,10 +180,9 @@ class DBWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param mixed $value
|
||||
* @param null|int|string|Type $type
|
||||
*/
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
public function quote(mixed $value, $type = ParameterType::STRING)
|
||||
{
|
||||
return $this->connection->quote($value, $type);
|
||||
}
|
||||
@@ -414,7 +411,7 @@ class DBWrapper
|
||||
* @return int|string the number of affected rows
|
||||
* @throws DBException
|
||||
*/
|
||||
public function executeStatement(string $sql, array $params = [], array $types = [])
|
||||
public function executeStatement(string $sql, array $params = [], array $types = []): int|string
|
||||
{
|
||||
try {
|
||||
return $this->connection->executeStatement($sql, $params, $types);
|
||||
@@ -436,7 +433,7 @@ class DBWrapper
|
||||
* @param null|string $name name of the sequence object from which the ID should be returned
|
||||
* @return false|int|string a string representation of the last inserted ID
|
||||
*/
|
||||
public function lastInsertId(?string $name = null)
|
||||
public function lastInsertId(?string $name = null): false|int|string
|
||||
{
|
||||
return $this->connection->lastInsertId($name);
|
||||
}
|
||||
@@ -600,13 +597,10 @@ class DBWrapper
|
||||
*/
|
||||
private function getConnectionClass(string $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'mysql':
|
||||
return MySQLDriver::class;
|
||||
case 'sqlite':
|
||||
return SQLiteDriver::class;
|
||||
default:
|
||||
throw new DBException('Unknown database type: ' . $type);
|
||||
}
|
||||
return match ($type) {
|
||||
'mysql' => MySQLDriver::class,
|
||||
'sqlite' => SQLiteDriver::class,
|
||||
default => throw new DBException('Unknown database type: ' . $type),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user