Completed
Push — master ( 00f539...b9f44a )
by Filippo
11:40 queued 08:31
created
src/EoC/Doc/DesignDoc.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -189,6 +189,9 @@
 block discarded – undo
189 189
   }
190 190
 
191 191
 
192
+  /**
193
+   * @param string $value
194
+   */
192 195
   public function setLanguage($value) {
193 196
     if (!empty($value))
194 197
       $this->meta['language'] = strtolower((string)$value);
Please login to merge, or discard this 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/Generator/UUID.php 3 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -162,6 +162,11 @@  discard block
 block discarded – undo
162 162
   /*
163 163
    * Public API, convert a UUID from one format to another
164 164
    */
165
+
166
+  /**
167
+   * @param integer $from
168
+   * @param integer $to
169
+   */
165 170
   static public function convert($uuid, $from, $to) {
166 171
     $conv = self::$m_convert[$from][$to];
167 172
     if (!isset($conv))
@@ -189,6 +194,11 @@  discard block
 block discarded – undo
189 194
   /*
190 195
    * Generate UUID version 3 and 5 (name based)
191 196
    */
197
+
198
+  /**
199
+   * @param string $hash
200
+   * @param integer $version
201
+   */
192 202
   static private function generateName($ns, $node, $hash, $version) {
193 203
     $ns_fmt = self::detectFormat($ns);
194 204
     $field = self::convert($ns, $ns_fmt, self::FMT_FIELD);
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -67,29 +67,29 @@  discard block
 block discarded – undo
67 67
  */
68 68
 class UUID {
69 69
   /* UUID versions */
70
-  const UUID_TIME	 = 1;	/* Time based UUID */
71
-  const UUID_NAME_MD5	 = 3;	/* Name based (MD5) UUID */
72
-  const UUID_RANDOM	 = 4;	/* Random UUID */
73
-  const UUID_NAME_SHA1	 = 5;	/* Name based (SHA1) UUID */
70
+  const UUID_TIME = 1; /* Time based UUID */
71
+  const UUID_NAME_MD5 = 3; /* Name based (MD5) UUID */
72
+  const UUID_RANDOM = 4; /* Random UUID */
73
+  const UUID_NAME_SHA1 = 5; /* Name based (SHA1) UUID */
74 74
 
75 75
   /* UUID formats */
76 76
   const FMT_FIELD	 = 100;
77 77
   const FMT_STRING	 = 101;
78 78
   const FMT_BINARY	 = 102;
79
-  const FMT_QWORD	 = 1;	/* Quad-word, 128-bit (not impl.) */
80
-  const FMT_DWORD	 = 2;	/* Double-word, 64-bit (not impl.) */
81
-  const FMT_WORD		 = 4;	/* Word, 32-bit (not impl.) */
82
-  const FMT_SHORT		= 8;	/* Short (not impl.) */
83
-  const FMT_BYTE		= 16;	/* Byte */
84
-  const FMT_DEFAULT	 = 16;
79
+  const FMT_QWORD	 = 1; /* Quad-word, 128-bit (not impl.) */
80
+  const FMT_DWORD	 = 2; /* Double-word, 64-bit (not impl.) */
81
+  const FMT_WORD		 = 4; /* Word, 32-bit (not impl.) */
82
+  const FMT_SHORT		= 8; /* Short (not impl.) */
83
+  const FMT_BYTE = 16; /* Byte */
84
+  const FMT_DEFAULT = 16;
85 85
 
86 86
   /* Field UUID representation */
87 87
   static private $m_uuid_field = array(
88
-    'time_low' => 0,		/* 32-bit */
89
-    'time_mid' => 0,		/* 16-bit */
90
-    'time_hi' => 0,			/* 16-bit */
91
-    'clock_seq_hi' => 0,		/*  8-bit */
92
-    'clock_seq_low' => 0,		/*  8-bit */
88
+    'time_low' => 0, /* 32-bit */
89
+    'time_mid' => 0, /* 16-bit */
90
+    'time_hi' => 0, /* 16-bit */
91
+    'clock_seq_hi' => 0, /*  8-bit */
92
+    'clock_seq_low' => 0, /*  8-bit */
93 93
     'node' => array()		/* 48-bit */
94 94
   );
95 95
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
     $uuid[9] = $src['clock_seq_low'];
285 285
 
286 286
     for ($i = 0; $i < 6; $i++)
287
-      $uuid[10+$i] = $src['node'][$i];
287
+      $uuid[10 + $i] = $src['node'][$i];
288 288
 
289 289
     return ($uuid);
290 290
   }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
     $field['clock_seq_low'] = $uuid[9];
315 315
 
316 316
     for ($i = 0; $i < 6; $i++)
317
-      $field['node'][$i] = $uuid[10+$i];
317
+      $field['node'][$i] = $uuid[10 + $i];
318 318
     return ($field);
319 319
   }
320 320
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8;
340 340
     $field['clock_seq_low'] = $parts[3] & 0x00ff;
341 341
     for ($i = 0; $i < 6; $i++)
342
-      $field['node'][$i] = $parts[4+$i];
342
+      $field['node'][$i] = $parts[4 + $i];
343 343
 
344 344
     return ($field);
345 345
   }
Please login to merge, or discard this patch.
Braces   +34 added lines, -25 removed lines patch added patch discarded remove patch
@@ -131,17 +131,18 @@  discard block
 block discarded – undo
131 131
 
132 132
   /* Auto-detect UUID format */
133 133
   static private function detectFormat($src) {
134
-    if (is_string($src))
135
-      return self::FMT_STRING;
136
-    else if (is_array($src)) {
134
+    if (is_string($src)) {
135
+          return self::FMT_STRING;
136
+    } else if (is_array($src)) {
137 137
       $len = count($src);
138
-      if ($len == 1 || ($len % 2) == 0)
139
-        return $len;
140
-      else
141
-        return (-1);
138
+      if ($len == 1 || ($len % 2) == 0) {
139
+              return $len;
140
+      } else {
141
+              return (-1);
142
+      }
143
+    } else {
144
+          return self::FMT_BINARY;
142 145
     }
143
-    else
144
-      return self::FMT_BINARY;
145 146
   }
146 147
 
147 148
   /*
@@ -151,8 +152,9 @@  discard block
 block discarded – undo
151 152
   static public function generate($type, $fmt = self::FMT_BYTE,
152 153
                                   $node = "", $ns = "") {
153 154
     $func = self::$m_generate[$type];
154
-    if (!isset($func))
155
-      return null;
155
+    if (!isset($func)) {
156
+          return null;
157
+    }
156 158
     $conv = self::$m_convert[self::FMT_FIELD][$fmt];
157 159
 
158 160
     $uuid = self::$func($ns, $node);
@@ -164,8 +166,9 @@  discard block
 block discarded – undo
164 166
    */
165 167
   static public function convert($uuid, $from, $to) {
166 168
     $conv = self::$m_convert[$from][$to];
167
-    if (!isset($conv))
168
-      return ($uuid);
169
+    if (!isset($conv)) {
170
+          return ($uuid);
171
+    }
169 172
 
170 173
     return (self::$conv($uuid));
171 174
   }
@@ -181,8 +184,9 @@  discard block
 block discarded – undo
181 184
     $uuid['time_low'] = mt_rand(0, 0xffff) + (mt_rand(0, 0xffff) << 16);
182 185
     $uuid['time_mid'] = mt_rand(0, 0xffff);
183 186
     $uuid['clock_seq_low'] = mt_rand(0, 255);
184
-    for ($i = 0; $i < 6; $i++)
185
-      $uuid['node'][$i] = mt_rand(0, 255);
187
+    for ($i = 0; $i < 6; $i++) {
188
+          $uuid['node'][$i] = mt_rand(0, 255);
189
+    }
186 190
     return ($uuid);
187 191
   }
188 192
 
@@ -205,8 +209,9 @@  discard block
 block discarded – undo
205 209
     /* Hash the namespace and node and convert to a byte array */
206 210
     $val = $hash($raw, true);
207 211
     $tmp = unpack('C16', $val);
208
-    foreach (array_keys($tmp) as $key)
209
-      $byte[$key - 1] = $tmp[$key];
212
+    foreach (array_keys($tmp) as $key) {
213
+          $byte[$key - 1] = $tmp[$key];
214
+    }
210 215
 
211 216
     /* Convert byte array to a field array */
212 217
     $field = self::conv_byte2field($byte);
@@ -264,8 +269,9 @@  discard block
 block discarded – undo
264 269
       * Node should be set to the 48-bit IEEE node identifier, but
265 270
       * we leave it for the user to supply the node.
266 271
       */
267
-    for ($i = 0; $i < 6; $i++)
268
-      $uuid['node'][$i] = ord(substr($node, $i, 1));
272
+    for ($i = 0; $i < 6; $i++) {
273
+          $uuid['node'][$i] = ord(substr($node, $i, 1));
274
+    }
269 275
 
270 276
     return ($uuid);
271 277
   }
@@ -283,8 +289,9 @@  discard block
 block discarded – undo
283 289
     $uuid[8] = $src['clock_seq_hi'];
284 290
     $uuid[9] = $src['clock_seq_low'];
285 291
 
286
-    for ($i = 0; $i < 6; $i++)
287
-      $uuid[10+$i] = $src['node'][$i];
292
+    for ($i = 0; $i < 6; $i++) {
293
+          $uuid[10+$i] = $src['node'][$i];
294
+    }
288 295
 
289 296
     return ($uuid);
290 297
   }
@@ -313,8 +320,9 @@  discard block
 block discarded – undo
313 320
     $field['clock_seq_hi'] = $uuid[8];
314 321
     $field['clock_seq_low'] = $uuid[9];
315 322
 
316
-    for ($i = 0; $i < 6; $i++)
317
-      $field['node'][$i] = $uuid[10+$i];
323
+    for ($i = 0; $i < 6; $i++) {
324
+          $field['node'][$i] = $uuid[10+$i];
325
+    }
318 326
     return ($field);
319 327
   }
320 328
 
@@ -338,8 +346,9 @@  discard block
 block discarded – undo
338 346
     $field['time_hi'] = ($parts[2]);
339 347
     $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8;
340 348
     $field['clock_seq_low'] = $parts[3] & 0x00ff;
