@@ -189,6 +189,9 @@ |
||
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); |
@@ -63,8 +63,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -162,6 +162,11 @@ discard block |
||
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 |
||
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); |
@@ -67,29 +67,29 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -131,17 +131,18 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -266,6 +266,7 @@ discard block |
||
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 |
||
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")); |
@@ -189,9 +189,9 @@ discard block |
||
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 |
||
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 | } |
@@ -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 |
@@ -45,10 +45,11 @@ |
||
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 |
@@ -100,8 +100,8 @@ |
||
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'; |
@@ -82,9 +82,9 @@ |
||
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 |
@@ -908,7 +908,7 @@ |
||
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)) { |
@@ -35,8 +35,8 @@ discard block |
||
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 | |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * @see http://docs.couchdb.org/en/latest/api/database/compact.html#db-view-cleanup |
663 | 663 | */ |
664 | 664 | public function cleanupViews($dbName) { |
665 | - $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_view_cleanup"); |
|
665 | + $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_view_cleanup"); |
|
666 | 666 | |
667 | 667 | // A POST method requires Content-Type header. |
668 | 668 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -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 | } |
@@ -17,7 +17,7 @@ |
||
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 |
@@ -25,8 +25,9 @@ |
||
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 |
@@ -59,10 +59,11 @@ |
||
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 |
@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | $instance = new self(); |
42 | 42 | |
43 | 43 | if (file_exists($fileName)) { |
44 | - if (is_dir($fileName)) |
|
45 | - throw new \Exception("The file $fileName is a directory."); |
|
44 | + if (is_dir($fileName)) { |
|
45 | + throw new \Exception("The file $fileName is a directory."); |
|
46 | + } |
|
46 | 47 | |
47 | 48 | $instance->name = basename($fileName); |
48 | 49 | |
@@ -58,14 +59,15 @@ discard block |
||
58 | 59 | finfo_close($finfo); |
59 | 60 | fclose($fd); |
60 | 61 | |
61 | - if ($instance->data === FALSE) |
|
62 | - throw new \Exception("Error reading the file $fileName."); |
|
62 | + if ($instance->data === FALSE) { |
|
63 | + throw new \Exception("Error reading the file $fileName."); |
|
64 | + } |
|
65 | + } else { |
|
66 | + throw new \Exception("Cannot open the file $fileName."); |
|
63 | 67 | } |
64 | - else |
|
65 | - throw new \Exception("Cannot open the file $fileName."); |
|
68 | + } else { |
|
69 | + throw new \Exception("The file $fileName doesn't exist."); |
|
66 | 70 | } |
67 | - else |
|
68 | - throw new \Exception("The file $fileName doesn't exist."); |
|
69 | 71 | |
70 | 72 | return $instance; |
71 | 73 | } |
@@ -101,11 +103,12 @@ discard block |
||
101 | 103 | $bytes = fwrite($fd, $this->data); |
102 | 104 | fclose($fd); |
103 | 105 | |
104 | - if ($bytes === FALSE) |
|
105 | - throw new \Exception("Error writing the file `$this->name`."); |
|
106 | + if ($bytes === FALSE) { |
|
107 | + throw new \Exception("Error writing the file `$this->name`."); |
|
108 | + } |
|
109 | + } else { |
|
110 | + throw new \Exception("Cannot create the file `$this->name`."); |
|
106 | 111 | } |
107 | - else |
|
108 | - throw new \Exception("Cannot create the file `$this->name`."); |
|
109 | 112 | } |
110 | 113 | |
111 | 114 |