Completed
Push — master ( b98c31...4a8cfc )
by Filippo
02:46
created
src/EoC/Info/AttachmentInfo.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -45,10 +45,11 @@
 block discarded – undo
45 45
    * @retval string|bool The codec name or `false` if the attachment is not compressed.
46 46
    */
47 47
   public function getContentEncoding() {
48
-    if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF))
49
-      return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF);
50
-    else
51
-      return FALSE;
48
+    if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) {
49
+          return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF);
50
+    } else {
51
+          return FALSE;
52
+    }
52 53
   }
53 54
 
54 55
 
Please login to merge, or discard this patch.
src/EoC/Info/DbInfo.php 1 patch
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@
 block discarded – undo
82 82
       $this->purgeSeq = $info['purge_seq'];
83 83
       $this->compactRunning = $info['compact_running'];
84 84
       $this->committedUpdateSeq = $info['committed_update_seq'];
85
+    } else {
86
+          throw new \Exception("\$info must be an associative array.");
85 87
     }
86
-    else
87
-      throw new \Exception("\$info must be an associative array.");
88 88
   }
89 89
 
90 90
 
Please login to merge, or discard this patch.
src/EoC/Couch.php 1 patch
Braces   +206 added lines, -154 removed lines patch added patch discarded remove patch
@@ -102,10 +102,13 @@  discard block
 block discarded – undo
102 102
       foreach ($keys as $key) {
103 103
         $hash = md5(json_encode($key));
104 104
 
105
-        if (isset($matches[$hash])) // Match found.
105
+        if (isset($matches[$hash])) {
106
+          // Match found.
106 107
           $allRows[] = $matches[$hash];
107
-        else // No match found.
108
+        } else {
109
+          // No match found.
108 110
           $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL];
111
+        }
109 112
       }
110 113
 
111 114
       // Overrides the response, replacing rows.
@@ -176,15 +179,18 @@  discard block
 block discarded – undo
176 179
    * @param[in] bool $excludeLocal Document path.
177 180
    */
178 181
   public function validateDocPath($path, $excludeLocal = FALSE) {
179
-    if (empty($path)) // STD_DOC_PATH
182
+    if (empty($path)) {
183
+      // STD_DOC_PATH
180 184
       return;
185
+    }
181 186
 
182
-    if ($path == self::DESIGN_DOC_PATH)
183
-      return;
184
-    elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal)
185
-      throw new \InvalidArgumentException("Local document doesn't have attachments.");
186
-    else
187
-      throw new \InvalidArgumentException("Invalid document path.");
187
+    if ($path == self::DESIGN_DOC_PATH) {
188
+          return;
189
+    } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) {
190
+          throw new \InvalidArgumentException("Local document doesn't have attachments.");
191
+    } else {
192
+          throw new \InvalidArgumentException("Invalid document path.");
193
+    }
188 194
   }
189 195
 
190 196
 
@@ -206,10 +212,11 @@  discard block
 block discarded – undo
206 212
     #    One of the characters “_$()” «_$()»
207 213
     #    A character in the range between “+” and “/” «+-/»
208 214
     # Assert position at the very end of the string «\z»
209
-    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name))
210
-      return $name = rawurlencode($name);
211
-    else
212
-      throw new \InvalidArgumentException("Invalid database name.");
215
+    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name)) {
216
+          return $name = rawurlencode($name);
217
+    } else {
218
+          throw new \InvalidArgumentException("Invalid database name.");
219
+    }
213 220
   }
214 221
 
215 222
 
@@ -220,10 +227,11 @@  discard block
 block discarded – undo
220 227
    * @param string $docId Document id.
221 228
    */
222 229
   public function validateAndEncodeDocId(&$docId) {
223
-    if (!empty($docId))
224
-      $docId = rawurlencode($docId);
225
-    else
226
-      throw new \InvalidArgumentException("\$docId must be a non-empty string.");
230
+    if (!empty($docId)) {
231
+          $docId = rawurlencode($docId);
232
+    } else {
233
+          throw new \InvalidArgumentException("\$docId must be a non-empty string.");
234
+    }
227 235
   }
228 236
 
229 237
   //!@}
@@ -255,10 +263,10 @@  discard block
 block discarded – undo
255 263
     // before the client has received the entire response. To avoid problems, we trap the exception and we go on.
256 264
     try {
257 265
       $this->send($request);
258
-    }
259
-    catch (\Exception $e) {
260
-      if ($e->getCode() > 0)
261
-        throw $e;
266
+    } catch (\Exception $e) {
267
+      if ($e->getCode() > 0) {
268
+              throw $e;
269
+      }
262 270
     }
263 271
   }
264 272
 
@@ -295,10 +303,11 @@  discard block
 block discarded – undo
295 303
   public function getFavicon() {
296 304
     $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico"));
297 305
 
298
-    if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon")
299
-      return $response->getBody();
300
-    else
301
-      throw new \InvalidArgumentException("Content-Type must be image/x-icon.");
306
+    if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") {
307
+          return $response->getBody();
308
+    } else {
309
+          throw new \InvalidArgumentException("Content-Type must be image/x-icon.");
310
+    }
302 311
   }
303 312
 
304 313
 
@@ -334,8 +343,9 @@  discard block
 block discarded – undo