341
-    for ($i = 0; $i < 6; $i++)
342
-      $field['node'][$i] = $parts[4+$i];
349
+    for ($i = 0; $i < 6; $i++) {
350
+          $field['node'][$i] = $parts[4+$i];
351
+    }
343 352
 
344 353
     return ($field);
345 354
   }
Please login to merge, or discard this patch.
src/EoC/Helper/ArrayHelper.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -54,6 +54,7 @@
 block discarded – undo
54 54
    * @brief Converts the given JSON into an array.
55 55
    * @param[in] string $json A JSON object.
56 56
    * @param[in] bool $assoc When `true`, returned objects will be converted into associative arrays.
57
+   * @param boolean $assoc
57 58
    * @retval array
58 59
    */
59 60
   public static function fromJson($json, $assoc) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,10 +59,11 @@
 block discarded – undo
59 59
   public static function fromJson($json, $assoc) {
60 60
     $data = json_decode((string)$json, $assoc);
61 61
 
62
-    if (is_null($data))
63
-      switch (json_last_error()) {
62
+    if (is_null($data)) {
63
+          switch (json_last_error()) {
64 64
         case JSON_ERROR_DEPTH:
65 65
           throw new JSONErrorException("Unable to parse the given JSON, the maximum stack depth has been exceeded.");
66
+    }
66 67
           break;
67 68
         case JSON_ERROR_STATE_MISMATCH:
68 69
           throw new JSONErrorException("Unable to parse the given JSON, invalid or malformed JSON.");
Please login to merge, or discard this patch.
src/EoC/Message/Request.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -266,6 +266,7 @@  discard block
 block discarded – undo
266 266
    * @param[in] string $path The absolute path of the request.
267 267
    * @param[in] string $queryParams (optional) Associative array of query parameters.
268 268
    * @param[in] string $headerFields (optional) Associative array of header fields.
269
+   * @param string $path
269 270
    */
270 271
   public function __construct($method, $path, array $queryParams = NULL, array $headerFields = NULL) {
271 272
     parent::__construct();
@@ -419,6 +420,8 @@  discard block
 block discarded – undo
419 420
    * @brief This helper forces request to use the Authorization Basic mode.
420 421
    * @param[in] string $userName User name.
421 422
    * @param[in] string $password Password.
423
+   * @param string $userName
424
+   * @param string $password
422 425
    */
423 426
   public function setBasicAuth($userName, $password) {
424 427
     $this->setHeaderField(self::AUTHORIZATION_HF, "Basic ".base64_encode("$userName:$password"));
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
    */
190 190
   const X_FORWARDED_FOR_HF = "X-Forwarded-For";
191 191
 
192
-  const DESTINATION_HF = "Destination";  //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB.
193
-  const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate";  //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB.
194
-  const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit";  //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB.
192
+  const DESTINATION_HF = "Destination"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB.
193
+  const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate"; //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB.
194
+  const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB.
195 195
 
196 196
   //!@}
197 197
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
       $params = explode('&', $query);
409 409
 
410 410
       foreach ($params as $param) {
411
-        @list($name, $value)  = explode('=', $param, 2);
411
+        @list($name, $value) = explode('=', $param, 2);
412 412
         $this->setQueryParam($name, $value);
413 413
       }
414 414
     }
Please login to merge, or discard this patch.
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -281,11 +281,13 @@  discard block
 block discarded – undo
281 281
     $this->setMethod($method);
282 282
     $this->setPath($path);
283 283
 
284
-    if (isset($queryParams))
285
-      $this->setMultipleQueryParamsAtOnce($queryParams);
284
+    if (isset($queryParams)) {
285
+          $this->setMultipleQueryParamsAtOnce($queryParams);
286
+    }
286 287
 
287
-    if (isset($headerFields))
288
-      $this->setMultipleHeaderFieldsAtOnce($headerFields);
288
+    if (isset($headerFields)) {
289
+          $this->setMultipleHeaderFieldsAtOnce($headerFields);
290
+    }
289 291
   }
290 292
 
291 293
 
@@ -318,10 +320,11 @@  discard block
 block discarded – undo
318 320
    * @param[in] string $method The HTTP method for the request. You should use one of the public constants, like GET_METHOD.
319 321
    */
320 322
   public function setMethod($method) {
321
-    if (array_key_exists($method, self::$supportedMethods))
322
-      $this->method = $method;
323
-    else
324
-      throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method.");
323
+    if (array_key_exists($method, self::$supportedMethods)) {
324
+          $this->method = $method;
325
+    } else {
326
+          throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method.");
327
+    }
325 328
   }
326 329
 
327 330
 
@@ -330,10 +333,11 @@  discard block
 block discarded – undo
330 333
    * @param[in] string $method The HTTP custom method.
331 334
    */
332 335
   public static function addCustomMethod($method) {
333
-    if (array_key_exists($method, self::$supportedMethods))
334
-      throw new \UnexpectedValueException("$method method is supported and already exists.");
335
-    else
336
-      self::$supportedMethods[] = $method;
336
+    if (array_key_exists($method, self::$supportedMethods)) {
337
+          throw new \UnexpectedValueException("$method method is supported and already exists.");
338
+    } else {
339
+          self::$supportedMethods[] = $method;
340
+    }
337 341
   }
338 342
 
339 343
 
@@ -351,10 +355,11 @@  discard block
 block discarded – undo
351 355
    * @param[in] string $path The absolute path of the request.
352 356
    */
353 357
   public function setPath($path) {
354
-    if (is_string($path))
355
-      $this->path = addslashes($path);
356
-    else
357
-      throw new \InvalidArgumentException("\$path must be a string.");
358
+    if (is_string($path)) {
359
+          $this->path = addslashes($path);
360
+    } else {
361
+          throw new \InvalidArgumentException("\$path must be a string.");
362
+    }
358 363
   }
359 364
 
360 365
 
@@ -364,11 +369,12 @@  discard block
 block discarded – undo
364 369
    * @param[in] string $value Parameter value.
365 370
    */
366 371
   public function setQueryParam($name, $value) {
367
-    if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name))
368
-      $this->queryParams[$name] = $value;
369
-    else
370
-      throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of
372
+    if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) {
373
+          $this->queryParams[$name] = $value;
374
+    } else {
375
+          throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of
371 376
           letters, numbers, or underscores.");
377
+    }
372 378
   }
