66use Illuminate \Support \Arr ;
77use InvalidArgumentException ;
88use MongoDB \Client ;
9+ use MongoDB \Database ;
910
1011class Connection extends BaseConnection
1112{
1213 /**
1314 * The MongoDB database handler.
1415 *
15- * @var \MongoDB\ Database
16+ * @var Database
1617 */
1718 protected $ db ;
1819
1920 /**
2021 * The MongoDB connection handler.
2122 *
22- * @var \MongoDB\ Client
23+ * @var Client
2324 */
2425 protected $ connection ;
2526
2627 /**
2728 * Create a new database connection instance.
2829 *
29- * @param array $config
30+ * @param array $config
3031 */
3132 public function __construct (array $ config )
3233 {
@@ -57,7 +58,7 @@ public function __construct(array $config)
5758 /**
5859 * Begin a fluent query against a database collection.
5960 *
60- * @param string $collection
61+ * @param string $collection
6162 * @return Query\Builder
6263 */
6364 public function collection ($ collection )
@@ -70,8 +71,8 @@ public function collection($collection)
7071 /**
7172 * Begin a fluent query against a database collection.
7273 *
73- * @param string $table
74- * @param string|null $as
74+ * @param string $table
75+ * @param string|null $as
7576 * @return Query\Builder
7677 */
7778 public function table ($ table , $ as = null )
@@ -82,7 +83,7 @@ public function table($table, $as = null)
8283 /**
8384 * Get a MongoDB collection.
8485 *
85- * @param string $name
86+ * @param string $name
8687 * @return Collection
8788 */
8889 public function getCollection ($ name )
@@ -101,7 +102,7 @@ public function getSchemaBuilder()
101102 /**
102103 * Get the MongoDB database object.
103104 *
104- * @return \MongoDB\ Database
105+ * @return Database
105106 */
106107 public function getMongoDB ()
107108 {
@@ -111,7 +112,7 @@ public function getMongoDB()
111112 /**
112113 * return MongoDB object.
113114 *
114- * @return \MongoDB\ Client
115+ * @return Client
115116 */
116117 public function getMongoClient ()
117118 {
@@ -129,12 +130,13 @@ public function getDatabaseName()
129130 /**
130131 * Get the name of the default database based on db config or try to detect it from dsn.
131132 *
132- * @param string $dsn
133- * @param array $config
133+ * @param string $dsn
134+ * @param array $config
134135 * @return string
136+ *
135137 * @throws InvalidArgumentException
136138 */
137- protected function getDefaultDatabaseName ($ dsn , $ config )
139+ protected function getDefaultDatabaseName (string $ dsn , array $ config ): string
138140 {
139141 if (empty ($ config ['database ' ])) {
140142 if (preg_match ('/^mongodb(?:[+]srv)?: \\/ \\/.+ \\/([^?&]+)/s ' , $ dsn , $ matches )) {
@@ -150,12 +152,12 @@ protected function getDefaultDatabaseName($dsn, $config)
150152 /**
151153 * Create a new MongoDB connection.
152154 *
153- * @param string $dsn
154- * @param array $config
155- * @param array $options
156- * @return \MongoDB\ Client
155+ * @param string $dsn
156+ * @param array $config
157+ * @param array $options
158+ * @return Client
157159 */
158- protected function createConnection ($ dsn , array $ config , array $ options )
160+ protected function createConnection ($ dsn , array $ config , array $ options ): Client
159161 {
160162 // By default driver options is an empty array.
161163 $ driverOptions = [];
@@ -186,7 +188,7 @@ public function disconnect()
186188 /**
187189 * Determine if the given configuration array has a dsn string.
188190 *
189- * @param array $config
191+ * @param array $config
190192 * @return bool
191193 */
192194 protected function hasDsnString (array $ config )
@@ -197,21 +199,21 @@ protected function hasDsnString(array $config)
197199 /**
198200 * Get the DSN string form configuration.
199201 *
200- * @param array $config
202+ * @param array $config
201203 * @return string
202204 */
203- protected function getDsnString (array $ config )
205+ protected function getDsnString (array $ config ): string
204206 {
205207 return $ config ['dsn ' ];
206208 }
207209
208210 /**
209211 * Get the DSN string for a host / port configuration.
210212 *
211- * @param array $config
213+ * @param array $config
212214 * @return string
213215 */
214- protected function getHostDsn (array $ config )
216+ protected function getHostDsn (array $ config ): string
215217 {
216218 // Treat host option as array of hosts
217219 $ hosts = is_array ($ config ['host ' ]) ? $ config ['host ' ] : [$ config ['host ' ]];
@@ -232,10 +234,10 @@ protected function getHostDsn(array $config)
232234 /**
233235 * Create a DSN string from a configuration.
234236 *
235- * @param array $config
237+ * @param array $config
236238 * @return string
237239 */
238- protected function getDsn (array $ config )
240+ protected function getDsn (array $ config ): string
239241 {
240242 return $ this ->hasDsnString ($ config )
241243 ? $ this ->getDsnString ($ config )
@@ -285,7 +287,7 @@ protected function getDefaultSchemaGrammar()
285287 /**
286288 * Set database.
287289 *
288- * @param \MongoDB\Database $db
290+ * @param \MongoDB\Database $db
289291 */
290292 public function setDatabase (\MongoDB \Database $ db )
291293 {
@@ -295,12 +297,12 @@ public function setDatabase(\MongoDB\Database $db)
295297 /**
296298 * Dynamically pass methods to the connection.
297299 *
298- * @param string $method
299- * @param array $parameters
300+ * @param string $method
301+ * @param array $parameters
300302 * @return mixed
301303 */
302304 public function __call ($ method , $ parameters )
303305 {
304- return call_user_func_array ([ $ this ->db , $ method], $ parameters );
306+ return $ this ->db -> $ method(... $ parameters );
305307 }
306308}
0 commit comments