334 343
 
335 344
     $request = new Request(Request::GET_METHOD, "/_db_updates");
336 345
 
337
-    if (isset($opts))
338
-      $request->setMultipleQueryParamsAtOnce($opts->asArray());
346
+    if (isset($opts)) {
347
+          $request->setMultipleQueryParamsAtOnce($opts->asArray());
348
+    }
339 349
 
340 350
     return $this->send($request)->getBodyAsArray();
341 351
   }
@@ -364,9 +374,9 @@  discard block
 block discarded – undo
364 374
       $request = new Request(Request::GET_METHOD, "/_log");
365 375
       $request->setQueryParam("bytes", $bytes);
366 376
       return $this->send($request)->getBody();
377
+    } else {
378
+          throw new \InvalidArgumentException("\$bytes must be a positive integer.");
367 379
     }
368
-    else
369
-      throw new \InvalidArgumentException("\$bytes must be a positive integer.");
370 380
   }
371 381
 
372 382
 
@@ -383,13 +393,15 @@  discard block
 block discarded – undo
383 393
 
384 394
       $response = $this->send($request);
385 395
 
386
-      if ($count == 1) // We don't need to use === operator because, just above, we made a type checking.
396
+      if ($count == 1) {
397
+        // We don't need to use === operator because, just above, we made a type checking.
387 398
         return $response->getBodyAsArray()['uuids'][0];
388
-      else
389
-        return $response->getBodyAsArray()['uuids'];
399
+      } else {
400
+              return $response->getBodyAsArray()['uuids'];
401
+      }
402
+    } else {
403
+          throw new \InvalidArgumentException("\$count must be a positive integer.");
390 404
     }
391
-    else
392
-      throw new \InvalidArgumentException("\$count must be a positive integer.");
393 405
   }
394 406
 
395 407
   //!@}
@@ -403,8 +415,9 @@  discard block
 block discarded – undo
403 415
   private function endTransaction() {
404 416
     if (is_array($this->transaction)) {
405 417
 
406
-      foreach ($this->transaction as $doc)
407
-        unset($doc);
418
+      foreach ($this->transaction as $doc) {
419
+              unset($doc);
420
+      }
408 421
 
409 422
       unset($this->transaction);
410 423
     }
@@ -416,10 +429,11 @@  discard block
 block discarded – undo
416 429
    * @brief Starts a new transaction.
417 430
    */
418 431
   public function begin() {
419
-    if (is_null($this->transaction))
420
-      $this->transaction = [];
421
-    else
422
-      throw new \RuntimeException("A transaction is already in progress.");
432
+    if (is_null($this->transaction)) {
433
+          $this->transaction = [];
434
+    } else {
435
+          throw new \RuntimeException("A transaction is already in progress.");
436
+    }
423 437
   }
424 438
 
425 439
 
@@ -445,8 +459,7 @@  discard block
 block discarded – undo
445 459
     try {
446 460
       $this->performBulkOperations($this->transaction, $immediately, TRUE, $newEdits);
447 461
       $this->endTransaction();
448
-    }
449
-    catch (\Exception $e) {
462
+    } catch (\Exception $e) {
450 463
       $this->rollback();
451 464
       throw $e;
452 465
     }
@@ -481,8 +494,9 @@  discard block
 block discarded – undo
481 494
     if (!empty($section)) {
482 495
       $path .= "/".$section;
483 496
 
484
-      if (!empty($key))
485
-        $path .= "/".$key;
497
+      if (!empty($key)) {
498
+              $path .= "/".$key;
499
+      }
486 500
     }
487 501
 
488 502
     return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray();
@@ -497,14 +511,17 @@  discard block
 block discarded – undo
497 511
    * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key
498 512
    */
499 513
   public function setConfigKey($section, $key, $value) {
500
-    if (!is_string($section) or empty($section))
501
-      throw new \InvalidArgumentException("\$section must be a not empty string.");
514
+    if (!is_string($section) or empty($section)) {
515
+          throw new \InvalidArgumentException("\$section must be a not empty string.");
516
+    }
502 517
 
503
-    if (!is_string($key) or empty($key))
504
-      throw new \InvalidArgumentException("\$key must be a not empty string.");
518
+    if (!is_string($key) or empty($key)) {
519
+          throw new \InvalidArgumentException("\$key must be a not empty string.");
520
+    }
505 521
 
506
-    if (is_null($value))
507
-      throw new \InvalidArgumentException("\$value cannot be null.");
522
+    if (is_null($value)) {
523
+          throw new \InvalidArgumentException("\$value cannot be null.");
524
+    }
508 525
 
509 526
     $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key);
510 527
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
@@ -520,11 +537,13 @@  discard block
 block discarded – undo
520 537
    * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key
521 538
    */
522 539
   public function deleteConfigKey($section, $key) {
523
-    if (!is_string($section) or empty($section))
524
-      throw new \InvalidArgumentException("\$section must be a not empty string.");
540
+    if (!is_string($section) or empty($section)) {
541
+          throw new \InvalidArgumentException("\$section must be a not empty string.");
542
+    }
525 543
 
526
-    if (!is_string($key) or empty($key))
527
-      throw new \InvalidArgumentException("\$key must be a not empty string.");
544
+    if (!is_string($key) or empty($key)) {
545
+          throw new \InvalidArgumentException("\$key must be a not empty string.");
546
+    }
528 547
 
529 548
     $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key));
