style 优化

This commit is contained in:
zyimm 2022-10-23 15:00:54 +08:00
parent 27f46b9671
commit a655cf7432
3 changed files with 24 additions and 7 deletions

View File

@ -205,7 +205,7 @@ class Mongodb
* @return bool
* @throws MongoDBException
*/
public function insertOne($namespace, array $data = [])
public function insertOne($namespace, array $data = []): bool
{
try {
/**
@ -220,12 +220,13 @@ class Mongodb
/**
* 插入批量数据
*
* @param $namespace
* @param array $data
* @return bool|string
* @return array
* @throws MongoDBException
*/
public function insertMany($namespace, array $data)
public function insertMany($namespace, array $data): array
{
if (count($data) == count($data, 1)) {
throw new MongoDBException('data is can only be a two-dimensional array');
@ -397,10 +398,10 @@ class Mongodb
*
* @param string $namespace
* @param array $filter
* @return bool
* @return int
* @throws MongoDBException
*/
public function count(string $namespace, array $filter = [])
public function count(string $namespace, array $filter = []): int
{
try {
/**
@ -421,7 +422,7 @@ class Mongodb
* @throws MongoDBException
* @throws Exception
*/
public function command(string $namespace, array $filter = [])
public function command(string $namespace, array $filter = []): bool
{
try {
/**

View File

@ -9,7 +9,9 @@ use Hyperf\Mongodb\MongodbConnection;
use Hyperf\Pool\Pool;
use Hyperf\Utils\Arr;
use InvalidArgumentException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class MongoDBPool extends Pool
{
@ -23,6 +25,12 @@ class MongoDBPool extends Pool
*/
protected $config;
/**
* @param ContainerInterface $container
* @param string $name
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(ContainerInterface $container, string $name)
{
$this->name = $name;

View File

@ -5,7 +5,9 @@ namespace Hyperf\Mongodb\Pool;
use Hyperf\Di\Container;
use Hyperf\Di\Exception\NotFoundException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Swoole\Coroutine\Channel;
class PoolFactory
@ -26,9 +28,15 @@ class PoolFactory
}
/**
* getPool
*
* @param string $name
* @return MongoDBPool|mixed|Channel
* @throws NotFoundException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getPool(string $name): Channel
public function getPool(string $name)
{
if (isset($this->pools[$name])) {
return $this->pools[$name];