Skip to content

Commit 3c8fdfd

Browse files
committed
Factor out redundant parameter in append_document()
1 parent 1b082cf commit 3c8fdfd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/MongoDB/BulkWrite.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ static bool php_phongo_bulkwrite_opts_append_array(bson_t* opts, const char* key
139139

140140
/* Appends a document field for the given opts document and key. Returns true on
141141
* success; otherwise, false is returned and an exception is thrown. */
142-
static bool php_phongo_bulkwrite_opts_append_document(bson_t* opts, const char* opts_key, zval* zarr, const char* zarr_key TSRMLS_DC) /* {{{ */
142+
static bool php_phongo_bulkwrite_opts_append_document(bson_t* opts, const char* key, zval* zarr TSRMLS_DC) /* {{{ */
143143
{
144-
zval* value = php_array_fetch(zarr, zarr_key);
144+
zval* value = php_array_fetch(zarr, key);
145145
bson_t b = BSON_INITIALIZER;
146146

147147
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) {
148-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" option to be array or object, %s given", zarr_key, zend_get_type_by_const(Z_TYPE_P(value)));
148+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected \"%s\" option to be array or object, %s given", key, zend_get_type_by_const(Z_TYPE_P(value)));
149149
return false;
150150
}
151151

@@ -156,8 +156,8 @@ static bool php_phongo_bulkwrite_opts_append_document(bson_t* opts, const char*
156156
return false;
157157
}
158158

159-
if (!BSON_APPEND_DOCUMENT(opts, opts_key, &b)) {
160-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", opts_key);
159+
if (!BSON_APPEND_DOCUMENT(opts, key, &b)) {
160+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Error appending \"%s\" option", key);
161161
bson_destroy(&b);
162162
return false;
163163
}
@@ -185,11 +185,11 @@ static bool php_phongo_bulkwrite_opts_append_document(bson_t* opts, const char*
185185
} \
186186
}
187187

188-
#define PHONGO_BULKWRITE_OPT_DOCUMENT(opt) \
189-
if (zoptions && php_array_existsc(zoptions, (opt))) { \
190-
if (!php_phongo_bulkwrite_opts_append_document(boptions, (opt), zoptions, (opt) TSRMLS_CC)) { \
191-
return false; \
192-
} \
188+
#define PHONGO_BULKWRITE_OPT_DOCUMENT(opt) \
189+
if (zoptions && php_array_existsc(zoptions, (opt))) { \
190+
if (!php_phongo_bulkwrite_opts_append_document(boptions, (opt), zoptions TSRMLS_CC)) { \
191+
return false; \
192+
} \
193193
}
194194

195195
/* Applies options (including defaults) for an update operation. */

0 commit comments

Comments
 (0)