From e31de985aeb818e09e812d9e74705334c2ee8aaf Mon Sep 17 00:00:00 2001 From: Nuno Chaves Date: Fri, 28 Sep 2018 13:43:18 +0100 Subject: [PATCH] Update QueryBuilder.php --- src/QueryBuilder.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 5ef6eb0..745c630 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -150,6 +150,10 @@ public function find() /* insert / update */ + /** + * @param $document + * @return $this + */ public function setDocument($document) { if (is_array($document) || is_object($document)) { @@ -160,6 +164,11 @@ public function setDocument($document) } + /** + * @param $document + * @return null + * @throws \Exception + */ public function save($document) { $rid = null; @@ -230,6 +239,7 @@ public function toJson() { return $this->response; } + /** * @return mixed */ @@ -239,8 +249,13 @@ public function toObject() $docs = $res->Documents ?? []; if (!is_array($docs) || empty($docs)) return []; - return $this->multipleResults == true ? $docs : $docs[0]; + if ($this->multipleResults) { + return $docs; + } + + return isset($docs[0]) ? $docs[0] : null; } + /** * @return array|mixed */ @@ -248,8 +263,14 @@ public function toArray() { $res = json_decode($this->response); $docs = $res->Documents ?? []; - return $this->multipleResults == true ? $docs : $docs[0]; + + if ($this->multipleResults) { + return $docs; + } + + return isset($docs[0]) ? $docs[0] : null; } + /** * @param $fieldName * @param null $default