From a655cf74327efae04ee4aea35528893aaf05898b Mon Sep 17 00:00:00 2001 From: zyimm Date: Sun, 23 Oct 2022 15:00:54 +0800 Subject: [PATCH] =?UTF-8?q?style=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Mongodb.php | 13 +++++++------ src/Pool/MongoDBPool.php | 8 ++++++++ src/Pool/PoolFactory.php | 10 +++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Mongodb.php b/src/Mongodb.php index 83c5ad5..104b570 100644 --- a/src/Mongodb.php +++ b/src/Mongodb.php @@ -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 { /** diff --git a/src/Pool/MongoDBPool.php b/src/Pool/MongoDBPool.php index 3778d88..9006d93 100644 --- a/src/Pool/MongoDBPool.php +++ b/src/Pool/MongoDBPool.php @@ -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; diff --git a/src/Pool/PoolFactory.php b/src/Pool/PoolFactory.php index f9f9753..c3c0733 100644 --- a/src/Pool/PoolFactory.php +++ b/src/Pool/PoolFactory.php @@ -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];