@@ -143,10 +143,11 @@ |
||
143 | 143 | * @param[in] string|array $revs The revision(s) identifier(s). |
144 | 144 | */ |
145 | 145 | public function includeOpenRevs($revs = 'all') { |
146 | - if (is_array($revs)) |
|
147 | - $this->options['open_revs'] = json_encode($revs); |
|
148 | - else |
|
149 | - $this->options['open_revs'] = 'all'; |
|
146 | + if (is_array($revs)) { |
|
147 | + $this->options['open_revs'] = json_encode($revs); |
|
148 | + } else { |
|
149 | + $this->options['open_revs'] = 'all'; |
|
150 | + } |
|
150 | 151 | |
151 | 152 | return $this; |
152 | 153 | } |
@@ -281,11 +281,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -206,8 +206,9 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function getHeaderAsArray() { |
208 | 208 | $wellformedHeader = []; |
209 | - foreach ($this->header as $name => $value) |
|
210 | - $wellformedHeader[] = $name.": ".$value; |
|
209 | + foreach ($this->header as $name => $value) { |
|
210 | + $wellformedHeader[] = $name.": ".$value; |
|
211 | + } |
|
211 | 212 | |
212 | 213 | return $wellformedHeader; |
213 | 214 | } |
@@ -238,10 +239,11 @@ discard block |
||
238 | 239 | * @retval string |
239 | 240 | */ |
240 | 241 | public function getHeaderFieldValue($name) { |
241 | - if ($this->hasHeaderField($name)) |
|
242 | - return $this->header[$name]; |
|
243 | - else |
|
244 | - return FALSE; |
|
242 | + if ($this->hasHeaderField($name)) { |
|
243 | + return $this->header[$name]; |
|
244 | + } else { |
|
245 | + return FALSE; |
|
246 | + } |
|
245 | 247 | } |
246 | 248 | |
247 | 249 | |
@@ -251,10 +253,11 @@ discard block |
||
251 | 253 | * @param[in] string $value The header field value. |
252 | 254 | */ |
253 | 255 | public function setHeaderField($name, $value) { |
254 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
255 | - $this->header[$name] = $value; |
|
256 | - else |
|
257 | - throw new \Exception("$name header field is not supported."); |
|
256 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
257 | + $this->header[$name] = $value; |
|
258 | + } else { |
|
259 | + throw new \Exception("$name header field is not supported."); |
|
260 | + } |
|
258 | 261 | } |
259 | 262 | |
260 | 263 | |
@@ -263,8 +266,9 @@ discard block |
||
263 | 266 | * @param[in] string $name The header field name. |
264 | 267 | */ |
265 | 268 | public function removeHeaderField($name) { |
266 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
267 | - unset($this->header[$name]); |
|
269 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
270 | + unset($this->header[$name]); |
|
271 | + } |
|
268 | 272 | } |
269 | 273 | |
270 | 274 | |
@@ -273,11 +277,12 @@ discard block |
||
273 | 277 | * @param[in] array $headerFields An associative array of header fields. |
274 | 278 | */ |
275 | 279 | public function setMultipleHeaderFieldsAtOnce(array $headerFields) { |
276 | - if (Helper\ArrayHelper::isAssociative($headerFields)) |
|
277 | - foreach ($headerFields as $name => $value) |
|
280 | + if (Helper\ArrayHelper::isAssociative($headerFields)) { |
|
281 | + foreach ($headerFields as $name => $value) |
|
278 | 282 | $this->setHeaderField($name, $value); |
279 | - else |
|
280 | - throw new \Exception("\$headerFields must be an associative array."); |
|
283 | + } else { |
|
284 | + throw new \Exception("\$headerFields must be an associative array."); |
|
285 | + } |
|
281 | 286 | } |
282 | 287 | |
283 | 288 | |
@@ -286,10 +291,11 @@ discard block |
||
286 | 291 | * @param[in] string $name Header field name. |
287 | 292 | */ |
288 | 293 | public static function addCustomHeaderField($name) { |
289 | - if (array_key_exists($name, static::$supportedHeaderFields)) |
|
290 | - throw new \Exception("$name header field is supported but already exists."); |
|
291 | - else |
|
292 | - static::$supportedHeaderFields[] = $name; |
|
294 | + if (array_key_exists($name, static::$supportedHeaderFields)) { |
|
295 | + throw new \Exception("$name header field is supported but already exists."); |
|
296 | + } else { |
|
297 | + static::$supportedHeaderFields[] = $name; |
|
298 | + } |
|
293 | 299 | } |
294 | 300 | |
295 | 301 |
@@ -68,9 +68,10 @@ |
||
68 | 68 | $this->scheme = isset($matches['scheme']) ? $matches['scheme'] : "tcp://"; |
69 | 69 | $this->host = isset($matches['host']) ? $matches['host'] : self::DEFAULT_HOST; |
70 | 70 | $this->port = isset($matches['port']) ? substr($matches['port'], 1) : self::DEFAULT_PORT; |
71 | - } |
|
72 | - else // Match attempt failed. |
|
71 | + } else { |
|
72 | + // Match attempt failed. |
|
73 | 73 | throw new \InvalidArgumentException(sprintf("'%s' is not a valid URI.", $server)); |
74 | + } |
|
74 | 75 | |
75 | 76 | $this->userName = (string)$userName; |
76 | 77 | $this->password = (string)$password; |
@@ -52,8 +52,9 @@ discard block |
||
52 | 52 | * @copydoc AbstractAdapter::initialize() |
53 | 53 | */ |
54 | 54 | public function initialize() { |
55 | - if (!extension_loaded("curl")) |
|
56 | - throw new \RuntimeException("The cURL extension is not loaded."); |
|
55 | + if (!extension_loaded("curl")) { |
|
56 | + throw new \RuntimeException("The cURL extension is not loaded."); |
|
57 | + } |
|
57 | 58 | } |
58 | 59 | |
59 | 60 | |
@@ -64,8 +65,9 @@ discard block |
||
64 | 65 | $opts = []; |
65 | 66 | |
66 | 67 | // Resets all the cURL options. The curl_reset() function is available only since PHP 5.5. |
67 | - if (function_exists('curl_reset')) |
|
68 | - curl_reset($this->handle); |
|
68 | + if (function_exists('curl_reset')) { |
|
69 | + curl_reset($this->handle); |
|
70 | + } |
|
69 | 71 | |
70 | 72 | // Sets the methods and its related options. |
71 | 73 | switch ($request->getMethod()) { |
@@ -100,9 +102,9 @@ discard block |
||
100 | 102 | |
101 | 103 | $opts[CURLOPT_INFILE] = $fd; |
102 | 104 | $opts[CURLOPT_INFILESIZE] = $request->getBodyLength(); |
105 | + } else { |
|
106 | + throw new \RuntimeException("Cannot create the stream."); |
|
103 | 107 | } |
104 | - else |
|
105 | - throw new \RuntimeException("Cannot create the stream."); |
|
106 | 108 | } |
107 | 109 | |
108 | 110 | break; |
@@ -143,8 +145,9 @@ discard block |
||
143 | 145 | // This fix a known cURL bug: see http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/ |
144 | 146 | // cURL sets the Expect header field automatically, ignoring the fact that a client may not need it for the specific |
145 | 147 | // request. |
146 | - if (!$request->hasHeaderField(Request::EXPECT_HF)) |
|
147 | - curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
148 | + if (!$request->hasHeaderField(Request::EXPECT_HF)) { |
|
149 | + curl_setopt($this->handle, CURLOPT_HTTPHEADER, array("Expect:")); |
|
150 | + } |
|
148 | 151 | |
149 | 152 | // Sets the request header. |
150 | 153 | // Due to a stupid bug, using curl_setopt_array(), cURL doesn't override the Content-Type header field. So we must |
@@ -176,8 +179,7 @@ discard block |
||
176 | 179 | $response = new Response($header); |
177 | 180 | $response->setBody($result); |
178 | 181 | return $response; |
179 | - } |
|
180 | - else { |
|
182 | + } else { |
|
181 | 183 | $error = curl_error($this->handle); |
182 | 184 | throw new \RuntimeException($error); |
183 | 185 | } |
@@ -144,8 +144,9 @@ discard block |
||
144 | 144 | public static function checkFn($fnImpl, $fnDef, $fnRegex) { |
145 | 145 | Lint::checkSourceCode($fnImpl); |
146 | 146 | |
147 | - if (!preg_match($fnRegex, $fnImpl)) |
|
148 | - throw new \Exception("The \$closure must be defined like: $fnDef"); |
|
147 | + if (!preg_match($fnRegex, $fnImpl)) { |
|
148 | + throw new \Exception("The \$closure must be defined like: $fnDef"); |
|
149 | + } |
|
149 | 150 | } |
150 | 151 | |
151 | 152 | |
@@ -153,14 +154,17 @@ discard block |
||
153 | 154 | $view = []; |
154 | 155 | $view['map'] = $this->mapFn; |
155 | 156 | |
156 | - if (!empty($this->language)) |
|
157 | - $view['language'] = $this->language; |
|
157 | + if (!empty($this->language)) { |
|
158 | + $view['language'] = $this->language; |
|
159 | + } |
|
158 | 160 | |
159 | - if (!empty($this->reduceFn)) |
|
160 | - $view['reduce'] = $this->reduceFn; |
|
161 | + if (!empty($this->reduceFn)) { |
|
162 | + $view['reduce'] = $this->reduceFn; |
|
163 | + } |
|
161 | 164 | |
162 | - if (!empty($this->options)) |
|
163 | - $view['options'] = $this->options; |
|
165 | + if (!empty($this->options)) { |
|
166 | + $view['options'] = $this->options; |
|
167 | + } |
|
164 | 168 | |
165 | 169 | return $view; |
166 | 170 | } |
@@ -225,8 +229,9 @@ discard block |
||
225 | 229 | public function setMapFn($value) { |
226 | 230 | $fn = stripslashes((string)$value); |
227 | 231 | |
228 | - if ($this->language == "php") |
|
229 | - self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); |
|
232 | + if ($this->language == "php") { |
|
233 | + self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); |
|
234 | + } |
|
230 | 235 | |
231 | 236 | $this->mapFn = $fn; |
232 | 237 | } |
@@ -240,8 +245,9 @@ discard block |
||
240 | 245 | public function setReduceFn($value) { |
241 | 246 | $fn = stripslashes((string)$value); |
242 | 247 | |
243 | - if ($this->language == "php") |
|
244 | - self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); |
|
248 | + if ($this->language == "php") { |
|
249 | + self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); |
|
250 | + } |
|
245 | 251 | |
246 | 252 | $this->reduceFn = $fn; |
247 | 253 | } |
@@ -107,10 +107,13 @@ discard block |
||
107 | 107 | foreach ($keys as $key) { |
108 | 108 | $hash = md5(json_encode($key)); |
109 | 109 | |
110 | - if (isset($matches[$hash])) // Match found. |
|
110 | + if (isset($matches[$hash])) { |
|
111 | + // Match found. |
|
111 | 112 | $allRows[] = $matches[$hash]; |
112 | - else // No match found. |
|
113 | + } else { |
|
114 | + // No match found. |
|
113 | 115 | $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL]; |
116 | + } |
|
114 | 117 | } |
115 | 118 | |
116 | 119 | // Overrides the response, replacing rows. |
@@ -190,15 +193,18 @@ discard block |
||
190 | 193 | * @param[in] bool $excludeLocal Document path. |
191 | 194 | */ |
192 | 195 | public function validateDocPath($path, $excludeLocal = FALSE) { |
193 | - if (empty($path)) // STD_DOC_PATH |
|
196 | + if (empty($path)) { |
|
197 | + // STD_DOC_PATH |
|
194 | 198 | return; |
199 | + } |
|
195 | 200 | |
196 | - if ($path == self::DESIGN_DOC_PATH) |
|
197 | - return; |
|
198 | - elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) |
|
199 | - throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
200 | - else |
|
201 | - throw new \InvalidArgumentException("Invalid document path."); |
|
201 | + if ($path == self::DESIGN_DOC_PATH) { |
|
202 | + return; |
|
203 | + } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) { |
|
204 | + throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
205 | + } else { |
|
206 | + throw new \InvalidArgumentException("Invalid document path."); |
|
207 | + } |
|
202 | 208 | } |
203 | 209 | |
204 | 210 | |
@@ -209,10 +215,11 @@ discard block |
||
209 | 215 | * @param string $docId Document id. |
210 | 216 | */ |
211 | 217 | public function validateAndEncodeDocId(&$docId) { |
212 | - if (!empty($docId)) |
|
213 | - $docId = rawurlencode($docId); |
|
214 | - else |
|
215 | - throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
218 | + if (!empty($docId)) { |
|
219 | + $docId = rawurlencode($docId); |
|
220 | + } else { |
|
221 | + throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
222 | + } |
|
216 | 223 | } |
217 | 224 | |
218 | 225 | //!@} |
@@ -244,10 +251,10 @@ discard block |
||
244 | 251 | // before the client has received the entire response. To avoid problems, we trap the exception and we go on. |
245 | 252 | try { |
246 | 253 | $this->send($request); |
247 | - } |
|
248 | - catch (\Exception $e) { |
|
249 | - if ($e->getCode() > 0) |
|
250 | - throw $e; |
|
254 | + } catch (\Exception $e) { |
|
255 | + if ($e->getCode() > 0) { |
|
256 | + throw $e; |
|
257 | + } |
|
251 | 258 | } |
252 | 259 | } |
253 | 260 | |
@@ -284,10 +291,11 @@ discard block |
||
284 | 291 | public function getFavicon() { |
285 | 292 | $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico")); |
286 | 293 | |
287 | - if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") |
|
288 | - return $response->getBody(); |
|
289 | - else |
|
290 | - throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
294 | + if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") { |
|
295 | + return $response->getBody(); |
|
296 | + } else { |
|
297 | + throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
298 | + } |
|
291 | 299 | } |
292 | 300 | |
293 | 301 | |
@@ -321,8 +329,9 @@ discard block |
||
321 | 329 | public function getDbUpdates(Opt\DbUpdatesFeedOpts $opts = NULL) { |
322 | 330 | $request = new Request(Request::GET_METHOD, "/_db_updates"); |
323 | 331 | |
324 | - if (isset($opts)) |
|
325 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
332 | + if (isset($opts)) { |
|
333 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
334 | + } |
|
326 | 335 | |
327 | 336 | return $this->send($request)->getBodyAsArray(); |
328 | 337 | } |
@@ -351,9 +360,9 @@ discard block |
||
351 | 360 | $request = new Request(Request::GET_METHOD, "/_log"); |
352 | 361 | $request->setQueryParam("bytes", $bytes); |
353 | 362 | return $this->send($request)->getBody(); |
363 | + } else { |
|
364 | + throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
354 | 365 | } |
355 | - else |
|
356 | - throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
357 | 366 | } |
358 | 367 | |
359 | 368 | |
@@ -370,13 +379,15 @@ discard block |
||
370 | 379 | |
371 | 380 | $response = $this->send($request); |
372 | 381 | |
373 | - if ($count == 1) // We don't need to use === operator because, just above, we made a type checking. |
|
382 | + if ($count == 1) { |
|
383 | + // We don't need to use === operator because, just above, we made a type checking. |
|
374 | 384 | return $response->getBodyAsArray()['uuids'][0]; |
375 | - else |
|
376 | - return $response->getBodyAsArray()['uuids']; |
|
385 | + } else { |
|
386 | + return $response->getBodyAsArray()['uuids']; |
|
387 | + } |
|
388 | + } else { |
|
389 | + throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
377 | 390 | } |
378 | - else |
|
379 | - throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
380 | 391 | } |
381 | 392 | |
382 | 393 | //!@} |
@@ -400,8 +411,9 @@ discard block |
||
400 | 411 | if (!empty($section)) { |
401 | 412 | $path .= "/".$section; |
402 | 413 | |
403 | - if (!empty($key)) |
|
404 | - $path .= "/".$key; |
|
414 | + if (!empty($key)) { |
|
415 | + $path .= "/".$key; |
|
416 | + } |
|
405 | 417 | } |
406 | 418 | |
407 | 419 | return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray(); |
@@ -416,14 +428,17 @@ discard block |
||
416 | 428 | * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key |
417 | 429 | */ |
418 | 430 | public function setConfigKey($section, $key, $value) { |
419 | - if (!is_string($section) or empty($section)) |
|
420 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
431 | + if (!is_string($section) or empty($section)) { |
|
432 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
433 | + } |
|
421 | 434 | |
422 | - if (!is_string($key) or empty($key)) |
|
423 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
435 | + if (!is_string($key) or empty($key)) { |
|
436 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
437 | + } |
|
424 | 438 | |
425 | - if (is_null($value)) |
|
426 | - throw new \InvalidArgumentException("\$value cannot be null."); |
|
439 | + if (is_null($value)) { |
|
440 | + throw new \InvalidArgumentException("\$value cannot be null."); |
|
441 | + } |
|
427 | 442 | |
428 | 443 | $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key); |
429 | 444 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -439,11 +454,13 @@ discard block |
||
439 | 454 | * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key |
440 | 455 | */ |
441 | 456 | public function deleteConfigKey($section, $key) { |
442 | - if (!is_string($section) or empty($section)) |
|
443 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
457 | + if (!is_string($section) or empty($section)) { |
|
458 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
459 | + } |
|
444 | 460 | |
445 | - if (!is_string($key) or empty($key)) |
|
446 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
461 | + if (!is_string($key) or empty($key)) { |
|
462 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
463 | + } |
|
447 | 464 | |
448 | 465 | $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key)); |
449 | 466 | } |
@@ -470,11 +487,13 @@ discard block |
||
470 | 487 | * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session |
471 | 488 | */ |
472 | 489 | public function setSession($userName, $password) { |
473 | - if (!is_string($userName) or empty($userName)) |
|
474 | - throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
490 | + if (!is_string($userName) or empty($userName)) { |
|
491 | + throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
492 | + } |
|
475 | 493 | |
476 | - if (!is_string($password) or empty($password)) |
|
477 | - throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
494 | + if (!is_string($password) or empty($password)) { |
|
495 | + throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
496 | + } |
|
478 | 497 | |
479 | 498 | $request = new Request(Request::POST_METHOD, "/_session"); |
480 | 499 | |
@@ -561,8 +580,9 @@ discard block |
||
561 | 580 | # One of the characters “_$()” «_$()» |
562 | 581 | # A character in the range between “+” and “/” «+-/» |
563 | 582 | # Assert position at the very end of the string «\z» |
564 | - if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) |
|
565 | - throw new \InvalidArgumentException("Invalid database name."); |
|
583 | + if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) { |
|
584 | + throw new \InvalidArgumentException("Invalid database name."); |
|
585 | + } |
|
566 | 586 | |
567 | 587 | $this->send(new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$name)."/")); |
568 | 588 | } |
@@ -600,8 +620,9 @@ discard block |
||
600 | 620 | public function getDbChanges($name, Opt\ChangesFeedOpts $opts = NULL) { |
601 | 621 | $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$name)."/_changes"); |
602 | 622 | |
603 | - if (isset($opts)) |
|
604 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
623 | + if (isset($opts)) { |
|
624 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
625 | + } |
|
605 | 626 | |
606 | 627 | return $this->send($request); |
607 | 628 | } |
@@ -790,40 +811,47 @@ discard block |
||
790 | 811 | is_string($targetDbUrl) && !empty($targetDbUrl)) { |
791 | 812 | $body["source"] = $sourceDbUrl; |
792 | 813 | $body["target"] = $targetDbUrl; |
814 | + } else { |
|
815 | + throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
793 | 816 | } |
794 | - else |
|
795 | - throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
796 | 817 | |
797 | - if (!is_bool($continuous)) |
|
798 | - throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
799 | - elseif ($continuous) |
|
800 | - $body["continuous"] = $continuous; |
|
818 | + if (!is_bool($continuous)) { |
|
819 | + throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
820 | + } elseif ($continuous) { |
|
821 | + $body["continuous"] = $continuous; |
|
822 | + } |
|
801 | 823 | |
802 | 824 | // Uses the specified proxy if any set. |
803 | - if (isset($proxy)) |
|
804 | - $body["proxy"] = $proxy; |
|
825 | + if (isset($proxy)) { |
|
826 | + $body["proxy"] = $proxy; |
|
827 | + } |
|
805 | 828 | |
806 | 829 | // create_target option |
807 | - if (!is_bool($createTargetDb)) |
|
808 | - throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
809 | - elseif ($createTargetDb) |
|
810 | - $body["create_target"] = $createTargetDb; |
|
830 | + if (!is_bool($createTargetDb)) { |
|
831 | + throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
832 | + } elseif ($createTargetDb) { |
|
833 | + $body["create_target"] = $createTargetDb; |
|
834 | + } |
|
811 | 835 | |
812 | 836 | if (!empty($filter)) { |
813 | - if (is_string($filter)) // filter option |
|
837 | + if (is_string($filter)) { |
|
838 | + // filter option |
|
814 | 839 | $body["filter"] = $filter; |
815 | - elseif (is_array($filter)) // doc_ids option |
|
840 | + } elseif (is_array($filter)) { |
|
841 | + // doc_ids option |
|
816 | 842 | $body["doc_ids"] = array_values($filter); |
817 | - else |
|
818 | - throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
843 | + } else { |
|
844 | + throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
845 | + } |
|
819 | 846 | } |
820 | 847 | |
821 | 848 | // queryParams option |
822 | 849 | if (!is_null($opts)) { |
823 | - if ($opts instanceof Opt\ViewQueryOpts) |
|
824 | - $body["query_params"] = get_object_vars($opts); |
|
825 | - else |
|
826 | - throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
850 | + if ($opts instanceof Opt\ViewQueryOpts) { |
|
851 | + $body["query_params"] = get_object_vars($opts); |
|
852 | + } else { |
|
853 | + throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
854 | + } |
|
827 | 855 | } |
828 | 856 | |
829 | 857 | $request = new Request(Request::POST_METHOD, "/_replicate"); |
@@ -840,8 +868,9 @@ discard block |
||
840 | 868 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication |
841 | 869 | */ |
842 | 870 | public function stopReplication($replicationId) { |
843 | - if (is_null($replicationId)) |
|
844 | - throw new \InvalidArgumentException("You must provide a replication id."); |
|
871 | + if (is_null($replicationId)) { |
|
872 | + throw new \InvalidArgumentException("You must provide a replication id."); |
|
873 | + } |
|
845 | 874 | |
846 | 875 | $body["replication_id"] = $replicationId; |
847 | 876 | $body["cancel"] = TRUE; |
@@ -890,15 +919,16 @@ discard block |
||
890 | 919 | * @see http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs |
891 | 920 | */ |
892 | 921 | public function queryAllDocs($dbName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { |
893 | - if (is_null($keys)) |
|
894 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
|
895 | - else { |
|
922 | + if (is_null($keys)) { |
|
923 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
|
924 | + } else { |
|
896 | 925 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); |
897 | 926 | $request->setBody(json_encode(['keys' => $keys])); |
898 | 927 | } |
899 | 928 | |
900 | - if (isset($opts)) |
|
901 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
929 | + if (isset($opts)) { |
|
930 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
931 | + } |
|
902 | 932 | |
903 | 933 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
904 | 934 | |
@@ -927,12 +957,13 @@ discard block |
||
927 | 957 | public function queryView($dbName, $designDocName, $viewName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { |
928 | 958 | $this->validateAndEncodeDocId($designDocName); |
929 | 959 | |
930 | - if (empty($viewName)) |
|
931 | - throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
960 | + if (empty($viewName)) { |
|
961 | + throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
962 | + } |
|
932 | 963 | |
933 | - if (empty($keys)) |
|
934 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
|
935 | - else { |
|
964 | + if (empty($keys)) { |
|
965 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
|
966 | + } else { |
|
936 | 967 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); |
937 | 968 | $request->setBody(json_encode(['keys' => $keys])); |
938 | 969 | } |
@@ -940,14 +971,15 @@ discard block |
||
940 | 971 | if (isset($opts)) { |
941 | 972 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
942 | 973 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
974 | + } else { |
|
975 | + $includeMissingKeys = FALSE; |
|
943 | 976 | } |
944 | - else |
|
945 | - $includeMissingKeys = FALSE; |
|
946 | 977 | |
947 | 978 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
948 | 979 | |
949 | - if ($includeMissingKeys) |
|
950 | - $this->addMissingRows($keys, $result['rows']); |
|
980 | + if ($includeMissingKeys) { |
|
981 | + $this->addMissingRows($keys, $result['rows']); |
|
982 | + } |
|
951 | 983 | |
952 | 984 | return new Result\QueryResult($result); |
953 | 985 | } |
@@ -974,30 +1006,33 @@ discard block |
||
974 | 1006 | $handler = new Handler\ViewHandler('temp'); |
975 | 1007 | $handler->language = $language; |
976 | 1008 | $handler->mapFn = $mapFn; |
977 | - if (!empty($reduce)) |
|
978 | - $handler->reduceFn = $reduceFn; |
|
1009 | + if (!empty($reduce)) { |
|
1010 | + $handler->reduceFn = $reduceFn; |
|
1011 | + } |
|
979 | 1012 | |
980 | 1013 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_temp_view"); |
981 | 1014 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
982 | 1015 | |
983 | 1016 | $array = $handler->asArray(); |
984 | 1017 | |
985 | - if (!empty($keys)) |
|
986 | - $array['keys'] = $keys; |
|
1018 | + if (!empty($keys)) { |
|
1019 | + $array['keys'] = $keys; |
|
1020 | + } |
|
987 | 1021 | |
988 | 1022 | $request->setBody(json_encode($array)); |
989 | 1023 | |
990 | 1024 | if (isset($opts)) { |
991 | 1025 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
992 | 1026 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
1027 | + } else { |
|
1028 | + $includeMissingKeys = FALSE; |
|
993 | 1029 | } |
994 | - else |
|
995 | - $includeMissingKeys = FALSE; |
|
996 | 1030 | |
997 | 1031 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
998 | 1032 | |
999 | - if ($includeMissingKeys) |
|
1000 | - $this->addMissingRows($keys, $result['rows']); |
|
1033 | + if ($includeMissingKeys) { |
|
1034 | + $this->addMissingRows($keys, $result['rows']); |
|
1035 | + } |
|
1001 | 1036 | |
1002 | 1037 | return new Result\QueryResult($result); |
1003 | 1038 | } |
@@ -1056,8 +1091,9 @@ discard block |
||
1056 | 1091 | * @see http://docs.couchdb.org/en/latest/api/database/misc.html#put--db-_revs_limit |
1057 | 1092 | */ |
1058 | 1093 | public function setRevsLimit($dbName, $revsLimit = self::REVS_LIMIT) { |
1059 | - if (!is_int($revsLimit) or ($revsLimit <= 0)) |
|
1060 | - throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
1094 | + if (!is_int($revsLimit) or ($revsLimit <= 0)) { |
|
1095 | + throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
1096 | + } |
|
1061 | 1097 | |
1062 | 1098 | $request = new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_revs_limit"); |
1063 | 1099 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -1115,16 +1151,17 @@ discard block |
||
1115 | 1151 | $request = new Request(Request::GET_METHOD, $requestPath); |
1116 | 1152 | |
1117 | 1153 | // Retrieves the specific revision of the document. |
1118 | - if (!empty($rev)) |
|
1119 | - $request->setQueryParam("rev", (string)$rev); |
|
1154 | + if (!empty($rev)) { |
|
1155 | + $request->setQueryParam("rev", (string)$rev); |
|
1156 | + } |
|
1120 | 1157 | |
1121 | 1158 | // If there are any options, add them to the request. |
1122 | 1159 | if (isset($opts)) { |
1123 | 1160 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
1124 | 1161 | $ignoreClass = $opts->issetIgnoreClass(); |
1162 | + } else { |
|
1163 | + $ignoreClass = FALSE; |
|
1125 | 1164 | } |
1126 | - else |
|
1127 | - $ignoreClass = FALSE; |
|
1128 | 1165 | |
1129 | 1166 | $response = $this->send($request); |
1130 | 1167 | $body = $response->getBodyAsArray(); |
@@ -1136,18 +1173,18 @@ discard block |
||
1136 | 1173 | if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc. |
1137 | 1174 | $class = "\\".$body['class']; |
1138 | 1175 | $doc = new $class; |
1176 | + } elseif ($path == self::DESIGN_DOC_PATH) { |
|
1177 | + $doc = new Doc\DesignDoc; |
|
1178 | + } else { |
|
1179 | + $doc = NULL; |
|
1139 | 1180 | } |
1140 | - elseif ($path == self::DESIGN_DOC_PATH) |
|
1141 | - $doc = new Doc\DesignDoc; |
|
1142 | - else |
|
1143 | - $doc = NULL; |
|
1144 | 1181 | |
1145 | 1182 | if (is_object($doc)) { |
1146 | 1183 | $doc->assignArray($body); |
1147 | 1184 | return $doc; |
1185 | + } else { |
|
1186 | + return $response; |
|
1148 | 1187 | } |
1149 | - else |
|
1150 | - return $response; |
|
1151 | 1188 | } |
1152 | 1189 | |
1153 | 1190 | |
@@ -1167,8 +1204,9 @@ discard block |
||
1167 | 1204 | public function saveDoc($dbName, Doc\IDoc $doc, $batchMode = FALSE) { |
1168 | 1205 | // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc |
1169 | 1206 | // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. |
1170 | - if (!$doc->issetId()) |
|
1171 | - $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
1207 | + if (!$doc->issetId()) { |
|
1208 | + $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
1209 | + } |
|
1172 | 1210 | |
1173 | 1211 | $this->setDocInfo($doc); |
1174 | 1212 | |
@@ -1182,8 +1220,9 @@ discard block |
||
1182 | 1220 | $request->setBody($doc->asJson()); |
1183 | 1221 | |
1184 | 1222 | // Enables batch mode. |
1185 | - if ($batchMode) |
|
1186 | - $request->setQueryParam("batch", "ok"); |
|
1223 | + if ($batchMode) { |
|
1224 | + $request->setQueryParam("batch", "ok"); |
|
1225 | + } |
|
1187 | 1226 | |
1188 | 1227 | $this->send($request); |
1189 | 1228 | } |
@@ -1236,10 +1275,11 @@ discard block |
||
1236 | 1275 | // This request uses the special method COPY. |
1237 | 1276 | $request = new Request(Request::COPY_METHOD, $path); |
1238 | 1277 | |
1239 | - if (empty($rev)) |
|
1240 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
1241 | - else |
|
1242 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
1278 | + if (empty($rev)) { |
|
1279 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
1280 | + } else { |
|
1281 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
1282 | + } |
|
1243 | 1283 | |
1244 | 1284 | $this->send($request); |
1245 | 1285 | } |
@@ -1268,8 +1308,9 @@ discard block |
||
1268 | 1308 | $request = new Request(Request::POST_METHOD, $path); |
1269 | 1309 | |
1270 | 1310 | $purge = []; |
1271 | - foreach ($refs as $ref) |
|
1272 | - $purge[] = $ref->asArray(); |
|
1311 | + foreach ($refs as $ref) { |
|
1312 | + $purge[] = $ref->asArray(); |
|
1313 | + } |
|
1273 | 1314 | |
1274 | 1315 | $request->setBody(json_encode($purge)); |
1275 | 1316 | |
@@ -1301,26 +1342,30 @@ discard block |
||
1301 | 1342 | * @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API |
1302 | 1343 | */ |
1303 | 1344 | public function performBulkOperations($dbName, array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) { |
1304 | - if (count($docs) == 0) |
|
1305 | - throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
1306 | - else |
|
1307 | - $operations = []; |
|
1345 | + if (count($docs) == 0) { |
|
1346 | + throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
1347 | + } else { |
|
1348 | + $operations = []; |
|
1349 | + } |
|
1308 | 1350 | |
1309 | 1351 | $path = "/".rawurlencode($this->prefix.$dbName)."/_bulk_docs"; |
1310 | 1352 | |
1311 | 1353 | $request = new Request(Request::POST_METHOD, $path); |
1312 | 1354 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
1313 | 1355 | |
1314 | - if ($fullCommit) |
|
1315 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
1316 | - else |
|
1317 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
1356 | + if ($fullCommit) { |
|
1357 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
1358 | + } else { |
|
1359 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
1360 | + } |
|
1318 | 1361 | |
1319 | - if ($allOrNothing) |
|
1320 | - $operations['all_or_nothing'] = 'true'; |
|
1362 | + if ($allOrNothing) { |
|
1363 | + $operations['all_or_nothing'] = 'true'; |
|
1364 | + } |
|
1321 | 1365 | |
1322 | - if (!$newEdits) |
|
1323 | - $operations['new_edits'] = 'false'; |
|
1366 | + if (!$newEdits) { |
|
1367 | + $operations['new_edits'] = 'false'; |
|
1368 | + } |
|
1324 | 1369 | |
1325 | 1370 | foreach ($docs as $doc) { |
1326 | 1371 | $this->setDocInfo($doc); |
@@ -1358,8 +1403,9 @@ discard block |
||
1358 | 1403 | $request = new Request(Request::HEAD_METHOD, $path); |
1359 | 1404 | |
1360 | 1405 | // In case we want retrieve a specific document revision. |
1361 | - if (!empty($rev)) |
|
1362 | - $request->setQueryParam("rev", (string)$rev); |
|
1406 | + if (!empty($rev)) { |
|
1407 | + $request->setQueryParam("rev", (string)$rev); |
|
1408 | + } |
|
1363 | 1409 | |
1364 | 1410 | return $this->send($request); |
1365 | 1411 | } |
@@ -1385,8 +1431,9 @@ discard block |
||
1385 | 1431 | $request = new Request(Request::GET_METHOD, $path); |
1386 | 1432 | |
1387 | 1433 | // In case we want retrieve a specific document revision. |
1388 | - if (!empty($rev)) |
|
1389 | - $request->setQueryParam("rev", (string)$rev); |
|
1434 | + if (!empty($rev)) { |
|
1435 | + $request->setQueryParam("rev", (string)$rev); |
|
1436 | + } |
|
1390 | 1437 | |
1391 | 1438 | return $this->send($request)->getBody(); |
1392 | 1439 | } |
@@ -1415,8 +1462,9 @@ discard block |
||
1415 | 1462 | $request->setBody(base64_encode($attachment->getData())); |
1416 | 1463 | |
1417 | 1464 | // In case of adding or updating an existence document. |
1418 | - if (!empty($rev)) |
|
1419 | - $request->setQueryParam("rev", (string)$rev); |
|
1465 | + if (!empty($rev)) { |
|
1466 | + $request->setQueryParam("rev", (string)$rev); |
|
1467 | + } |
|
1420 | 1468 | |
1421 | 1469 | return $this->send($request); |
1422 | 1470 | } |
@@ -36,8 +36,9 @@ discard block |
||
36 | 36 | * @attention Chainable. |
37 | 37 | */ |
38 | 38 | public function unsetOpt($name) { |
39 | - if (array_key_exists($name, $this->options)) |
|
40 | - unset($this->options['name']); |
|
39 | + if (array_key_exists($name, $this->options)) { |
|
40 | + unset($this->options['name']); |
|
41 | + } |
|
41 | 42 | |
42 | 43 | return $this; |
43 | 44 | } |
@@ -137,10 +138,11 @@ discard block |
||
137 | 138 | * @attention Chainable. |
138 | 139 | */ |
139 | 140 | public function setLimit($value) { |
140 | - if (is_int($value) && $value >= 0) |
|
141 | - $this->options["limit"] = $value; |
|
142 | - else |
|
143 | - throw new \Exception("\$value must be a non-negative integer."); |
|
141 | + if (is_int($value) && $value >= 0) { |
|
142 | + $this->options["limit"] = $value; |
|
143 | + } else { |
|
144 | + throw new \Exception("\$value must be a non-negative integer."); |
|
145 | + } |
|
144 | 146 | |
145 | 147 | return $this; |
146 | 148 | } |
@@ -173,9 +175,9 @@ discard block |
||
173 | 175 | if (is_int($value) && $value > 0) { |
174 | 176 | $this->options["group"] = "false"; // This parameter is used only if 'group' is 'false'. |
175 | 177 | $this->options["group_level"] = $value; |
178 | + } else { |
|
179 | + throw new \Exception("\$value must be a positive integer."); |
|
176 | 180 | } |
177 | - else |
|
178 | - throw new \Exception("\$value must be a positive integer."); |
|
179 | 181 | |
180 | 182 | return $this; |
181 | 183 | } |
@@ -311,10 +313,11 @@ discard block |
||
311 | 313 | * @attention Chainable. |
312 | 314 | */ |
313 | 315 | public function skipDocs($number) { |
314 | - if (is_int($number) && $number > 0) |
|
315 | - $this->options["skip"] = $number; |
|
316 | - else |
|
317 | - throw new \Exception("\$number must be a positive integer."); |
|
316 | + if (is_int($number) && $number > 0) { |
|
317 | + $this->options["skip"] = $number; |
|
318 | + } else { |
|
319 | + throw new \Exception("\$number must be a positive integer."); |
|
320 | + } |
|
318 | 321 | |
319 | 322 | return $this; |
320 | 323 | } |
@@ -423,13 +423,15 @@ discard block |
||
423 | 423 | */ |
424 | 424 | protected function parseStatusCode($rawMessage) { |
425 | 425 | $matches = []; |
426 | - if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) |
|
427 | - $this->statusCode = $matches[1]; |
|
428 | - else |
|
429 | - throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
426 | + if (preg_match('%HTTP/1\.[0-1] (\d\d\d) %', $rawMessage, $matches)) { |
|
427 | + $this->statusCode = $matches[1]; |
|
428 | + } else { |
|
429 | + throw new \UnexpectedValueException("HTTP Status Code undefined."); |
|
430 | + } |
|
430 | 431 | |
431 | - if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) |
|
432 | - throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
432 | + if (!array_key_exists($this->statusCode, self::$supportedStatusCodes)) { |
|
433 | + throw new \UnexpectedValueException("HTTP Status Code unknown."); |
|
434 | + } |
|
433 | 435 | } |
434 | 436 | |
435 | 437 | |
@@ -449,10 +451,11 @@ discard block |
||
449 | 451 | }, |
450 | 452 | strtolower(trim($matches[1]))); |
451 | 453 | |
452 | - if (isset($this->header[$matches[1]])) |
|
453 | - $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
454 | - else |
|
455 | - $this->header[$matches[1]] = trim($matches[2]); |
|
454 | + if (isset($this->header[$matches[1]])) { |
|
455 | + $this->header[$matches[1]] = array($this->header[$matches[1]], $matches[2]); |
|
456 | + } else { |
|
457 | + $this->header[$matches[1]] = trim($matches[2]); |
|
458 | + } |
|
456 | 459 | } |
457 | 460 | } |
458 | 461 | } |
@@ -463,11 +466,13 @@ discard block |
||
463 | 466 | * @param[in] string $rawMessage The raw message. |
464 | 467 | */ |
465 | 468 | protected function parseStatusCodeAndHeader($rawMessage) { |
466 | - if (!is_string($rawMessage)) |
|
467 | - throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
469 | + if (!is_string($rawMessage)) { |
|
470 | + throw new \InvalidArgumentException("\$rawMessage must be a string."); |
|
471 | + } |
|
468 | 472 | |
469 | - if (empty($rawMessage)) |
|
470 | - throw new \UnexpectedValueException("\$rawMessage is null."); |
|
473 | + if (empty($rawMessage)) { |
|
474 | + throw new \UnexpectedValueException("\$rawMessage is null."); |
|
475 | + } |
|
471 | 476 | |
472 | 477 | $this->parseStatusCode($rawMessage); |
473 | 478 | |
@@ -481,8 +486,9 @@ discard block |
||
481 | 486 | |
482 | 487 | $rawMessage = preg_split('/\r\n\r\n/', $rawMessage, 2); |
483 | 488 | |
484 | - if (empty($rawMessage)) |
|
485 | - throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
489 | + if (empty($rawMessage)) { |
|
490 | + throw new \RuntimeException("The server didn't return a valid Response for the Request."); |
|
491 | + } |
|
486 | 492 | |
487 | 493 | // $rawMessage[0] contains header fields. |
488 | 494 | $this->parseHeaderFields($rawMessage[0]); |
@@ -508,9 +514,9 @@ discard block |
||
508 | 514 | public function setStatusCode($value) { |
509 | 515 | if (array_key_exists($value, self::$supportedStatusCodes)) { |
510 | 516 | $this->statusCode = $value; |
517 | + } else { |
|
518 | + throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
511 | 519 | } |
512 | - else |
|
513 | - throw new \UnexpectedValueException("Status Code $value is not supported."); |
|
514 | 520 | } |
515 | 521 | |
516 | 522 | |
@@ -529,12 +535,13 @@ discard block |
||
529 | 535 | * @param[in] string $description A description for the Status Code. |
530 | 536 | */ |
531 | 537 | public static function addCustomStatusCode($code, $description) { |
532 | - if (in_array($code, self::$supportedStatusCodes)) |
|
533 | - throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
534 | - elseif (is_int($code) and $code > 0) |
|
535 | - self::$supportedStatusCodes[$code] = $description; |
|
536 | - else |
|
537 | - throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
538 | + if (in_array($code, self::$supportedStatusCodes)) { |
|
539 | + throw new \UnexpectedValueException("Status Code $code is supported and already exists."); |
|
540 | + } elseif (is_int($code) and $code > 0) { |
|
541 | + self::$supportedStatusCodes[$code] = $description; |
|
542 | + } else { |
|
543 | + throw new \InvalidArgumentException("\$code must be a positive integer."); |
|
544 | + } |
|
538 | 545 | } |
539 | 546 | |
540 | 547 | } |
541 | 548 | \ No newline at end of file |