530 549
   }
@@ -551,11 +570,13 @@  discard block
 block discarded – undo
551 570
    * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session
552 571
    */
553 572
   public function setSession($userName, $password) {
554
-    if (!is_string($userName) or empty($userName))
555
-      throw new \InvalidArgumentException("\$userName must be a not empty string.");
573
+    if (!is_string($userName) or empty($userName)) {
574
+          throw new \InvalidArgumentException("\$userName must be a not empty string.");
575
+    }
556 576
 
557
-    if (!is_string($password) or empty($password))
558
-      throw new \InvalidArgumentException("\$password must be a not empty string.");
577
+    if (!is_string($password) or empty($password)) {
578
+          throw new \InvalidArgumentException("\$password must be a not empty string.");
579
+    }
559 580
 
560 581
     $request = new Request(Request::POST_METHOD, "/_session");
561 582
 
@@ -650,8 +671,9 @@  discard block
 block discarded – undo
650 671
    * you are making a not supported call to CouchDB.
651 672
    */
652 673
   public function checkForDb() {
653
-    if (empty($this->dbName))
654
-      throw new \RuntimeException("No database selected.");
674
+    if (empty($this->dbName)) {
675
+          throw new \RuntimeException("No database selected.");
676
+    }
655 677
   }
656 678
 
657 679
 
@@ -669,11 +691,12 @@  discard block
 block discarded – undo
669 691
     if ($name != $this->dbName) {
670 692
       $this->send(new Request(Request::PUT_METHOD, "/".$name."/"));
671 693
 
672
-      if ($autoSelect)
673
-        $this->dbName = $name;
694
+      if ($autoSelect) {
695
+              $this->dbName = $name;
696
+      }
697
+    } else {
698
+          throw new \UnexpectedValueException("You can't create a database with the same name of the selected database.");
674 699
     }
675
-    else
676
-      throw new \UnexpectedValueException("You can't create a database with the same name of the selected database.");
677 700
   }
678 701
 
679 702
 
@@ -687,10 +710,11 @@  discard block
 block discarded – undo
687 710
   public function deleteDb($name) {
688 711
     $this->validateAndEncodeDbName($name);
689 712
 
690
-    if ($name != $this->dbName)
691
-      $this->send(new Request(Request::DELETE_METHOD, "/".$name));
692
-    else
693
-      throw new \UnexpectedValueException("You can't delete the selected database.");
713
+    if ($name != $this->dbName) {
714
+          $this->send(new Request(Request::DELETE_METHOD, "/".$name));
715
+    } else {
716
+          throw new \UnexpectedValueException("You can't delete the selected database.");
717
+    }
694 718
   }
695 719
 
696 720
 
@@ -718,8 +742,9 @@  discard block
 block discarded – undo
718 742
 
719 743
     $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_changes");
720 744
 
721
-    if (isset($opts))
722
-      $request->setMultipleQueryParamsAtOnce($opts->asArray());
745
+    if (isset($opts)) {
746
+          $request->setMultipleQueryParamsAtOnce($opts->asArray());
747
+    }
723 748
 
724 749
     return $this->send($request);
725 750
   }
@@ -914,40 +939,47 @@  discard block
 block discarded – undo
914 939
       is_string($targetDbUrl) && !empty($targetDbUrl)) {
915 940
       $body["source"] = $sourceDbUrl;
916 941
       $body["target"] = $targetDbUrl;
942
+    } else {
943
+          throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings.");
917 944
     }
918
-    else
919
-      throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings.");
920 945
 
921
-    if (!is_bool($continuous))
922
-      throw new \InvalidArgumentException("\$continuous must be a bool.");
923
-    elseif ($continuous)
924
-      $body["continuous"] = $continuous;
946
+    if (!is_bool($continuous)) {
947
+          throw new \InvalidArgumentException("\$continuous must be a bool.");
948
+    } elseif ($continuous) {
949
+          $body["continuous"] = $continuous;
950
+    }
925 951
 
926 952
     // Uses the specified proxy if any set.
927
-    if (isset($proxy))
928
-      $body["proxy"] = $this->proxy;
953
+    if (isset($proxy)) {
954
+          $body["proxy"] = $this->proxy;
955
+    }
929 956
 
930 957
     // create_target option
931
-    if (!is_bool($createTargetDb))
932
-      throw new \InvalidArgumentException("\$createTargetDb must be a bool.");
933
-    elseif ($createTargetDb)
934
-      $body["create_target"] = $createTargetDb;
958
+    if (!is_bool($createTargetDb)) {
959
+          throw new \InvalidArgumentException("\$createTargetDb must be a bool.");
960
+    } elseif ($createTargetDb) {
961
+          $body["create_target"] = $createTargetDb;
962
+    }
935 963
 
