Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 995a850

Browse files
tanlisujmikola
andcommitted
Apply suggestions from code review
Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
1 parent f54c3d7 commit 995a850

File tree

4 files changed

+20
-38
lines changed

4 files changed

+20
-38
lines changed

‎src/MongoDB/ServerDescription.c‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,32 @@
2929
zend_class_entry* php_phongo_serverdescription_ce;
3030

3131
/* {{{ proto array MongoDB\Driver\ServerDescription::getHelloResponse()
32-
Returns the most recent "hello" response */
32+
Returns the most recent "hello" response */
3333
static PHP_METHOD(ServerDescription, getHelloResponse)
3434
{
3535
php_phongo_serverdescription_t* intern;
3636
const bson_t* helloResponse;
37+
php_phongo_bson_state state;
3738

3839
intern = Z_SERVERDESCRIPTION_OBJ_P(getThis());
3940

4041
PHONGO_PARSE_PARAMETERS_NONE();
4142

4243
helloResponse = mongoc_server_description_hello_response(intern->server_description);
4344

44-
if (helloResponse->len) {
45-
php_phongo_bson_state state;
46-
47-
PHONGO_BSON_INIT_DEBUG_STATE(state);
48-
49-
if (!php_phongo_bson_to_zval_ex(bson_get_data(helloResponse), helloResponse->len, &state)) {
50-
zval_ptr_dtor(&state.zchild);
51-
return;
52-
}
45+
PHONGO_BSON_INIT_DEBUG_STATE(state);
5346

54-
RETURN_ZVAL(&state.zchild, 0, 1);
55-
} else {
56-
RETURN_NULL();
47+
if (!php_phongo_bson_to_zval_ex(bson_get_data(helloResponse), helloResponse->len, &state)) {
48+
/* Exception should already have been thrown */
49+
zval_ptr_dtor(&state.zchild);
50+
return;
5751
}
52+
53+
RETURN_ZVAL(&state.zchild, 0, 1);
5854
} /* }}} */
5955

6056
/* {{{ proto string MongoDB\Driver\ServerDescription::getHost()
61-
Returns the servers hostname */
57+
Returns the server's hostname */
6258
static PHP_METHOD(ServerDescription, getHost)
6359
{
6460
php_phongo_serverdescription_t* intern;
@@ -80,7 +76,7 @@ static PHP_METHOD(ServerDescription, getLastUpdateTime)
8076

8177
PHONGO_PARSE_PARAMETERS_NONE();
8278

83-
RETVAL_LONG((zend_long) mongoc_server_description_last_update_time(intern->server_description));
79+
RETVAL_LONG(mongoc_server_description_last_update_time(intern->server_description));
8480
} /* }}} */
8581

8682
/* {{{ proto integer MongoDB\Driver\ServerDescription::getPort()
@@ -106,7 +102,7 @@ static PHP_METHOD(ServerDescription, getRoundTripTime)
106102

107103
PHONGO_PARSE_PARAMETERS_NONE();
108104

109-
RETVAL_LONG((zend_long) mongoc_server_description_round_trip_time(intern->server_description));
105+
RETVAL_LONG(mongoc_server_description_round_trip_time(intern->server_description));
110106
} /* }}} */
111107

112108
/* {{{ proto integer MongoDB\Driver\ServerDescription::getType()
@@ -180,7 +176,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(phongo_compat_object
180176

181177
intern = Z_OBJ_SERVERDESCRIPTION(PHONGO_COMPAT_GET_OBJ(object));
182178

183-
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2);
179+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6);
184180

185181
{
186182
zval host, port, type;
@@ -203,20 +199,22 @@ HashTable* php_phongo_serverdescription_get_properties_hash(phongo_compat_object
203199
PHONGO_BSON_INIT_DEBUG_STATE(state);
204200

205201
if (!php_phongo_bson_to_zval_ex(bson_get_data(hello_response), hello_response->len, &state)) {
206-
return false;
202+
zval_ptr_dtor(&state.zchild);
203+
goto done;
207204
}
208205
zend_hash_str_update(props, "hello_response", sizeof("hello_response") - 1, &state.zchild);
209206
}
210207

211208
{
212209
zval last_update_time, round_trip_time;
213210

214-
ZVAL_LONG(&last_update_time, (zend_long) mongoc_server_description_last_update_time(intern->server_description));
211+
ZVAL_LONG(&last_update_time, mongoc_server_description_last_update_time(intern->server_description));
215212
zend_hash_str_update(props, "last_update_time", sizeof("last_update_time") - 1, &last_update_time);
216-
ZVAL_LONG(&round_trip_time, (zend_long) mongoc_server_description_round_trip_time(intern->server_description));
213+
ZVAL_LONG(&round_trip_time, mongoc_server_description_round_trip_time(intern->server_description));
217214
zend_hash_str_update(props, "round_trip_time", sizeof("round_trip_time") - 1, &round_trip_time);
218215
}
219216

217+
done:
220218
return props;
221219
} /* }}} */
222220

‎tests/server/server-getServerDescription-001.phpt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
--TEST--
22
MongoDB\Driver\Server::getServerDescription()
3-
--SKIPIF--
4-
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5-
<?php skip_if_not_live(); ?>
63
--FILE--
74
<?php
85
require_once __DIR__ . "/../utils/basic.inc";

‎tests/serverDescription/serverDescription-debug-001.phpt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
--TEST--
22
MongoDB\Driver\ServerDescription debug output
3-
--SKIPIF--
4-
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5-
<?php skip_if_not_live(); ?>
6-
<?php skip_if_not_clean(); ?>
73
--FILE--
84
<?php
95
require_once __DIR__ . "/../utils/basic.inc";

‎tests/serverDescription/serverDescription-getType-001.phpt‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,15 @@ $expected_types = array(
1313
MongoDB\Driver\ServerDescription::TYPE_RS_PRIMARY
1414
);
1515

16-
function isExpectedType(int $type, array $expected_types) {
17-
foreach ($expected_types as $expected_type) {
18-
if ($expected_type == $type) {
19-
return true;
20-
}
21-
}
22-
return false;
23-
}
24-
2516
$manager = create_test_manager();
2617
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference('primary'));
2718
$type = $server->getServerDescription()->getType();
2819

29-
var_dump(isExpectedType($type, $expected_types));
20+
var_dump(in_array($type, $expected_types));
3021

3122
?>
3223
===DONE===
3324
<?php exit(0); ?>
34-
--EXPECTF--
25+
--EXPECT--
3526
bool(true)
3627
===DONE===

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /