@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | |
| 298 | 298 | /** |
| 299 | 299 | * @brief Returns a list of all database events in the CouchDB instance. |
| 300 | - * @param DbUpdatesFeedOpts $opts Additional options. |
|
| 300 | + * @param Opt\DbUpdatesFeedOpts $opts Additional options. |
|
| 301 | 301 | * @return Response |
| 302 | 302 | * @attention Requires admin privileges. |
| 303 | 303 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#db-updates |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @brief Obtains a list of the changes made to the database. This can be used to monitor for update and modifications |
| 578 | 578 | * to the database for post processing or synchronization. |
| 579 | 579 | * @param string $name The database name. |
| 580 | - * @param ChangesFeedOpts $opts Additional options. |
|
| 580 | + * @param Opt\ChangesFeedOpts $opts Additional options. |
|
| 581 | 581 | * @return Response |
| 582 | 582 | * @see http://docs.couchdb.org/en/latest/api/database/changes.html |
| 583 | 583 | */ |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | /** |
| 709 | 709 | * @brief Returns the special security object for the database. |
| 710 | 710 | * @param string $dbName The database name. |
| 711 | - * @return string A JSON object. |
|
| 711 | + * @return Response A JSON object. |
|
| 712 | 712 | * @see http://docs.couchdb.org/en/latest/api/database/security.html#get--db-_security |
| 713 | 713 | */ |
| 714 | 714 | public function getSecurityObj($dbName) { |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * permanent continuous replications that survive a server restart without you having to do anything. |
| 763 | 763 | * @param string|array $filter (optional) Name of a filter function that can choose which revisions get replicated. |
| 764 | 764 | * You can also provide an array of document identifiers; if given, only these documents will be replicated. |
| 765 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 765 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 766 | 766 | * docs, etc. |
| 767 | 767 | * @return Response |
| 768 | 768 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned |
| 867 | 867 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called |
| 868 | 868 | * multi-document-fetch feature. |
| 869 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 869 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 870 | 870 | * docs, etc. |
| 871 | 871 | * @param ChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. |
| 872 | 872 | * @return Result::QueryResult The result of the query. |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned |
| 899 | 899 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called |
| 900 | 900 | * multi-document-fetch feature. |
| 901 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 901 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 902 | 902 | * docs, etc. |
| 903 | 903 | * @param IChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. |
| 904 | 904 | * @return Result::QueryResult The result of the query. |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned |
| 951 | 951 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called |
| 952 | 952 | * multi-document-fetch feature. |
| 953 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 953 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include |
|
| 954 | 954 | * docs, etc. |
| 955 | 955 | * @param string $language The language used to implement the map and reduce functions. |
| 956 | 956 | * @param IChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. |
@@ -1090,7 +1090,7 @@ discard block |
||
| 1090 | 1090 | * @param string $docId The document's identifier. |
| 1091 | 1091 | * @param string $path The document's path. |
| 1092 | 1092 | * @param string $rev (optional) The document's revision. |
| 1093 | - * @param DocOpts $opts Query options to get additional document information, like conflicts, attachments, etc. |
|
| 1093 | + * @param Opt\DocOpts $opts Query options to get additional document information, like conflicts, attachments, etc. |
|
| 1094 | 1094 | * @return object|Response An instance of Doc, LocalDoc, DesignDoc or any subclass of Doc. |
| 1095 | 1095 | * @see http://docs.couchdb.org/en/latest/api/document/common.html#get--db-docid |
| 1096 | 1096 | */ |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | * using PUT instead we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. |
| 1146 | 1146 | * This is an internal detail. You have only to know that CouchDB can generate the document id for you. |
| 1147 | 1147 | * @param string $dbName The database name. |
| 1148 | - * @param Doc $doc The document you want insert or update. |
|
| 1148 | + * @param Doc\IDoc $doc The document you want insert or update. |
|
| 1149 | 1149 | * @param bool $batchMode (optional) You can write documents to the database at a higher rate by using the batch |
| 1150 | 1150 | * option. This collects document writes together in memory (on a user-by-user basis) before they are committed to |
| 1151 | 1151 | * disk. This increases the risk of the documents not being stored in the event of a failure, since the documents are |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | * @param string $docId The document's identifier. |
| 1335 | 1335 | * @param string $path The document's path. |
| 1336 | 1336 | * @param string $rev (optional) The document's revision. |
| 1337 | - * @return string The document's revision. |
|
| 1337 | + * @return Response The document's revision. |
|
| 1338 | 1338 | * @see http://docs.couchdb.org/en/latest/api/document/attachments.html#db-doc-attachment |
| 1339 | 1339 | */ |
| 1340 | 1340 | public function getAttachmentInfo($dbName, $fileName, $path, $docId, $rev = NULL) { |
@@ -108,10 +108,13 @@ discard block |
||
| 108 | 108 | foreach ($keys as $key) { |
| 109 | 109 | $hash = md5(json_encode($key)); |
| 110 | 110 | |
| 111 | - if (isset($matches[$hash])) // Match found. |
|
| 111 | + if (isset($matches[$hash])) { |
|
| 112 | + // Match found. |
|
| 112 | 113 | $allRows[] = $matches[$hash]; |
| 113 | - else // No match found. |
|
| 114 | + } else { |
|
| 115 | + // No match found. |
|
| 114 | 116 | $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL]; |
| 117 | + } |
|
| 115 | 118 | } |
| 116 | 119 | |
| 117 | 120 | // Overrides the response, replacing rows. |
@@ -174,15 +177,18 @@ discard block |
||
| 174 | 177 | * @param bool $excludeLocal Document path. |
| 175 | 178 | */ |
| 176 | 179 | public function validateDocPath($path, $excludeLocal = FALSE) { |
| 177 | - if (empty($path)) // STD_DOC_PATH |
|
| 180 | + if (empty($path)) { |
|
| 181 | + // STD_DOC_PATH |
|
| 178 | 182 | return; |
| 183 | + } |
|
| 179 | 184 | |
| 180 | - if ($path == self::DESIGN_DOC_PATH) |
|
| 181 | - return; |
|
| 182 | - elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) |
|
| 183 | - throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
| 184 | - else |
|
| 185 | - throw new \InvalidArgumentException("Invalid document path."); |
|
| 185 | + if ($path == self::DESIGN_DOC_PATH) { |
|
| 186 | + return; |
|
| 187 | + } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) { |
|
| 188 | + throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
| 189 | + } else { |
|
| 190 | + throw new \InvalidArgumentException("Invalid document path."); |
|
| 191 | + } |
|
| 186 | 192 | } |
| 187 | 193 | |
| 188 | 194 | |
@@ -193,10 +199,11 @@ discard block |
||
| 193 | 199 | * @param string $docId Document id. |
| 194 | 200 | */ |
| 195 | 201 | public function validateAndEncodeDocId(&$docId) { |
| 196 | - if (!empty($docId)) |
|
| 197 | - $docId = rawurlencode($docId); |
|
| 198 | - else |
|
| 199 | - throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
| 202 | + if (!empty($docId)) { |
|
| 203 | + $docId = rawurlencode($docId); |
|
| 204 | + } else { |
|
| 205 | + throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
| 206 | + } |
|
| 200 | 207 | } |
| 201 | 208 | |
| 202 | 209 | //!@} |
@@ -228,10 +235,10 @@ discard block |
||
| 228 | 235 | // before the client has received the entire response. To avoid problems, we trap the exception and we go on. |
| 229 | 236 | try { |
| 230 | 237 | $this->send($request); |
| 231 | - } |
|
| 232 | - catch (\Exception $e) { |
|
| 233 | - if ($e->getCode() > 0) |
|
| 234 | - throw $e; |
|
| 238 | + } catch (\Exception $e) { |
|
| 239 | + if ($e->getCode() > 0) { |
|
| 240 | + throw $e; |
|
| 241 | + } |
|
| 235 | 242 | } |
| 236 | 243 | } |
| 237 | 244 | |
@@ -268,10 +275,11 @@ discard block |
||
| 268 | 275 | public function getFavicon() { |
| 269 | 276 | $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico")); |
| 270 | 277 | |
| 271 | - if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") |
|
| 272 | - return $response->getBody(); |
|
| 273 | - else |
|
| 274 | - throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
| 278 | + if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") { |
|
| 279 | + return $response->getBody(); |
|
| 280 | + } else { |
|
| 281 | + throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
| 282 | + } |
|
| 275 | 283 | } |
| 276 | 284 | |
| 277 | 285 | |
@@ -305,8 +313,9 @@ discard block |
||
| 305 | 313 | public function getDbUpdates(Opt\DbUpdatesFeedOpts $opts = NULL) { |
| 306 | 314 | $request = new Request(Request::GET_METHOD, "/_db_updates"); |
| 307 | 315 | |
| 308 | - if (isset($opts)) |
|
| 309 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 316 | + if (isset($opts)) { |
|
| 317 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 318 | + } |
|
| 310 | 319 | |
| 311 | 320 | return $this->send($request)->getBodyAsArray(); |
| 312 | 321 | } |
@@ -335,9 +344,9 @@ discard block |
||
| 335 | 344 | $request = new Request(Request::GET_METHOD, "/_log"); |
| 336 | 345 | $request->setQueryParam("bytes", $bytes); |
| 337 | 346 | return $this->send($request)->getBody(); |
| 347 | + } else { |
|
| 348 | + throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
| 338 | 349 | } |
| 339 | - else |
|
| 340 | - throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
| 341 | 350 | } |
| 342 | 351 | |
| 343 | 352 | |
@@ -354,13 +363,15 @@ discard block |
||
| 354 | 363 | |
| 355 | 364 | $response = $this->send($request); |
| 356 | 365 | |
| 357 | - if ($count == 1) // We don't need to use === operator because, just above, we made a type checking. |
|
| 366 | + if ($count == 1) { |
|
| 367 | + // We don't need to use === operator because, just above, we made a type checking. |
|
| 358 | 368 | return $response->getBodyAsArray()['uuids'][0]; |
| 359 | - else |
|
| 360 | - return $response->getBodyAsArray()['uuids']; |
|
| 369 | + } else { |
|
| 370 | + return $response->getBodyAsArray()['uuids']; |
|
| 371 | + } |
|
| 372 | + } else { |
|
| 373 | + throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
| 361 | 374 | } |
| 362 | - else |
|
| 363 | - throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
| 364 | 375 | } |
| 365 | 376 | |
| 366 | 377 | //!@} |
@@ -384,8 +395,9 @@ discard block |
||
| 384 | 395 | if (!empty($section)) { |
| 385 | 396 | $path .= "/".$section; |
| 386 | 397 | |
| 387 | - if (!empty($key)) |
|
| 388 | - $path .= "/".$key; |
|
| 398 | + if (!empty($key)) { |
|
| 399 | + $path .= "/".$key; |
|
| 400 | + } |
|
| 389 | 401 | } |
| 390 | 402 | |
| 391 | 403 | return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray(); |
@@ -400,14 +412,17 @@ discard block |
||
| 400 | 412 | * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key |
| 401 | 413 | */ |
| 402 | 414 | public function setConfigKey($section, $key, $value) { |
| 403 | - if (!is_string($section) or empty($section)) |
|
| 404 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 415 | + if (!is_string($section) or empty($section)) { |
|
| 416 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 417 | + } |
|
| 405 | 418 | |
| 406 | - if (!is_string($key) or empty($key)) |
|
| 407 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 419 | + if (!is_string($key) or empty($key)) { |
|
| 420 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 421 | + } |
|
| 408 | 422 | |
| 409 | - if (is_null($value)) |
|
| 410 | - throw new \InvalidArgumentException("\$value cannot be null."); |
|
| 423 | + if (is_null($value)) { |
|
| 424 | + throw new \InvalidArgumentException("\$value cannot be null."); |
|
| 425 | + } |
|
| 411 | 426 | |
| 412 | 427 | $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key); |
| 413 | 428 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -423,11 +438,13 @@ discard block |
||
| 423 | 438 | * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key |
| 424 | 439 | */ |
| 425 | 440 | public function deleteConfigKey($section, $key) { |
| 426 | - if (!is_string($section) or empty($section)) |
|
| 427 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 441 | + if (!is_string($section) or empty($section)) { |
|
| 442 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 443 | + } |
|
| 428 | 444 | |
| 429 | - if (!is_string($key) or empty($key)) |
|
| 430 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 445 | + if (!is_string($key) or empty($key)) { |
|
| 446 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 447 | + } |
|
| 431 | 448 | |
| 432 | 449 | $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key)); |
| 433 | 450 | } |
@@ -454,11 +471,13 @@ discard block |
||
| 454 | 471 | * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session |
| 455 | 472 | */ |
| 456 | 473 | public function setSession($userName, $password) { |
| 457 | - if (!is_string($userName) or empty($userName)) |
|
| 458 | - throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
| 474 | + if (!is_string($userName) or empty($userName)) { |
|
| 475 | + throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
| 476 | + } |
|
| 459 | 477 | |
| 460 | - if (!is_string($password) or empty($password)) |
|
| 461 | - throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
| 478 | + if (!is_string($password) or empty($password)) { |
|
| 479 | + throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
| 480 | + } |
|
| 462 | 481 | |
| 463 | 482 | $request = new Request(Request::POST_METHOD, "/_session"); |
| 464 | 483 | |
@@ -545,8 +564,9 @@ discard block |
||
| 545 | 564 | # One of the characters “_$()” «_$()» |
| 546 | 565 | # A character in the range between “+” and “/” «+-/» |
| 547 | 566 | # Assert position at the very end of the string «\z» |
| 548 | - if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) |
|
| 549 | - throw new \InvalidArgumentException("Invalid database name."); |
|
| 567 | + if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) { |
|
| 568 | + throw new \InvalidArgumentException("Invalid database name."); |
|
| 569 | + } |
|
| 550 | 570 | |
| 551 | 571 | $this->send(new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$name)."/")); |
| 552 | 572 | } |
@@ -584,8 +604,9 @@ discard block |
||
| 584 | 604 | public function getDbChanges($name, Opt\ChangesFeedOpts $opts = NULL) { |
| 585 | 605 | $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$name)."/_changes"); |
| 586 | 606 | |
| 587 | - if (isset($opts)) |
|
| 588 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 607 | + if (isset($opts)) { |
|
| 608 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 609 | + } |
|
| 589 | 610 | |
| 590 | 611 | return $this->send($request); |
| 591 | 612 | } |
@@ -774,40 +795,47 @@ discard block |
||
| 774 | 795 | is_string($targetDbUrl) && !empty($targetDbUrl)) { |
| 775 | 796 | $body["source"] = $sourceDbUrl; |
| 776 | 797 | $body["target"] = $targetDbUrl; |
| 798 | + } else { |
|
| 799 | + throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
| 777 | 800 | } |
| 778 | - else |
|
| 779 | - throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
| 780 | 801 | |
| 781 | - if (!is_bool($continuous)) |
|
| 782 | - throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
| 783 | - elseif ($continuous) |
|
| 784 | - $body["continuous"] = $continuous; |
|
| 802 | + if (!is_bool($continuous)) { |
|
| 803 | + throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
| 804 | + } elseif ($continuous) { |
|
| 805 | + $body["continuous"] = $continuous; |
|
| 806 | + } |
|
| 785 | 807 | |
| 786 | 808 | // Uses the specified proxy if any set. |
| 787 | - if (isset($proxy)) |
|
| 788 | - $body["proxy"] = $proxy; |
|
| 809 | + if (isset($proxy)) { |
|
| 810 | + $body["proxy"] = $proxy; |
|
| 811 | + } |
|
| 789 | 812 | |
| 790 | 813 | // create_target option |
| 791 | - if (!is_bool($createTargetDb)) |
|
| 792 | - throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
| 793 | - elseif ($createTargetDb) |
|
| 794 | - $body["create_target"] = $createTargetDb; |
|
| 814 | + if (!is_bool($createTargetDb)) { |
|
| 815 | + throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
| 816 | + } elseif ($createTargetDb) { |
|
| 817 | + $body["create_target"] = $createTargetDb; |
|
| 818 | + } |
|
| 795 | 819 | |
| 796 | 820 | if (!empty($filter)) { |
| 797 | - if (is_string($filter)) // filter option |
|
| 821 | + if (is_string($filter)) { |
|
| 822 | + // filter option |
|
| 798 | 823 | $body["filter"] = $filter; |
| 799 | - elseif (is_array($filter)) // doc_ids option |
|
| 824 | + } elseif (is_array($filter)) { |
|
| 825 | + // doc_ids option |
|
| 800 | 826 | $body["doc_ids"] = array_values($filter); |
| 801 | - else |
|
| 802 | - throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
| 827 | + } else { |
|
| 828 | + throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
| 829 | + } |
|
| 803 | 830 | } |
| 804 | 831 | |
| 805 | 832 | // queryParams option |
| 806 | 833 | if (!is_null($opts)) { |
| 807 | - if ($opts instanceof Opt\ViewQueryOpts) |
|
| 808 | - $body["query_params"] = get_object_vars($opts); |
|
| 809 | - else |
|
| 810 | - throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
| 834 | + if ($opts instanceof Opt\ViewQueryOpts) { |
|
| 835 | + $body["query_params"] = get_object_vars($opts); |
|
| 836 | + } else { |
|
| 837 | + throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
| 838 | + } |
|
| 811 | 839 | } |
| 812 | 840 | |
| 813 | 841 | $request = new Request(Request::POST_METHOD, "/_replicate"); |
@@ -824,8 +852,9 @@ discard block |
||
| 824 | 852 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication |
| 825 | 853 | */ |
| 826 | 854 | public function stopReplication($replicationId) { |
| 827 | - if (is_null($replicationId)) |
|
| 828 | - throw new \InvalidArgumentException("You must provide a replication id."); |
|
| 855 | + if (is_null($replicationId)) { |
|
| 856 | + throw new \InvalidArgumentException("You must provide a replication id."); |
|
| 857 | + } |
|
| 829 | 858 | |
| 830 | 859 | $body["replication_id"] = $replicationId; |
| 831 | 860 | $body["cancel"] = TRUE; |
@@ -874,15 +903,16 @@ discard block |
||
| 874 | 903 | * @see http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs |
| 875 | 904 | */ |
| 876 | 905 | public function queryAllDocs($dbName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { |
| 877 | - if (is_null($keys)) |
|
| 878 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
|
| 879 | - else { |
|
| 906 | + if (is_null($keys)) { |
|
| 907 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
|
| 908 | + } else { |
|
| 880 | 909 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
| 881 | 910 | $request->setBody(json_encode(['keys' => $keys])); |
| 882 | 911 | } |
| 883 | 912 | |
| 884 | - if (isset($opts)) |
|
| 885 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 913 | + if (isset($opts)) { |
|
| 914 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 915 | + } |
|
| 886 | 916 | |
| 887 | 917 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 888 | 918 | |
@@ -911,12 +941,13 @@ discard block |
||
| 911 | 941 | public function queryView($dbName, $designDocName, $viewName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { |
| 912 | 942 | $this->validateAndEncodeDocId($designDocName); |
| 913 | 943 | |
| 914 | - if (empty($viewName)) |
|
| 915 | - throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
| 944 | + if (empty($viewName)) { |
|
| 945 | + throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
| 946 | + } |
|
| 916 | 947 | |
| 917 | - if (empty($keys)) |
|
| 918 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
|
| 919 | - else { |
|
| 948 | + if (empty($keys)) { |
|
| 949 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
|
| 950 | + } else { |
|
| 920 | 951 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
| 921 | 952 | $request->setBody(json_encode(['keys' => $keys])); |
| 922 | 953 | } |
@@ -927,14 +958,15 @@ discard block |
||
| 927 | 958 | if (isset($opts)) { |
| 928 | 959 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 929 | 960 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
| 961 | + } else { |
|
| 962 | + $includeMissingKeys = FALSE; |
|
| 930 | 963 | } |
| 931 | - else |
|
| 932 | - $includeMissingKeys = FALSE; |
|
| 933 | 964 | |
| 934 | 965 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 935 | 966 | |
| 936 | - if ($includeMissingKeys) |
|
| 937 | - $this->addMissingRows($keys, $result['rows']); |
|
| 967 | + if ($includeMissingKeys) { |
|
| 968 | + $this->addMissingRows($keys, $result['rows']); |
|
| 969 | + } |
|
| 938 | 970 | |
| 939 | 971 | return new Result\QueryResult($result); |
| 940 | 972 | } |
@@ -961,30 +993,33 @@ discard block |
||
| 961 | 993 | $handler = new Handler\ViewHandler('temp'); |
| 962 | 994 | $handler->language = $language; |
| 963 | 995 | $handler->mapFn = $mapFn; |
| 964 | - if (!empty($reduce)) |
|
| 965 | - $handler->reduceFn = $reduceFn; |
|
| 996 | + if (!empty($reduce)) { |
|
| 997 | + $handler->reduceFn = $reduceFn; |
|
| 998 | + } |
|
| 966 | 999 | |
| 967 | 1000 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_temp_view"); |
| 968 | 1001 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
| 969 | 1002 | |
| 970 | 1003 | $array = $handler->asArray(); |
| 971 | 1004 | |
| 972 | - if (!empty($keys)) |
|
| 973 | - $array['keys'] = $keys; |
|
| 1005 | + if (!empty($keys)) { |
|
| 1006 | + $array['keys'] = $keys; |
|
| 1007 | + } |
|
| 974 | 1008 | |
| 975 | 1009 | $request->setBody(json_encode($array)); |
| 976 | 1010 | |
| 977 | 1011 | if (isset($opts)) { |
| 978 | 1012 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 979 | 1013 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
| 1014 | + } else { |
|
| 1015 | + $includeMissingKeys = FALSE; |
|
| 980 | 1016 | } |
| 981 | - else |
|
| 982 | - $includeMissingKeys = FALSE; |
|
| 983 | 1017 | |
| 984 | 1018 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 985 | 1019 | |
| 986 | - if ($includeMissingKeys) |
|
| 987 | - $this->addMissingRows($keys, $result['rows']); |
|
| 1020 | + if ($includeMissingKeys) { |
|
| 1021 | + $this->addMissingRows($keys, $result['rows']); |
|
| 1022 | + } |
|
| 988 | 1023 | |
| 989 | 1024 | return new Result\QueryResult($result); |
| 990 | 1025 | } |
@@ -1043,8 +1078,9 @@ discard block |
||
| 1043 | 1078 | * @see http://docs.couchdb.org/en/latest/api/database/misc.html#put--db-_revs_limit |
| 1044 | 1079 | */ |
| 1045 | 1080 | public function setRevsLimit($dbName, $revsLimit = self::REVS_LIMIT) { |
| 1046 | - if (!is_int($revsLimit) or ($revsLimit <= 0)) |
|
| 1047 | - throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
| 1081 | + if (!is_int($revsLimit) or ($revsLimit <= 0)) { |
|
| 1082 | + throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
| 1083 | + } |
|
| 1048 | 1084 | |
| 1049 | 1085 | $request = new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_revs_limit"); |
| 1050 | 1086 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -1103,16 +1139,17 @@ discard block |
||
| 1103 | 1139 | $request = new Request(Request::GET_METHOD, $requestPath); |
| 1104 | 1140 | |
| 1105 | 1141 | // Retrieves the specific revision of the document. |
| 1106 | - if (!empty($rev)) |
|
| 1107 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1142 | + if (!empty($rev)) { |
|
| 1143 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1144 | + } |
|
| 1108 | 1145 | |
| 1109 | 1146 | // If there are any options, add them to the request. |
| 1110 | 1147 | if (isset($opts)) { |
| 1111 | 1148 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 1112 | 1149 | $ignoreClass = $opts->issetIgnoreClass(); |
| 1150 | + } else { |
|
| 1151 | + $ignoreClass = FALSE; |
|
| 1113 | 1152 | } |
| 1114 | - else |
|
| 1115 | - $ignoreClass = FALSE; |
|
| 1116 | 1153 | |
| 1117 | 1154 | $response = $this->send($request); |
| 1118 | 1155 | $body = $response->getBodyAsArray(); |
@@ -1124,18 +1161,18 @@ discard block |
||
| 1124 | 1161 | if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc. |
| 1125 | 1162 | $class = "\\".$body['class']; |
| 1126 | 1163 | $doc = new $class; |
| 1164 | + } elseif ($path == self::DESIGN_DOC_PATH) { |
|
| 1165 | + $doc = new Doc\DesignDoc; |
|
| 1166 | + } else { |
|
| 1167 | + $doc = NULL; |
|
| 1127 | 1168 | } |
| 1128 | - elseif ($path == self::DESIGN_DOC_PATH) |
|
| 1129 | - $doc = new Doc\DesignDoc; |
|
| 1130 | - else |
|
| 1131 | - $doc = NULL; |
|
| 1132 | 1169 | |
| 1133 | 1170 | if (is_object($doc)) { |
| 1134 | 1171 | $doc->assignArray($body); |
| 1135 | 1172 | return $doc; |
| 1173 | + } else { |
|
| 1174 | + return $response; |
|
| 1136 | 1175 | } |
| 1137 | - else |
|
| 1138 | - return $response; |
|
| 1139 | 1176 | } |
| 1140 | 1177 | |
| 1141 | 1178 | |
@@ -1155,8 +1192,9 @@ discard block |
||
| 1155 | 1192 | public function saveDoc($dbName, Doc\IDoc $doc, $batchMode = FALSE) { |
| 1156 | 1193 | // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc |
| 1157 | 1194 | // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. |
| 1158 | - if (!$doc->issetId()) |
|
| 1159 | - $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
| 1195 | + if (!$doc->issetId()) { |
|
| 1196 | + $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
| 1197 | + } |
|
| 1160 | 1198 | |
| 1161 | 1199 | $this->setDocInfo($doc); |
| 1162 | 1200 | |
@@ -1170,8 +1208,9 @@ discard block |
||
| 1170 | 1208 | $request->setBody($doc->asJson()); |
| 1171 | 1209 | |
| 1172 | 1210 | // Enables batch mode. |
| 1173 | - if ($batchMode) |
|
| 1174 | - $request->setQueryParam("batch", "ok"); |
|
| 1211 | + if ($batchMode) { |
|
| 1212 | + $request->setQueryParam("batch", "ok"); |
|
| 1213 | + } |
|
| 1175 | 1214 | |
| 1176 | 1215 | $this->send($request); |
| 1177 | 1216 | } |
@@ -1224,10 +1263,11 @@ discard block |
||
| 1224 | 1263 | // This request uses the special method COPY. |
| 1225 | 1264 | $request = new Request(Request::COPY_METHOD, $path); |
| 1226 | 1265 | |
| 1227 | - if (empty($rev)) |
|
| 1228 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
| 1229 | - else |
|
| 1230 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
| 1266 | + if (empty($rev)) { |
|
| 1267 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
| 1268 | + } else { |
|
| 1269 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
| 1270 | + } |
|
| 1231 | 1271 | |
| 1232 | 1272 | $this->send($request); |
| 1233 | 1273 | } |
@@ -1256,8 +1296,9 @@ discard block |
||
| 1256 | 1296 | $request = new Request(Request::POST_METHOD, $path); |
| 1257 | 1297 | |
| 1258 | 1298 | $purge = []; |
| 1259 | - foreach ($refs as $ref) |
|
| 1260 | - $purge[] = $ref->asArray(); |
|
| 1299 | + foreach ($refs as $ref) { |
|
| 1300 | + $purge[] = $ref->asArray(); |
|
| 1301 | + } |
|
| 1261 | 1302 | |
| 1262 | 1303 | $request->setBody(json_encode($purge)); |
| 1263 | 1304 | |
@@ -1289,26 +1330,30 @@ discard block |
||
| 1289 | 1330 | * @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API |
| 1290 | 1331 | */ |
| 1291 | 1332 | public function performBulkOperations($dbName, array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) { |
| 1292 | - if (count($docs) == 0) |
|
| 1293 | - throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
| 1294 | - else |
|
| 1295 | - $operations = []; |
|
| 1333 | + if (count($docs) == 0) { |
|
| 1334 | + throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
| 1335 | + } else { |
|
| 1336 | + $operations = []; |
|
| 1337 | + } |
|
| 1296 | 1338 | |
| 1297 | 1339 | $path = "/".rawurlencode($this->prefix.$dbName)."/_bulk_docs"; |
| 1298 | 1340 | |
| 1299 | 1341 | $request = new Request(Request::POST_METHOD, $path); |
| 1300 | 1342 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
| 1301 | 1343 | |
| 1302 | - if ($fullCommit) |
|
| 1303 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
| 1304 | - else |
|
| 1305 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
| 1344 | + if ($fullCommit) { |
|
| 1345 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
| 1346 | + } else { |
|
| 1347 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
| 1348 | + } |
|
| 1306 | 1349 | |
| 1307 | - if ($allOrNothing) |
|
| 1308 | - $operations['all_or_nothing'] = 'true'; |
|
| 1350 | + if ($allOrNothing) { |
|
| 1351 | + $operations['all_or_nothing'] = 'true'; |
|
| 1352 | + } |
|
| 1309 | 1353 | |
| 1310 | - if (!$newEdits) |
|
| 1311 | - $operations['new_edits'] = 'false'; |
|
| 1354 | + if (!$newEdits) { |
|
| 1355 | + $operations['new_edits'] = 'false'; |
|
| 1356 | + } |
|
| 1312 | 1357 | |
| 1313 | 1358 | foreach ($docs as $doc) { |
| 1314 | 1359 | $this->setDocInfo($doc); |
@@ -1346,8 +1391,9 @@ discard block |
||
| 1346 | 1391 | $request = new Request(Request::HEAD_METHOD, $path); |
| 1347 | 1392 | |
| 1348 | 1393 | // In case we want retrieve a specific document revision. |
| 1349 | - if (!empty($rev)) |
|
| 1350 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1394 | + if (!empty($rev)) { |
|
| 1395 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1396 | + } |
|
| 1351 | 1397 | |
| 1352 | 1398 | return $this->send($request); |
| 1353 | 1399 | } |
@@ -1373,8 +1419,9 @@ discard block |
||
| 1373 | 1419 | $request = new Request(Request::GET_METHOD, $path); |
| 1374 | 1420 | |
| 1375 | 1421 | // In case we want retrieve a specific document revision. |
| 1376 | - if (!empty($rev)) |
|
| 1377 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1422 | + if (!empty($rev)) { |
|
| 1423 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1424 | + } |
|
| 1378 | 1425 | |
| 1379 | 1426 | return $this->send($request)->getBody(); |
| 1380 | 1427 | } |
@@ -1403,8 +1450,9 @@ discard block |
||
| 1403 | 1450 | $request->setBody(base64_encode($attachment->getData())); |
| 1404 | 1451 | |
| 1405 | 1452 | // In case of adding or updating an existence document. |
| 1406 | - if (!empty($rev)) |
|
| 1407 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1453 | + if (!empty($rev)) { |
|
| 1454 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1455 | + } |
|
| 1408 | 1456 | |
| 1409 | 1457 | return $this->send($request); |
| 1410 | 1458 | } |
@@ -50,10 +50,11 @@ |
||
| 50 | 50 | * @return string|bool The codec name or `false` if the attachment is not compressed. |
| 51 | 51 | */ |
| 52 | 52 | public function getContentEncoding() { |
| 53 | - if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) |
|
| 54 | - return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 55 | - else |
|
| 56 | - return FALSE; |
|
| 53 | + if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) { |
|
| 54 | + return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 55 | + } else { |
|
| 56 | + return FALSE; |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * arrays. |
| 55 | 55 | * @return array An array of rows. |
| 56 | 56 | */ |
| 57 | - public function asArray() { |
|
| 57 | + public function asArray() { |
|
| 58 | 58 | return $this->result['rows']; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param integer $offset The offset to retrieve. |
| 106 | 106 | * @return mixed Can return all value types. |
| 107 | 107 | */ |
| 108 | - public function offsetGet($offset) { |
|
| 108 | + public function offsetGet($offset) { |
|
| 109 | 109 | return $this->result['rows'][$offset]; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -81,10 +81,11 @@ discard block |
||
| 81 | 81 | * @param integer $since Sequence number to start results. Allowed values: positive integers | 'now'. |
| 82 | 82 | */ |
| 83 | 83 | public function setSince($since = 0) { |
| 84 | - if (($since == "now") or (is_int($since) and ($since >= 0))) |
|
| 85 | - $this->options["since"] = $since; |
|
| 86 | - else |
|
| 87 | - throw new \InvalidArgumentException("\$since must be a non-negative integer or can be 'now'."); |
|
| 84 | + if (($since == "now") or (is_int($since) and ($since >= 0))) { |
|
| 85 | + $this->options["since"] = $since; |
|
| 86 | + } else { |
|
| 87 | + throw new \InvalidArgumentException("\$since must be a non-negative integer or can be 'now'."); |
|
| 88 | + } |
|
| 88 | 89 | |
| 89 | 90 | return $this; |
| 90 | 91 | } |
@@ -95,10 +96,11 @@ discard block |
||
| 95 | 96 | * @param integer $limit Maximum number of rows to return. Must be a positive integer. |
| 96 | 97 | */ |
| 97 | 98 | public function setLimit($limit) { |
| 98 | - if (is_int($limit) and ($limit > 0)) |
|
| 99 | - $this->options["limit"] = $limit; |
|
| 100 | - else |
|
| 101 | - throw new \InvalidArgumentException("\$value must be a positive integer."); |
|
| 99 | + if (is_int($limit) and ($limit > 0)) { |
|
| 100 | + $this->options["limit"] = $limit; |
|
| 101 | + } else { |
|
| 102 | + throw new \InvalidArgumentException("\$value must be a positive integer."); |
|
| 103 | + } |
|
| 102 | 104 | |
| 103 | 105 | return $this; |
| 104 | 106 | } |
@@ -117,10 +119,11 @@ discard block |
||
| 117 | 119 | * @param string $type Type of feed. |
| 118 | 120 | */ |
| 119 | 121 | public function setFeedType($type) { |
| 120 | - if (array_key_exists($type, self::$supportedTypes)) |
|
| 121 | - $this->options["feed"] = $type; |
|
| 122 | - else |
|
| 123 | - throw new \InvalidArgumentException("Invalid feed type."); |
|
| 122 | + if (array_key_exists($type, self::$supportedTypes)) { |
|
| 123 | + $this->options["feed"] = $type; |
|
| 124 | + } else { |
|
| 125 | + throw new \InvalidArgumentException("Invalid feed type."); |
|
| 126 | + } |
|
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | |
@@ -130,10 +133,11 @@ discard block |
||
| 130 | 133 | * @param bool $style The feed style. |
| 131 | 134 | */ |
| 132 | 135 | public function setStyle($style) { |
| 133 | - if (array_key_exists($style, self::$supportedStyles)) |
|
| 134 | - $this->options["style"] = $style; |
|
| 135 | - else |
|
| 136 | - throw new \InvalidArgumentException("Invalid feed style."); |
|
| 136 | + if (array_key_exists($style, self::$supportedStyles)) { |
|
| 137 | + $this->options["style"] = $style; |
|
| 138 | + } else { |
|
| 139 | + throw new \InvalidArgumentException("Invalid feed style."); |
|
| 140 | + } |
|
| 137 | 141 | } |
| 138 | 142 | |
| 139 | 143 | |
@@ -146,11 +150,12 @@ discard block |
||
| 146 | 150 | public function setHeartbeat($heartbeat = self::DEFAULT_HEARTBEAT) { |
| 147 | 151 | $feed = $this->options['feed']; |
| 148 | 152 | |
| 149 | - if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) |
|
| 150 | - if (is_int($heartbeat) and ($heartbeat >= 0)) |
|
| 153 | + if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) { |
|
| 154 | + if (is_int($heartbeat) and ($heartbeat >= 0)) |
|
| 151 | 155 | $this->options["heartbeat"] = $heartbeat; |
| 152 | - else |
|
| 153 | - throw new \InvalidArgumentException("\$heartbeat must be a non-negative integer."); |
|
| 156 | + } else { |
|
| 157 | + throw new \InvalidArgumentException("\$heartbeat must be a non-negative integer."); |
|
| 158 | + } |
|
| 154 | 159 | } |
| 155 | 160 | |
| 156 | 161 | |
@@ -163,11 +168,12 @@ discard block |
||
| 163 | 168 | public function setTimeout($timeout = self::DEFAULT_TIMEOUT) { |
| 164 | 169 | $feed = $this->options['feed']; |
| 165 | 170 | |
| 166 | - if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) |
|
| 167 | - if (is_int($timeout) and ($timeout > 0)) |
|
| 171 | + if (($feed == self::CONTINUOUS_TYPE) or ($feed == self::LONGPOLL_TYPE)) { |
|
| 172 | + if (is_int($timeout) and ($timeout > 0)) |
|
| 168 | 173 | $this->options["timeout"] = $timeout; |
| 169 | - else |
|
| 170 | - throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 174 | + } else { |
|
| 175 | + throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 176 | + } |
|
| 171 | 177 | } |
| 172 | 178 | |
| 173 | 179 | |
@@ -143,10 +143,11 @@ |
||
| 143 | 143 | * @param string|array $revs The revision(s) identifier(s). |
| 144 | 144 | */ |
| 145 | 145 | public function includeOpenRevs($revs = 'all') { |
| 146 | - if (is_array($revs)) |
|
| 147 | - $this->options['open_revs'] = json_encode($revs); |
|
| 148 | - else |
|
| 149 | - $this->options['open_revs'] = 'all'; |
|
| 146 | + if (is_array($revs)) { |
|
| 147 | + $this->options['open_revs'] = json_encode($revs); |
|
| 148 | + } else { |
|
| 149 | + $this->options['open_revs'] = 'all'; |
|
| 150 | + } |
|
| 150 | 151 | |
| 151 | 152 | return $this; |
| 152 | 153 | } |
@@ -63,10 +63,11 @@ discard block |
||
| 63 | 63 | * @param string $type Type of feed. |
| 64 | 64 | */ |
| 65 | 65 | public function setFeedType($type) { |
| 66 | - if (array_key_exists($type, self::$supportedTypes)) |
|
| 67 | - $this->options["feed"] = $type; |
|
| 68 | - else |
|
| 69 | - throw new \InvalidArgumentException("Invalid feed type."); |
|
| 66 | + if (array_key_exists($type, self::$supportedTypes)) { |
|
| 67 | + $this->options["feed"] = $type; |
|
| 68 | + } else { |
|
| 69 | + throw new \InvalidArgumentException("Invalid feed type."); |
|
| 70 | + } |
|
| 70 | 71 | |
| 71 | 72 | return $this; |
| 72 | 73 | } |
@@ -81,11 +82,12 @@ discard block |
||
| 81 | 82 | public function setTimeout($timeout = self::DEFAULT_TIMEOUT) { |
| 82 | 83 | $feed = $this->options['feed']; |
| 83 | 84 | |
| 84 | - if ($feed == self::CONTINUOUS_TYPE) |
|
| 85 | - if (is_int($timeout) and ($timeout > 0)) |
|
| 85 | + if ($feed == self::CONTINUOUS_TYPE) { |
|
| 86 | + if (is_int($timeout) and ($timeout > 0)) |
|
| 86 | 87 | $this->options["timeout"] = $timeout; |
| 87 | - else |
|
| 88 | - throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 88 | + } else { |
|
| 89 | + throw new \InvalidArgumentException("\$timeout must be a positive integer."); |
|
| 90 | + } |
|
| 89 | 91 | |
| 90 | 92 | return $this; |
| 91 | 93 | } |
@@ -45,8 +45,9 @@ discard block |
||
| 45 | 45 | public function getAttachments() { |
| 46 | 46 | $attachments = []; |
| 47 | 47 | |
| 48 | - foreach ($this->meta[self::ATTACHMENTS] as $attachment) |
|
| 49 | - $attachments[] = Attachment::fromArray($attachment); |
|
| 48 | + foreach ($this->meta[self::ATTACHMENTS] as $attachment) { |
|
| 49 | + $attachments[] = Attachment::fromArray($attachment); |
|
| 50 | + } |
|
| 50 | 51 | |
| 51 | 52 | return $attachments; |
| 52 | 53 | } |
@@ -64,13 +65,15 @@ discard block |
||
| 64 | 65 | * @brief Removes an attachment. |
| 65 | 66 | */ |
| 66 | 67 | public function removeAttachment($name) { |
| 67 | - if ($this->isMetadataPresent(self::ATTACHMENTS)) |
|
| 68 | - if (array_key_exists($name, $this->meta[self::ATTACHMENTS])) |
|
| 68 | + if ($this->isMetadataPresent(self::ATTACHMENTS)) { |
|
| 69 | + if (array_key_exists($name, $this->meta[self::ATTACHMENTS])) |
|
| 69 | 70 | unset($this->meta[self::ATTACHMENTS][$name]); |
| 70 | - else |
|
| 71 | - throw new \Exception("Can't find `$name` attachment in the document."); |
|
| 72 | - else |
|
| 73 | - throw new \Exception("The document doesn't have any attachment."); |
|
| 71 | + } else { |
|
| 72 | + throw new \Exception("Can't find `$name` attachment in the document."); |
|
| 73 | + } |
|
| 74 | + else { |
|
| 75 | + throw new \Exception("The document doesn't have any attachment."); |
|
| 76 | + } |
|
| 74 | 77 | } |
| 75 | 78 | |
| 76 | 79 | |