936 964
     if (!empty($filter)) {
937
-      if (is_string($filter)) // filter option
965
+      if (is_string($filter)) {
966
+        // filter option
938 967
         $body["filter"] = $filter;
939
-      elseif (is_array($filter)) // doc_ids option
968
+      } elseif (is_array($filter)) {
969
+        // doc_ids option
940 970
         $body["doc_ids"] = array_values($filter);
941
-      else
942
-        throw new \InvalidArgumentException("\$filter must be a string or an array.");
971
+      } else {
972
+              throw new \InvalidArgumentException("\$filter must be a string or an array.");
973
+      }
943 974
     }
944 975
 
945 976
     // queryParams option
946 977
     if (!is_null($opts)) {
947
-      if ($opts instanceof Opt\ViewQueryOpts)
948
-        $body["query_params"] = get_object_vars($opts);
949
-      else
950
-        throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class.");
978
+      if ($opts instanceof Opt\ViewQueryOpts) {
979
+              $body["query_params"] = get_object_vars($opts);
980
+      } else {
981
+              throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class.");
982
+      }
951 983
     }
952 984
 
953 985
     return $this->send(Request::POST_METHOD, "/_replicate", NULL, NULL, $body);
@@ -961,8 +993,9 @@  discard block
 block discarded – undo
961 993
    * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication
962 994
    */
963 995
   public function stopReplication($replicationId) {
964
-    if (is_null($replicationId))
965
-      throw new \InvalidArgumentException("You must provide a replication id.");
996
+    if (is_null($replicationId)) {
997
+          throw new \InvalidArgumentException("You must provide a replication id.");
998
+    }
966 999
 
967 1000
     $body["replication_id"] = $replicationId;
968 1001
     $body["cancel"] = TRUE;
@@ -1008,15 +1041,16 @@  discard block
 block discarded – undo
1008 1041
   public function queryAllDocs(array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) {
1009 1042
     $this->checkForDb();
1010 1043
 
1011
-    if (is_null($keys))
1012
-      $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs");
1013
-    else {
1044
+    if (is_null($keys)) {
1045
+          $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs");
1046
+    } else {
1014 1047
       $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_all_docs");
1015 1048
       $request->setBody(json_encode(['keys' => $keys]));
1016 1049
     }
1017 1050
 
1018
-    if (isset($opts))
1019
-      $request->setMultipleQueryParamsAtOnce($opts->asArray());
1051
+    if (isset($opts)) {
1052
+          $request->setMultipleQueryParamsAtOnce($opts->asArray());
1053
+    }
1020 1054
 
1021 1055
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1022 1056
 
@@ -1045,12 +1079,13 @@  discard block
 block discarded – undo
1045 1079
     $this->checkForDb();
1046 1080
     $this->validateAndEncodeDocId($designDocName);
1047 1081
 
1048
-    if (empty($viewName))
1049
-      throw new \InvalidArgumentException("You must provide a valid \$viewName.");
1082
+    if (empty($viewName)) {
1083
+          throw new \InvalidArgumentException("You must provide a valid \$viewName.");
1084
+    }
1050 1085
 
1051
-    if (empty($keys))
1052
-      $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1053
-    else {
1086
+    if (empty($keys)) {
1087
+          $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1088
+    } else {
1054 1089
       $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1055 1090
       $request->setBody(json_encode(['keys' => $keys]));
1056 1091
     }
@@ -1058,14 +1093,15 @@  discard block
 block discarded – undo
1058 1093
     if (isset($opts)) {
1059 1094
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1060 1095
       $includeMissingKeys = $opts->issetIncludeMissingKeys();
1096
+    } else {
1097
+          $includeMissingKeys = FALSE;
1061 1098
     }
1062
-    else
1063
-      $includeMissingKeys = FALSE;
1064 1099
 
1065 1100
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1066 1101
 
1067
-    if ($includeMissingKeys)
1068
-      $this->addMissingRows($keys, $result['rows']);
1102
+    if ($includeMissingKeys) {
1103
+          $this->addMissingRows($keys, $result['rows']);
1104
+    }
1069 1105
 
1070 1106
     return new Result\QueryResult($result);
1071 1107
   }
@@ -1093,30 +1129,33 @@  discard block
 block discarded – undo
1093 1129
     $handler = new Handler\ViewHandler('temp');
1094 1130
     $handler->language = $language;
1095 1131
     $handler->mapFn = $mapFn;
1096
-    if (!empty($reduce))
1097
-      $handler->reduceFn = $reduceFn;
1132
+    if (!empty($reduce)) {
1133
+          $handler->reduceFn = $reduceFn;
1134
+    }
1098 1135
 
1099 1136
     $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_temp_view");
1100 1137
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
1101 1138
 
1102 1139
     $array = $handler->asArray();
1103 1140
 
1104
-    if (!empty($keys))
1105
-      $array['keys'] = $keys;
1141
+    if (!empty($keys)) {
1142
+          $array['keys'] = $keys;
1143
+    }
1106 1144
 
1107 1145
     $request->setBody(json_encode($array));
1108 1146
 
1109 1147
     if (isset($opts)) {
1110 1148
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1111 1149
       $includeMissingKeys = $opts->issetIncludeMissingKeys();
1150
+    } else {
1151
+          $includeMissingKeys = FALSE;
1112 1152
     }
1113
-    else
1114
-      $includeMissingKeys = FALSE;
1115 1153
 
1116 1154
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1117 1155
 
1118
-    if ($includeMissingKeys)
1119
-      $this->addMissingRows($keys, $result['rows']);
1156
+    if ($includeMissingKeys) {
1157
+          $this->addMissingRows($keys, $result['rows']);
1158
+    }
1120 1159
 
1121 1160
     return new Result\QueryResult($result);
1122 1161
   }
@@ -1179,8 +1218,9 @@  discard block
 block discarded – undo
1179 1218
   public function setRevsLimit($revsLimit = self::REVS_LIMIT) {
1180 1219
     $this->checkForDb();
1181 1220
 
1182
-    if (!is_int($revsLimit) or ($revsLimit <= 0))
1183
-      throw new \InvalidArgumentException("\$revsLimit must be a positive integer.");
1221
+    if (!is_int($revsLimit) or ($revsLimit <= 0)) {
1222
+          throw new \InvalidArgumentException("\$revsLimit must be a positive integer.");
1223
+    }
1184 1224
 
1185 1225
     $request = new Request(Request::PUT_METHOD, "/".$this->dbName."/_revs_limit");
1186 1226
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
@@ -1238,16 +1278,17 @@  discard block
 block discarded – undo
1238 1278
     $request = new Request(Request::GET_METHOD, $requestPath);
1239 1279
 
1240 1280
     // Retrieves the specific revision of the document.
1241
-    if (!empty($rev))
1242
-      $request->setQueryParam("rev", (string)$rev);
1281
+    if (!empty($rev)) {
1282
+          $request->setQueryParam("rev", (string)$rev);
1283
+    }
1243 1284
 
1244 1285
     // If there are any options, add them to the request.
1245 1286
     if (isset($opts)) {
1246 1287
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1247 1288
       $ignoreClass = $opts->issetIgnoreClass();
1289
+    } else {
1290
+          $ignoreClass = FALSE;
1248 1291
     }
1249
-    else
1250
-      $ignoreClass = FALSE;
1251 1292
 
1252 1293
     $response = $this->send($request);
1253 1294
     $body = $response->getBodyAsArray();
@@ -1259,18 +1300,18 @@  discard block
 block discarded – undo
1259 1300
     if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc.
1260 1301
       $class = "\\".$body['class'];
1261 1302
       $doc = new $class;
1303
+    } elseif ($path == self::DESIGN_DOC_PATH) {
1304
+          $doc = new Doc\DesignDoc;
1305
+    } else {
1306
+          $doc = NULL;
1262 1307
     }
1263
-    elseif ($path == self::DESIGN_DOC_PATH)
1264
-      $doc = new Doc\DesignDoc;
1265
-    else
1266
-      $doc = NULL;
1267 1308
 
1268 1309
     if (is_object($doc)) {
1269 1310
       $doc->assignArray($body);
1270 1311
       return $doc;
1312
+    } else {
1313
+          return $response;
1271 1314
     }
1272
-    else
1273
-      return $response;
1274 1315
   }
1275 1316
 
1276 1317
 
@@ -1297,8 +1338,9 @@  discard block
 block discarded – undo
1297 1338
 
1298 1339
     // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc
1299 1340
     // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids.
1300
-    if (!$doc->issetId())
1301
-      $doc->setid(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));
1341
+    if (!$doc->issetId()) {
1342
+          $doc->setid(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));
1343
+    }
1302 1344
 
1303 1345
     $this->setDocInfo($doc);
1304 1346
 
@@ -1312,8 +1354,9 @@  discard block
 block discarded – undo
1312 1354
     $request->setBody($doc->asJson());
1313 1355
 
1314 1356
     // Enables batch mode.
1315
-    if ($batchMode)
1316
-      $request->setQueryParam("batch", "ok");
1357
+    if ($batchMode) {
1358
+          $request->setQueryParam("batch", "ok");
1359
+    }
1317 1360
 
1318 1361
     $this->send($request);
1319 1362
   }
@@ -1366,10 +1409,11 @@  discard block
 block discarded – undo
1366 1409
     // This request uses the special method COPY.
1367 1410
     $request = new Request(Request::COPY_METHOD, $path);
1368 1411
 
1369
-    if (empty($rev))
1370
-      $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);
1371
-    else
1372
-      $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);
1412
+    if (empty($rev)) {
1413
+          $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);
1414
+    } else {
1415
+          $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);
1416
+    }
1373 1417
 
1374 1418
     $this->send($request);
1375 1419
   }
@@ -1399,8 +1443,9 @@  discard block
 block discarded – undo
1399 1443
     $request = new Request(Request::POST_METHOD, $path);
1400 1444
 
1401 1445
     $purge = [];
1402
-    foreach ($refs as $ref)
1403
-      $purge[] = $ref->asArray();
1446
+    foreach ($refs as $ref) {
1447
+          $purge[] = $ref->asArray();
1448
+    }
1404 1449
 
1405 1450
     $request->setBody(json_encode($purge));
1406 1451
 
@@ -1433,26 +1478,30 @@  discard block
 block discarded – undo
