From a93f74e64543dab2d981ec266b9521528a56258a Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 7 Aug 2025 10:18:01 +0300 Subject: [PATCH 1/2] Refactor Client class to remove null value checks in document processing This update simplifies the handling of document updates by allowing null values to be included, removing unnecessary checks for null values in the Client class methods. --- src/Client.php | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/Client.php b/src/Client.php index d52e2b28b6..6a6d5ceddd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -461,10 +461,6 @@ class Client $docObj = new stdClass(); foreach ($document as $key => $value) { - if (\is_null($value)) { - continue; - } - $docObj->{$key} = $value; } @@ -486,10 +482,6 @@ class Client $docObj = new stdClass(); foreach ($document as $key => $value) { - if (\is_null($value)) { - continue; - } - $docObj->{$key} = $value; } @@ -540,22 +532,14 @@ class Client */ public function update(string $collection, array $where = [], array $updates = [], array $options = [], bool $multi = false): self { - $cleanUpdates = []; - - foreach ($updates as $k => $v) { - if (\is_null($v)) { - continue; - } - $cleanUpdates[$k] = $v; - } - + $this->query( array_merge([ self::COMMAND_UPDATE => $collection, 'updates' => [ [ 'q' => $this->toObject($where), - 'u' => $this->toObject($cleanUpdates), + 'u' => $this->toObject($updates), 'multi' => $multi, 'upsert' => false ] @@ -582,16 +566,9 @@ class Client $updates = []; foreach ($operations as $op) { - $cleanUpdate = []; - foreach ($op['update'] as $k => $v) { - if (!is_null($v)) { - $cleanUpdate[$k] = $v; - } - } - $updateOperation = [ 'q' => $op['filter'], - 'u' => $this->toObject($cleanUpdate), + 'u' => $this->toObject($op['update']), 'upsert' => true, 'multi' => isset($op['multi']) ? $op['multi'] : false, ]; @@ -897,12 +874,7 @@ class Client if (in_array($k, ['$and', '$or', '$nor']) && is_array($v)) { $values = []; - foreach ($v as $item) { - if (is_null($item)) { - continue; - } - $values[] = is_array($item) ? $this->toObject($item) : $item; } From 21fdcdcc763783ce52c9f8052d1e3c16741e731f Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 7 Aug 2025 10:20:50 +0300 Subject: [PATCH 2/2] Remove unnecessary whitespace in update method of Client class --- src/Client.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 6a6d5ceddd..7a2273c9d9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -532,7 +532,6 @@ class Client */ public function update(string $collection, array $where = [], array $updates = [], array $options = [], bool $multi = false): self { - $this->query( array_merge([ self::COMMAND_UPDATE => $collection,