373 379
 
374 380
 
@@ -377,11 +383,12 @@  discard block
 block discarded – undo
377 383
    * @param[in] array $params An associative array of parameters.
378 384
    */
379 385
   public function setMultipleQueryParamsAtOnce(array $params) {
380
-    if (Helper\ArrayHelper::isAssociative($params))
381
-      foreach ($params as $name => $value)
386
+    if (Helper\ArrayHelper::isAssociative($params)) {
387
+          foreach ($params as $name => $value)
382 388
         $this->setQueryParam($name, $value);
383
-    else
384
-      throw new \InvalidArgumentException("\$params must be an associative array.");
389
+    } else {
390
+          throw new \InvalidArgumentException("\$params must be an associative array.");
391
+    }
385 392
   }
386 393
 
387 394
 
@@ -390,11 +397,12 @@  discard block
 block discarded – undo
390 397
    * @retval string
391 398
    */
392 399
   public function getQueryString() {
393
-    if (empty($this->queryParams))
394
-      return "";
395
-    else
396
-      // Encoding is based on RFC 3986.
400
+    if (empty($this->queryParams)) {
401
+          return "";
402
+    } else {
403
+          // Encoding is based on RFC 3986.
397 404
       return "?".http_build_query($this->queryParams, NULL, "&", PHP_QUERY_RFC3986);
405
+    }
398 406
   }