1433 1478
   public function performBulkOperations(array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) {
1434 1479
     $this->checkForDb();
1435 1480
 
1436
-    if (count($docs) == 0)
1437
-      throw new \InvalidArgumentException("The \$docs array cannot be empty.");
1438
-    else
1439
-      $operations = [];
1481
+    if (count($docs) == 0) {
1482
+          throw new \InvalidArgumentException("The \$docs array cannot be empty.");
1483
+    } else {
1484
+          $operations = [];
1485
+    }
1440 1486
 
1441 1487
     $path = "/".$this->dbName."/_bulk_docs";
1442 1488
 
1443 1489
     $request = new Request(Request::POST_METHOD, $path);
1444 1490
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
1445 1491
 
1446
-    if ($fullCommit)
1447
-      $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");
1448
-    else
1449
-      $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");
1492
+    if ($fullCommit) {
1493
+          $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");
1494
+    } else {
1495
+          $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");
1496
+    }
1450 1497
 
1451
-    if ($allOrNothing)
1452
-      $operations['all_or_nothing'] = 'true';
1498
+    if ($allOrNothing) {
1499
+          $operations['all_or_nothing'] = 'true';
1500
+    }
1453 1501
 
1454
-    if (!$newEdits)
1455
-      $operations['new_edits'] = 'false';
1502
+    if (!$newEdits) {
1503
+          $operations['new_edits'] = 'false';
1504
+    }
1456 1505
 
1457 1506
     foreach ($docs as $doc) {
1458 1507
       $this->setDocInfo($doc);
@@ -1490,8 +1539,9 @@  discard block
 block discarded – undo
1490 1539
     $request = new Request(Request::HEAD_METHOD, $path);
1491 1540
 
1492 1541
     // In case we want retrieve a specific document revision.
1493
-    if (!empty($rev))
1494
-      $request->setQueryParam("rev", (string)$rev);
1542
+    if (!empty($rev)) {
1543
+          $request->setQueryParam("rev", (string)$rev);
1544
+    }
1495 1545
 
1496 1546
     return $this->send($request);
1497 1547
   }
@@ -1517,8 +1567,9 @@  discard block
 block discarded – undo
1517 1567
     $request = new Request(Request::GET_METHOD, $path);
1518 1568
 
1519 1569
     // In case we want retrieve a specific document revision.
1520
-    if (!empty($rev))
1521
-      $request->setQueryParam("rev", (string)$rev);
1570
+    if (!empty($rev)) {
1571
+          $request->setQueryParam("rev", (string)$rev);
1572
+    }
1522 1573
 
1523 1574
     return $this->send($request)->getBody();
1524 1575
   }
@@ -1547,8 +1598,9 @@  discard block
 block discarded – undo
1547 1598
     $request->setBody(base64_encode($attachment->getData()));
1548 1599
 
1549 1600
     // In case of adding or updating an existence document.
1550
-    if (!empty($rev))
1551
-      $request->setQueryParam("rev", (string)$rev);
1601
+    if (!empty($rev)) {
1602
+          $request->setQueryParam("rev", (string)$rev);
1603
+    }
1552 1604
 
1553 1605
     return $this->send($request);
1554 1606
   }
Please login to merge, or discard this patch.
src/EoC/Doc/LocalDoc.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,8 +25,9 @@
 block discarded – undo
25 25
    * @brief Removes `_local/` from he document identifier.
26 26
    */
27 27
   protected function fixDocId() {
28
-    if (isset($this->meta['_id']))
29
-      $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']);
28
+    if (isset($this->meta['_id'])) {
29
+          $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']);
30
+    }
30 31
   }
31 32
 
32 33
 
Please login to merge, or discard this patch.
src/EoC/Doc/DesignDoc.php 1 patch
Braces   +55 added lines, -46 removed lines patch added patch discarded remove patch
@@ -63,8 +63,9 @@  discard block
 block discarded – undo
63 63
    * @brief Removes `_design/` from he document identifier.
64 64
    */
65 65
   protected function fixDocId() {
66
-    if (isset($this->meta['_id']))
67
-      $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']);
66
+    if (isset($this->meta['_id'])) {
67
+          $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']);
68
+    }
68 69
   }
69 70
 
70 71
 
@@ -94,8 +95,9 @@  discard block
 block discarded – undo
94 95
    */
95 96
   public function resetHandlers() {
96 97
     foreach ($this->sections as $name => $value) {
97
-      if (array_key_exists($name, $this->meta))
98
-        unset($this->meta[$name]);
98
+      if (array_key_exists($name, $this->meta)) {
99
+              unset($this->meta[$name]);
100
+      }
99 101
     }
100 102
   }
101 103
 
@@ -108,16 +110,17 @@  discard block
 block discarded – undo
108 110
    */
109 111
   public function getHandlerAttributes($section, $name = "") {
110 112
     if (empty($name)) { // The handler doesn't have a name.
111
-      if (array_key_exists($section, $this->meta))
112
-        return $this->meta[$section];
113
-      else
114
-        throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section));
115
-    }
116
-    else { // The handler has a name.
117
-      if (@array_key_exists($name, $this->meta[$section]))
118
-        return $this->meta[$section][$name];
119
-      else
120
-        throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section));
113
+      if (array_key_exists($section, $this->meta)) {
114
+              return $this->meta[$section];
115
+      } else {
116
+              throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section));
117
+      }
118
+    } else { // The handler has a name.
119
+      if (@array_key_exists($name, $this->meta[$section])) {
120
+              return $this->meta[$section][$name];
121
+      } else {
122
+              throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section));
123
+      }
121 124
     }
