Skip to content

Commit 202539b

Browse files
committed
Make Database constructor accept first class arguments
1 parent 2658f4a commit 202539b

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

src/PHPCouchDB/Database.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,14 @@ class Database
2222
* Constructor for the Database object - this is usually called by
2323
* Server::useDb rather than directly
2424
*
25-
* @param array $options This should contain "client" (implementing
26-
* \GuzzleHTTP\ClientInterface) and "db_name" (a string)
27-
* @throws \PHPCouchDB\Exception\ServerException if we don't have the
28-
* expected constructor arguments
25+
* @param \GuzzleHTTP\ClientInterface $client Our HTTP client
26+
* @param string $db_name The datbase to connect to
2927
*/
3028

31-
public function __construct($options)
29+
public function __construct(\GuzzleHttp\ClientInterface $client, string $db_name)
3230
{
33-
if (empty($options) || !is_array($options)) {
34-
throw new \PHPCouchDB\Exception\ServerException(
35-
'$options is a required parameter, array must contain both the client and a db_name'
36-
);
37-
}
38-
39-
if (isset($options['client']) && $options['client'] instanceof \GuzzleHttp\ClientInterface) {
40-
$this->client = $options['client'];
41-
} else {
42-
throw new \PHPCouchDB\Exception\ServerException(
43-
"The options array must contain a 'client' element of type GuzzleHTTP\ClientInterface"
44-
);
45-
}
46-
47-
if (isset($options['db_name']) && is_string($options['db_name'])) {
48-
$this->db_name = $options['db_name'];
49-
} else {
50-
throw new \PHPCouchDB\Exception\ServerException(
51-
"The options array must contain a 'db_name' key with a value of type string"
52-
);
53-
}
31+
$this->client = $client;
32+
$this->db_name = $db_name;
5433
}
5534

5635
/**

src/PHPCouchDB/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function useDb($options) : \PHPCouchDB\Database
141141
}
142142

143143
if ($exists) {
144-
return new \PHPCouchDB\Database(["client" => $this->client, "db_name" => $db_name]);
144+
return new Database($this->client, $db_name);
145145
}
146146

147147
throw new \PHPCouchDB\Exception\ServerException(

0 commit comments

Comments
 (0)