399 407
 
400 408
 
Please login to merge, or discard this patch.
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 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -100,8 +100,8 @@
 block discarded – undo
100 100
       $buffer .= "File Opened Since: ".sprintf($since, $time['days'], $time['hours'], $time['minutes'], $time['seconds']).PHP_EOL;
101 101
     }
102 102
 
103
-    $buffer .= "Disk Size: ".round($this->diskSize/(1024*1024*1024), 3)." GB".PHP_EOL;
104
-    $buffer .= "Data Size: ".round($this->dataSize/(1024*1024*1024), 3)." GB".PHP_EOL;
103
+    $buffer .= "Disk Size: ".round($this->diskSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL;
104
+    $buffer .= "Data Size: ".round($this->dataSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL;
105 105
     $buffer .= "Disk Format Version: ".$this->diskFormatVersion.PHP_EOL;
106 106
 
107 107
     $compactRunning = ($this->compactRunning) ? 'active' : 'inactive';
Please login to merge, or discard this 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 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -908,7 +908,7 @@
 block discarded – undo
908 908
    * @see http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate
909 909
    */
910 910
   public function startReplication($sourceDbUrl, $targetDbUrl, $proxy = NULL, $createTargetDb = TRUE,
911
-                                     $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) {
911
+                                      $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) {
912 912
     // Sets source and target databases.
913 913
     if (is_string($sourceDbUrl) && !empty($sourceDbUrl) &&
914 914
       is_string($targetDbUrl) && !empty($targetDbUrl)) {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
   //!@{
36 36
 
37 37
   const STD_DOC_PATH = ""; //!< Path for standard documents.
38
-  const LOCAL_DOC_PATH = "_local/";  //!< Path for local documents.
39
-  const DESIGN_DOC_PATH = "_design/";  //!< Path for design documents.
38
+  const LOCAL_DOC_PATH = "_local/"; //!< Path for local documents.
39
+  const DESIGN_DOC_PATH = "_design/"; //!< Path for design documents.
40 40
 
41 41
   //!@}
42 42
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
   public function cleanupViews() {
784 784
     $this->checkForDb();
785 785
 
786
-    $request =  new Request(Request::POST_METHOD, "/".$this->dbName."/_view_cleanup");
786
+    $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_view_cleanup");
787 787
 
788 788
     // A POST method requires Content-Type header.
789 789
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
Please login to merge, or discard this 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
     $request = new Request(Request::POST_METHOD, "/_replicate");
@@ -964,8 +996,9 @@  discard block
 block discarded – undo
964 996
    * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication
965 997
    */
966 998
   public function stopReplication($replicationId) {
967
-    if (is_null($replicationId))
968
-      throw new \InvalidArgumentException("You must provide a replication id.");
999
+    if (is_null($replicationId)) {
1000
+          throw new \InvalidArgumentException("You must provide a replication id.");
1001
+    }
969 1002
 
970 1003
     $body["replication_id"] = $replicationId;
971 1004
     $body["cancel"] = TRUE;
@@ -1015,15 +1048,16 @@  discard block
 block discarded – undo
1015 1048
   public function queryAllDocs(array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) {
1016 1049
     $this->checkForDb();
1017 1050
 
1018
-    if (is_null($keys))
1019
-      $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs");
1020
-    else {
1051
+    if (is_null($keys)) {
1052
+          $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs");
1053
+    } else {
1021 1054
       $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_all_docs");
1022 1055
       $request->setBody(json_encode(['keys' => $keys]));
1023 1056
     }
1024 1057
 
1025
-    if (isset($opts))
1026
-      $request->setMultipleQueryParamsAtOnce($opts->asArray());
1058
+    if (isset($opts)) {
1059
+          $request->setMultipleQueryParamsAtOnce($opts->asArray());
1060
+    }
1027 1061
 
1028 1062
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1029 1063
 
@@ -1052,12 +1086,13 @@  discard block
 block discarded – undo
1052 1086
     $this->checkForDb();
1053 1087
     $this->validateAndEncodeDocId($designDocName);
1054 1088
 
1055
-    if (empty($viewName))
1056
-      throw new \InvalidArgumentException("You must provide a valid \$viewName.");
1089
+    if (empty($viewName)) {
1090
+          throw new \InvalidArgumentException("You must provide a valid \$viewName.");
1091
+    }
1057 1092
 
1058
-    if (empty($keys))
1059
-      $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1060
-    else {
1093
+    if (empty($keys)) {
1094
+          $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1095
+    } else {
1061 1096
       $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName);
1062 1097
       $request->setBody(json_encode(['keys' => $keys]));
1063 1098
     }
@@ -1065,14 +1100,15 @@  discard block
 block discarded – undo
1065 1100
     if (isset($opts)) {
1066 1101
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1067 1102
       $includeMissingKeys = $opts->issetIncludeMissingKeys();
1103
+    } else {
1104
+          $includeMissingKeys = FALSE;
1068 1105
     }
1069
-    else
1070
-      $includeMissingKeys = FALSE;
1071 1106
 
1072 1107
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1073 1108
 
1074
-    if ($includeMissingKeys)
1075
-      $this->addMissingRows($keys, $result['rows']);
1109
+    if ($includeMissingKeys) {
1110
+          $this->addMissingRows($keys, $result['rows']);
1111
+    }
1076 1112
 
1077 1113
     return new Result\QueryResult($result);
1078 1114
   }
@@ -1100,30 +1136,33 @@  discard block
 block discarded – undo
1100 1136
     $handler = new Handler\ViewHandler('temp');
1101 1137
     $handler->language = $language;
1102 1138
     $handler->mapFn = $mapFn;
1103
-    if (!empty($reduce))
1104
-      $handler->reduceFn = $reduceFn;
1139
+    if (!empty($reduce)) {
1140
+          $handler->reduceFn = $reduceFn;
1141
+    }
1105 1142
 
1106 1143
     $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_temp_view");
1107 1144
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
1108 1145
 
1109 1146
     $array = $handler->asArray();
1110 1147
 
1111
-    if (!empty($keys))
1112
-      $array['keys'] = $keys;
1148
+    if (!empty($keys)) {
1149
+          $array['keys'] = $keys;
1150
+    }
1113 1151
 
1114 1152
     $request->setBody(json_encode($array));
1115 1153
 
1116 1154
     if (isset($opts)) {
1117 1155
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1118 1156
       $includeMissingKeys = $opts->issetIncludeMissingKeys();
1157
+    } else {
1158
+          $includeMissingKeys = FALSE;
1119 1159
     }
1120
-    else
1121
-      $includeMissingKeys = FALSE;
1122 1160
 
1123 1161
     $result = $this->send($request, $chunkHook)->getBodyAsArray();
1124 1162
 
1125
-    if ($includeMissingKeys)
1126
-      $this->addMissingRows($keys, $result['rows']);
1163
+    if ($includeMissingKeys) {
1164
+          $this->addMissingRows($keys, $result['rows']);
1165
+    }
1127 1166
 
1128 1167
     return new Result\QueryResult($result);
1129 1168
   }
@@ -1186,8 +1225,9 @@  discard block
 block discarded – undo
1186 1225
   public function setRevsLimit($revsLimit = self::REVS_LIMIT) {
1187 1226
     $this->checkForDb();
1188 1227
 
1189
-    if (!is_int($revsLimit) or ($revsLimit <= 0))
1190
-      throw new \InvalidArgumentException("\$revsLimit must be a positive integer.");
1228
+    if (!is_int($revsLimit) or ($revsLimit <= 0)) {
1229
+          throw new \InvalidArgumentException("\$revsLimit must be a positive integer.");
1230
+    }
1191 1231
 
1192 1232
     $request = new Request(Request::PUT_METHOD, "/".$this->dbName."/_revs_limit");
1193 1233
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
@@ -1245,16 +1285,17 @@  discard block
 block discarded – undo
1245 1285
     $request = new Request(Request::GET_METHOD, $requestPath);
1246 1286
 
1247 1287
     // Retrieves the specific revision of the document.
1248
-    if (!empty($rev))
1249
-      $request->setQueryParam("rev", (string)$rev);
1288
+    if (!empty($rev)) {
1289
+          $request->setQueryParam("rev", (string)$rev);
1290
+    }
1250 1291
 
1251 1292
     // If there are any options, add them to the request.
1252 1293
     if (isset($opts)) {
1253 1294
       $request->setMultipleQueryParamsAtOnce($opts->asArray());
1254 1295
       $ignoreClass = $opts->issetIgnoreClass();
1296
+    } else {
1297
+          $ignoreClass = FALSE;
1255 1298
     }
1256
-    else
1257
-      $ignoreClass = FALSE;
1258 1299
 
1259 1300
     $response = $this->send($request);
1260 1301
     $body = $response->getBodyAsArray();
@@ -1266,18 +1307,18 @@  discard block
 block discarded – undo
1266 1307
     if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc.
1267 1308
       $class = "\\".$body['class'];
1268 1309
       $doc = new $class;
1310
+    } elseif ($path == self::DESIGN_DOC_PATH) {
1311
+          $doc = new Doc\DesignDoc;
1312
+    } else {
1313
+          $doc = NULL;
1269 1314
     }
1270
-    elseif ($path == self::DESIGN_DOC_PATH)
1271
-      $doc = new Doc\DesignDoc;
1272
-    else
1273
-      $doc = NULL;
1274 1315
 
1275 1316
     if (is_object($doc)) {
1276 1317
       $doc->assignArray($body);
1277 1318
       return $doc;
1319
+    } else {
1320
+          return $response;
1278 1321
     }
1279
-    else
1280
-      return $response;
1281 1322
   }
1282 1323
 
1283 1324
 
@@ -1304,8 +1345,9 @@  discard block
 block discarded – undo
1304 1345
 
1305 1346
     // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc
1306 1347
     // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids.
1307
-    if (!$doc->issetId())
1308
-      $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));
1348
+    if (!$doc->issetId()) {
1349
+          $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));
1350
+    }
1309 1351
 
1310 1352
     $this->setDocInfo($doc);
1311 1353
 
@@ -1319,8 +1361,9 @@  discard block
 block discarded – undo
1319 1361
     $request->setBody($doc->asJson());
1320 1362
 
1321 1363
     // Enables batch mode.
1322
-    if ($batchMode)
1323
-      $request->setQueryParam("batch", "ok");
1364
+    if ($batchMode) {
1365
+          $request->setQueryParam("batch", "ok");
1366
+    }
1324 1367
 
1325 1368
     $this->send($request);
1326 1369
   }