122 125
   }
123 126
 
@@ -133,22 +136,25 @@  discard block
 block discarded – undo
133 136
     $section = $handler->getSection();
134 137
 
135 138
     if (property_exists($handler, "name")) {
136
-      if (!$handler->isConsistent())
137
-        throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name));
138
-
139
-      if (@array_key_exists($handler->name, $this->meta[$section]))
140
-        throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name));
141
-      else
142
-        $this->meta[$section][$handler->name] = $handler->asArray();
143
-    }
144
-    else {
145
-      if (!$handler->isConsistent())
146
-        throw new \Exception(sprintf("The '%s' handler is not consistent.", $section));
147
-
148
-      if (array_key_exists($section, $this->meta))
149
-        throw new \Exception(sprintf("The '%s' handler already exists.", $section));
150
-      else
151
-        $this->meta[$section] = $handler;
139
+      if (!$handler->isConsistent()) {
140
+              throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name));
141
+      }
142
+
143
+      if (@array_key_exists($handler->name, $this->meta[$section])) {
144
+              throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name));
145
+      } else {
146
+              $this->meta[$section][$handler->name] = $handler->asArray();
147
+      }
148
+    } else {
149
+      if (!$handler->isConsistent()) {
150
+              throw new \Exception(sprintf("The '%s' handler is not consistent.", $section));
151
+      }
152
+
153
+      if (array_key_exists($section, $this->meta)) {
154
+              throw new \Exception(sprintf("The '%s' handler already exists.", $section));
155
+      } else {
156
+              $this->meta[$section] = $handler;
157
+      }
152 158
     }
153 159
   }
154 160
 
@@ -163,16 +169,17 @@  discard block
 block discarded – undo
163 169
    */
164 170
   public function removeHandler($section, $name = "") {
165 171
     if (empty($name)) { // The handler doesn't have a name.
166
-      if (array_key_exists($section, $this->meta))
167
-        unset($this->meta[$section]);
168
-      else
169
-        throw new \Exception(sprintf("Can't find the '%s' handler.", $section));
170
-    }
171
-    else { // The handler has a name.
172
-      if (@array_key_exists($name, $this->meta[$section]))
173
-        unset($this->meta[$section][$name]);
174
-      else
175
-        throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name));
172
+      if (array_key_exists($section, $this->meta)) {
173
+              unset($this->meta[$section]);
174
+      } else {
175
+              throw new \Exception(sprintf("Can't find the '%s' handler.", $section));
176
+      }
177
+    } else { // The handler has a name.
178
+      if (@array_key_exists($name, $this->meta[$section])) {
179
+              unset($this->meta[$section][$name]);
180
+      } else {
181
+              throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name));
182
+      }
176 183
     }
177 184
   }
178 185
 
@@ -190,16 +197,18 @@  discard block
 block discarded – undo
190 197
 
191 198
 
192 199
   public function setLanguage($value) {
193
-    if (!empty($value))
194
-      $this->meta['language'] = strtolower((string)$value);
195
-    else
196
-      throw new \InvalidArgumentException("\$language must be a non-empty string.");
200
+    if (!empty($value)) {
201
+          $this->meta['language'] = strtolower((string)$value);
202
+    } else {
203
+          throw new \InvalidArgumentException("\$language must be a non-empty string.");
204
+    }
197 205
   }
198 206
 
199 207
 
200 208
   public function unsetLanguage() {
201
-    if ($this->isMetadataPresent('language'))
202
-      unset($this->meta['language']);
209
+    if ($this->isMetadataPresent('language')) {
210
+          unset($this->meta['language']);
211
+    }
203 212
   }
204 213
 
205 214
   //! @endcond
Please login to merge, or discard this patch.
src/EoC/Doc/DocRef.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,10 +59,11 @@
 block discarded – undo
59 59
 
60 60
 
61 61
   public function setId($value) {
62
-    if (!empty($value))
63
-      $this->id = (string)$value;
64
-    else
65
-      throw new \Exception("\$id must be a non-empty string.");
62
+    if (!empty($value)) {
63
+          $this->id = (string)$value;
64
+    } else {
65
+          throw new \Exception("\$id must be a non-empty string.");
66
+    }
66 67
   }
67 68
 
68 69
 
Please login to merge, or discard this patch.
src/EoC/Doc/Attachment/Attachment.php 1 patch
Braces   +15 added lines, -12 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
     $instance = new self();
42 42
 
43 43
     if (file_exists($fileName)) {
44
-      if (is_dir($fileName))
45
-        throw new \Exception("The file $fileName is a directory.");
44
+      if (is_dir($fileName)) {
45
+              throw new \Exception("The file $fileName is a directory.");
46
+      }
46 47
 
47 48
       $instance->name = basename($fileName);
48 49
 
@@ -58,14 +59,15 @@  discard block
 block discarded – undo
58 59
         finfo_close($finfo);
59 60
         fclose($fd);
60 61
 
61
-        if ($instance->data === FALSE)
62
-          throw new \Exception("Error reading the file $fileName.");
62
+        if ($instance->data === FALSE) {
63
+                  throw new \Exception("Error reading the file $fileName.");
64
+        }
65
+      } else {
66
+              throw new \Exception("Cannot open the file $fileName.");
63 67
       }
