@@ -208,81 +208,98 @@ discard block |
||
| 208 | 208 | $args = $input->getArgument('keys'); |
| 209 | 209 | |
| 210 | 210 | $keys = []; |
| 211 | - foreach ($args as $key) |
|
| 212 | - $keys[] = $this->castArg($key, FALSE); |
|
| 211 | + foreach ($args as $key) { |
|
| 212 | + $keys[] = $this->castArg($key, FALSE); |
|
| 213 | + } |
|
| 214 | + } else { |
|
| 215 | + $keys = NULL; |
|
| 213 | 216 | } |
| 214 | - else |
|
| 215 | - $keys = NULL; |
|
| 216 | 217 | |
| 217 | 218 | // Sets the options. |
| 218 | 219 | $opts = new ViewQueryOpts(); |
| 219 | 220 | |
| 220 | 221 | // Key. |
| 221 | - if ($key = $input->getOption('key')) |
|
| 222 | - $opts->setKey($this->castArg($key)); |
|
| 222 | + if ($key = $input->getOption('key')) { |
|
| 223 | + $opts->setKey($this->castArg($key)); |
|
| 224 | + } |
|
| 223 | 225 | |
| 224 | 226 | // Start key. |
| 225 | - if ($startkey = $input->getOption('startkey')) |
|
| 226 | - $opts->setStartKey($this->castArg($startkey)); |
|
| 227 | + if ($startkey = $input->getOption('startkey')) { |
|
| 228 | + $opts->setStartKey($this->castArg($startkey)); |
|
| 229 | + } |
|
| 227 | 230 | |
| 228 | 231 | // End key. |
| 229 | - if ($endkey = $input->getOption('endkey')) |
|
| 230 | - $opts->setEndKey($this->castArg($endkey)); |
|
| 232 | + if ($endkey = $input->getOption('endkey')) { |
|
| 233 | + $opts->setEndKey($this->castArg($endkey)); |
|
| 234 | + } |
|
| 231 | 235 | |
| 232 | 236 | // Start doc id. |
| 233 | - if ($docId = $input->getOption('startkey-docid')) |
|
| 234 | - $opts->setStartDocId($docId); |
|
| 237 | + if ($docId = $input->getOption('startkey-docid')) { |
|
| 238 | + $opts->setStartDocId($docId); |
|
| 239 | + } |
|
| 235 | 240 | |
| 236 | 241 | // End doc id. |
| 237 | - if ($docId = $input->getOption('endkey-docid')) |
|
| 238 | - $opts->setEndDocId($docId); |
|
| 242 | + if ($docId = $input->getOption('endkey-docid')) { |
|
| 243 | + $opts->setEndDocId($docId); |
|
| 244 | + } |
|
| 239 | 245 | |
| 240 | 246 | // Limit. |
| 241 | 247 | $limit = (int)$input->getOption('limit'); |
| 242 | - if ($limit > 0) |
|
| 243 | - $opts->setLimit($limit); |
|
| 248 | + if ($limit > 0) { |
|
| 249 | + $opts->setLimit($limit); |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Group results. |
| 246 | - if ($input->getOption('group-results')) |
|
| 247 | - $opts->groupResults(); |
|
| 253 | + if ($input->getOption('group-results')) { |
|
| 254 | + $opts->groupResults(); |
|
| 255 | + } |
|
| 248 | 256 | |
| 249 | 257 | // Sets group level. |
| 250 | 258 | $level = (int)$input->getOption('group-level'); |
| 251 | - if ($level > 0) |
|
| 252 | - $opts->setGroupLevel($level); |
|
| 259 | + if ($level > 0) { |
|
| 260 | + $opts->setGroupLevel($level); |
|
| 261 | + } |
|
| 253 | 262 | |
| 254 | 263 | // Do not reduce. |
| 255 | - if ($input->getOption('do-not-reduce')) |
|
| 256 | - $opts->doNotReduce(); |
|
| 264 | + if ($input->getOption('do-not-reduce')) { |
|
| 265 | + $opts->doNotReduce(); |
|
| 266 | + } |
|
| 257 | 267 | |
| 258 | 268 | // Includes docs. |
| 259 | - if ($input->getOption('include-docs')) |
|
| 260 | - $opts->includeDocs(); |
|
| 269 | + if ($input->getOption('include-docs')) { |
|
| 270 | + $opts->includeDocs(); |
|
| 271 | + } |
|
| 261 | 272 | |
| 262 | 273 | // Excludes results. |
| 263 | - if ($input->getOption('exclude-results')) |
|
| 264 | - $opts->excludeResults(); |
|
| 274 | + if ($input->getOption('exclude-results')) { |
|
| 275 | + $opts->excludeResults(); |
|
| 276 | + } |
|
| 265 | 277 | |
| 266 | 278 | // Excludes endkey. |
| 267 | - if ($input->getOption('exclude-endkey')) |
|
| 268 | - $opts->excludeEndKey(); |
|
| 279 | + if ($input->getOption('exclude-endkey')) { |
|
| 280 | + $opts->excludeEndKey(); |
|
| 281 | + } |
|
| 269 | 282 | |
| 270 | 283 | // Reverses order of results. |
| 271 | - if ($input->getOption('reverse-order')) |
|
| 272 | - $opts->reverseOrderOfResults(); |
|
| 284 | + if ($input->getOption('reverse-order')) { |
|
| 285 | + $opts->reverseOrderOfResults(); |
|
| 286 | + } |
|
| 273 | 287 | |
| 274 | 288 | // Skips the defined number of documents. |
| 275 | 289 | $skip = (int)$input->getOption('skip'); |
| 276 | - if ($skip > 0) |
|
| 277 | - $opts->skipDocs($skip); |
|
| 290 | + if ($skip > 0) { |
|
| 291 | + $opts->skipDocs($skip); |
|
| 292 | + } |
|
| 278 | 293 | |
| 279 | 294 | // Includes conflicts. |
| 280 | - if ($input->getOption('include-conflicts')) |
|
| 281 | - $opts->includeConflicts(); |
|
| 295 | + if ($input->getOption('include-conflicts')) { |
|
| 296 | + $opts->includeConflicts(); |
|
| 297 | + } |
|
| 282 | 298 | |
| 283 | 299 | // Includes missing keys. |
| 284 | - if ($input->getOption('include-missing-keys')) |
|
| 285 | - $opts->includeMissingKeys(); |
|
| 300 | + if ($input->getOption('include-missing-keys')) { |
|
| 301 | + $opts->includeMissingKeys(); |
|
| 302 | + } |
|
| 286 | 303 | |
| 287 | 304 | if ($view == "_temp_view") { |
| 288 | 305 | |
@@ -290,30 +307,31 @@ discard block |
||
| 290 | 307 | if ($fileName = $input->getOption('map')) { |
| 291 | 308 | $map = file_get_contents($fileName); |
| 292 | 309 | |
| 293 | - if ($fileName = $input->getOption('reduce')) |
|
| 294 | - $reduce = file_get_contents($fileName); |
|
| 295 | - else |
|
| 296 | - $reduce = ""; |
|
| 310 | + if ($fileName = $input->getOption('reduce')) { |
|
| 311 | + $reduce = file_get_contents($fileName); |
|
| 312 | + } else { |
|
| 313 | + $reduce = ""; |
|
| 314 | + } |
|
| 297 | 315 | |
| 298 | 316 | $language = $input->getOption('language'); |
| 299 | - if (empty($language)) |
|
| 300 | - $language = "php"; |
|
| 317 | + if (empty($language)) { |
|
| 318 | + $language = "php"; |
|
| 319 | + } |
|
| 320 | + } else { |
|
| 321 | + throw new \InvalidArgumentException("You didn't provided the map function."); |
|
| 301 | 322 | } |
| 302 | - else |
|
| 303 | - throw new \InvalidArgumentException("You didn't provided the map function."); |
|
| 304 | 323 | |
| 305 | 324 | print_r($couch->queryTempView($map, $reduce, $keys, $opts, $language)); |
| 306 | - } |
|
| 307 | - elseif ($view == "_all_docs") { |
|
| 325 | + } elseif ($view == "_all_docs") { |
|
| 308 | 326 | print_r($couch->queryAllDocs($keys, $opts)); |
| 309 | - } |
|
| 310 | - else { |
|
| 327 | + } else { |
|
| 311 | 328 | $names = explode('/', $view, 2); |
| 312 | 329 | |
| 313 | - if (count($names) == 2) |
|
| 314 | - var_dump($couch->queryView($names[0], $names[1], $keys, $opts)); |
|
| 315 | - else |
|
| 316 | - throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
| 330 | + if (count($names) == 2) { |
|
| 331 | + var_dump($couch->queryView($names[0], $names[1], $keys, $opts)); |
|
| 332 | + } else { |
|
| 333 | + throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
| 334 | + } |
|
| 317 | 335 | } |
| 318 | 336 | |
| 319 | 337 | } |