@@ -1373,10 +1416,11 @@  discard block
 block discarded – undo
1373 1416
     // This request uses the special method COPY.
1374 1417
     $request = new Request(Request::COPY_METHOD, $path);
1375 1418
 
1376
-    if (empty($rev))
1377
-      $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);
1378
-    else
1379
-      $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);
1419
+    if (empty($rev)) {
1420
+          $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);
1421
+    } else {
1422
+          $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);
1423
+    }
1380 1424
 
1381 1425
     $this->send($request);
1382 1426
   }
@@ -1406,8 +1450,9 @@  discard block
 block discarded – undo
1406 1450
     $request = new Request(Request::POST_METHOD, $path);
1407 1451
 
1408 1452
     $purge = [];
1409
-    foreach ($refs as $ref)
1410
-      $purge[] = $ref->asArray();
1453
+    foreach ($refs as $ref) {
1454
+          $purge[] = $ref->asArray();
1455
+    }
1411 1456
 
1412 1457
     $request->setBody(json_encode($purge));
1413 1458
 
@@ -1440,26 +1485,30 @@  discard block
 block discarded – undo
1440 1485
   public function performBulkOperations(array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) {
1441 1486
     $this->checkForDb();
1442 1487
 
1443
-    if (count($docs) == 0)
1444
-      throw new \InvalidArgumentException("The \$docs array cannot be empty.");
1445
-    else
1446
-      $operations = [];
1488
+    if (count($docs) == 0) {
1489
+          throw new \InvalidArgumentException("The \$docs array cannot be empty.");
1490
+    } else {
1491
+          $operations = [];
1492
+    }
1447 1493
 
1448 1494
     $path = "/".$this->dbName."/_bulk_docs";
1449 1495
 
1450 1496
     $request = new Request(Request::POST_METHOD, $path);
1451 1497
     $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");
1452 1498
 
1453
-    if ($fullCommit)
1454
-      $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");
1455
-    else
1456
-      $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");
1499
+    if ($fullCommit) {
1500
+          $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");
1501
+    } else {
1502
+          $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");
1503
+    }
1457 1504
 
1458
-    if ($allOrNothing)
1459
-      $operations['all_or_nothing'] = 'true';
1505
+    if ($allOrNothing) {
1506
+          $operations['all_or_nothing'] = 'true';
1507
+    }
1460 1508
 
1461
-    if (!$newEdits)
1462
-      $operations['new_edits'] = 'false';
1509
+    if (!$newEdits) {
1510
+          $operations['new_edits'] = 'false';
1511
+    }
1463 1512
 
1464 1513
     foreach ($docs as $doc) {
1465 1514
       $this->setDocInfo($doc);
@@ -1497,8 +1546,9 @@  discard block
 block discarded – undo
1497 1546
     $request = new Request(Request::HEAD_METHOD, $path);
1498 1547
 
1499 1548
     // In case we want retrieve a specific document revision.
1500
-    if (!empty($rev))
1501
-      $request->setQueryParam("rev", (string)$rev);
1549
+    if (!empty($rev)) {
1550
+          $request->setQueryParam("rev", (string)$rev);
1551
+    }
1502 1552
 
1503 1553
     return $this->send($request);
1504 1554
   }
@@ -1524,8 +1574,9 @@  discard block
 block discarded – undo
1524 1574
     $request = new Request(Request::GET_METHOD, $path);
1525 1575
 
1526 1576
     // In case we want retrieve a specific document revision.
1527
-    if (!empty($rev))
1528
-      $request->setQueryParam("rev", (string)$rev);
1577
+    if (!empty($rev)) {
1578
+          $request->setQueryParam("rev", (string)$rev);
1579
+    }
1529 1580
 
1530 1581
     return $this->send($request)->getBody();
1531 1582
   }
@@ -1554,8 +1605,9 @@  discard block
 block discarded – undo
1554 1605
     $request->setBody(base64_encode($attachment->getData()));
1555 1606
 
1556 1607
     // In case of adding or updating an existence document.
1557
-    if (!empty($rev))
1558
-      $request->setQueryParam("rev", (string)$rev);
1608
+    if (!empty($rev)) {
1609
+          $request->setQueryParam("rev", (string)$rev);
1610
+    }
1559 1611
 
1560 1612
     return $this->send($request);
1561 1613
   }
Please login to merge, or discard this patch.
src/EoC/Doc/LocalDoc.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
  * configurations.\n
18 18
  * Inherit from LocalDoc if you want create a persistent class that is not replicable.
19 19
  * @nosubgrouping
20
-   */
20
+ */
21 21
 class LocalDoc extends AbstractDoc {
22 22
 
23 23
 
Please login to merge, or discard this 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/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.