64
-      else
65
-        throw new \Exception("Cannot open the file $fileName.");
68
+    } else {
69
+          throw new \Exception("The file $fileName doesn't exist.");
66 70
     }
67
-    else
68
-      throw new \Exception("The file $fileName doesn't exist.");
69 71
 
70 72
     return $instance;
71 73
   }
@@ -101,11 +103,12 @@  discard block
 block discarded – undo
101 103
       $bytes = fwrite($fd, $this->data);
102 104
       fclose($fd);
103 105
 
104
-      if ($bytes === FALSE)
105
-        throw new \Exception("Error writing the file `$this->name`.");
106
+      if ($bytes === FALSE) {
107
+              throw new \Exception("Error writing the file `$this->name`.");
108
+      }
109
+    } else {
110
+          throw new \Exception("Cannot create the file `$this->name`.");
106 111
     }
107
-    else
108
-      throw new \Exception("Cannot create the file `$this->name`.");
109 112
   }
110 113
 
111 114
 
Please login to merge, or discard this patch.
src/EoC/Doc/Doc.php 1 patch
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -54,8 +54,9 @@  discard block
 block discarded – undo
54 54
   public function getAttachments() {
55 55
     $attachments = [];
56 56
 
57
-    foreach ($this->meta[self::ATTACHMENTS] as $attachment)
58
-      $attachments[] = Attachment::fromArray($attachment);
57
+    foreach ($this->meta[self::ATTACHMENTS] as $attachment) {
58
+          $attachments[] = Attachment::fromArray($attachment);
59
+    }
59 60
 
60 61
     return $attachments;
61 62
   }
@@ -75,13 +76,15 @@  discard block
 block discarded – undo
75 76
    * @todo To be documented.
76 77
    */
77 78
   public function removeAttachment($name) {
78
-    if ($this->isMetadataPresent(self::ATTACHMENTS))
79
-      if (array_key_exists($name, $this->meta[self::ATTACHMENTS]))
79
+    if ($this->isMetadataPresent(self::ATTACHMENTS)) {
80
+          if (array_key_exists($name, $this->meta[self::ATTACHMENTS]))
80 81
         unset($this->meta[self::ATTACHMENTS][$name]);
81
-      else
82
-        throw new \Exception("Can't find `$name` attachment in the document.");
83
-    else
84
-      throw new \Exception("The document doesn't have any attachment.");
82
+    } else {
83
+              throw new \Exception("Can't find `$name` attachment in the document.");
84
+      }
85
+    else {
86
+          throw new \Exception("The document doesn't have any attachment.");
87
+    }
85 88
   }
86 89
 
87 90
 
Please login to merge, or discard this patch.
src/EoC/Doc/TDoc.php 1 patch
Braces   +17 added lines, -12 removed lines patch added patch discarded remove patch
@@ -48,19 +48,22 @@  discard block
 block discarded – undo
48 48
 
49 49
 
50 50
   public function setMetadata($name, $value, $override = TRUE, $allowNull = TRUE) {
51
-    if (is_null($value) && !$allowNull)
52
-      return;
51
+    if (is_null($value) && !$allowNull) {
52
+          return;
53
+    }
53 54
 
54
-    if ($this->isMetadataPresent($name) && !$override)
55
-      return;
55
+    if ($this->isMetadataPresent($name) && !$override) {
56
+          return;
57
+    }
56 58
 
57 59
     $this->meta[$name] = $value;
58 60
   }
59 61
 
60 62
 
61 63
   public function unsetMetadata($name) {
62
-    if (array_key_exists($name, $this->meta))
63
-      unset($this->meta[$name]);
64
+    if (array_key_exists($name, $this->meta)) {
65
+          unset($this->meta[$name]);
66
+    }
64 67
   }
65 68
 
66 69
 
@@ -94,9 +97,9 @@  discard block
 block discarded – undo
94 97
     if (Helper\ArrayHelper::isAssociative($array)) {
95 98
       $this->meta = array_merge($this->meta, $array);
96 99
       $this->fixDocId();
100
+    } else {
101
+          throw new \InvalidArgumentException("\$array must be an associative array.");
97 102
     }
98
-    else
99
-      throw new \InvalidArgumentException("\$array must be an associative array.");
100 103
   }
101 104
 
102 105
 
@@ -147,8 +150,9 @@  discard block
 block discarded – undo
147 150
 
148 151
 
149 152
   public function unsetId() {
150
-    if ($this->isMetadataPresent('_id'))
151
-      unset($this->meta['_id']);
153
+    if ($this->isMetadataPresent('_id')) {
154
+          unset($this->meta['_id']);
155
+    }
152 156
   }
153 157
 
154 158
 
@@ -168,8 +172,9 @@  discard block
 block discarded – undo
168 172
 
169 173
 
170 174
   public function unsetRev() {
171
-    if ($this->isMetadataPresent('_rev'))
172
-      unset($this->meta['_rev']);
175
+    if ($this->isMetadataPresent('_rev')) {
176
+          unset($this->meta['_rev']);
177
+    }
173 178
   }
174 179
 
175 180
 }
176 181
\ No newline at end of file
Please login to merge, or discard this patch.