Completed
Push — master ( 9aba75...1de340 )
by Filippo
02:17
created
src/EoC/CLI/Command/QueryCommand.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@
 block discarded – undo
15 15
 use Symfony\Component\Console\Input\InputOption;
16 16
 use Symfony\Component\Console\Input\InputInterface;
17 17
 use Symfony\Component\Console\Output\OutputInterface;
18
-
19 18
 use EoC\Opt\ViewQueryOpts;
20 19
 
21 20
 
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
     %i - the argument is treated as an integer.
59 59
     %f - the argument is treated as a float.
60 60
 DESC
61
-   );
61
+    );
62 62
 
63 63
     // General options.
64 64
     $this->addOption("key",
Please login to merge, or discard this patch.
Braces   +70 added lines, -52 removed lines patch added patch discarded remove patch
@@ -208,81 +208,98 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
   }
Please login to merge, or discard this patch.
src/EoC/CLI/Command/UseCommand.php 1 patch
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -45,20 +45,21 @@
 block discarded – undo
45 45
 
46 46
     if ($shmKey = ftok($_SERVER['PHP_SELF'], 'd')) {
47 47
 
48
-      if (@$shmId = shmop_open($shmKey, 'a', 0644, 0))
49
-        shmop_delete($shmId);
48
+      if (@$shmId = shmop_open($shmKey, 'a', 0644, 0)) {
49
+              shmop_delete($shmId);
50
+      }
50 51
 
51 52
       $shmId = shmop_open($shmKey, 'n', 0644, mb_strlen($database));
52 53
 
53 54
       if ($shmId) {
54 55
         $shmBytesWritten = shmop_write($shmId, $database, 0);
55 56
         shmop_close($shmId);
57
+      } else {
58
+              throw new \RuntimeException("Couldn't create shared memory segment.");
56 59
       }
57
-      else
58
-        throw new \RuntimeException("Couldn't create shared memory segment.");
60
+    } else {
61
+          throw new \RuntimeException("Cannot get a System V IPC key.");
59 62
     }
60
-    else
61
-      throw new \RuntimeException("Cannot get a System V IPC key.");
62 63
   }
63 64
 
64 65
 }
65 66
\ No newline at end of file
Please login to merge, or discard this patch.
src/EoC/CLI/Command/AllDbsCommand.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@
 block discarded – undo
41 41
     $couch = $this->getConnection();
42 42
 
43 43
     $dbs = $couch->getAllDbs();
44
-    foreach ($dbs as $db)
45
-      echo $db.PHP_EOL;
44
+    foreach ($dbs as $db) {
45
+          echo $db.PHP_EOL;
46
+    }
46 47
   }
47 48
 
48 49
 }
49 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/EoC/CLI/Command/ConnectCommand.php 2 patches
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -74,26 +74,28 @@
 block discarded – undo
74 74
 
75 75
     // We reset the database in use.
76 76
     if ($shmKey = ftok($_SERVER['PHP_SELF'], 'd')) {
77
-      if (@$shmId = shmop_open($shmKey, "a", 0644, 0))
78
-        shmop_delete($shmId);
77
+      if (@$shmId = shmop_open($shmKey, "a", 0644, 0)) {
78
+              shmop_delete($shmId);
79
+      }
79 80
     }
80 81
 
81 82
     if ($shmKey = ftok($_SERVER['PHP_SELF'], 'c')) {
82 83
 
83
-      if (@$shmId = shmop_open($shmKey, 'a', 0644, 0))
84
-        shmop_delete($shmId);
84
+      if (@$shmId = shmop_open($shmKey, 'a', 0644, 0)) {
85
+              shmop_delete($shmId);
86
+      }
85 87
 
86 88
       $shmId = shmop_open($shmKey, 'n', 0644, mb_strlen($serialized));
87 89
 
88 90
       if ($shmId) {
89 91
         $shmBytesWritten = shmop_write($shmId, $serialized, 0);
90 92
         shmop_close($shmId);
93
+      } else {
94
+              throw new \RuntimeException("Couldn't create shared memory segment.");
91 95
       }
92
-      else
93
-        throw new \RuntimeException("Couldn't create shared memory segment.");
96
+    } else {
97
+          throw new \RuntimeException("Cannot get a System V IPC key.");
94 98
     }
95
-    else
96
-      throw new \RuntimeException("Cannot get a System V IPC key.");
97 99
   }
98 100
 
99 101
 }
100 102
\ No newline at end of file
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@
 block discarded – undo
15 15
 use Symfony\Component\Console\Input\InputOption;
16 16
 use Symfony\Component\Console\Input\InputInterface;
17 17
 use Symfony\Component\Console\Output\OutputInterface;
18
-
19 18
 use EoC\Opt\ViewQueryOpts;
20 19
 
21 20
 
Please login to merge, or discard this patch.
src/EoC/CLI/Command/CompactCommand.php 1 patch
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,10 +44,11 @@
 block discarded – undo
44 44
     $couch = $this->getConnection();
45 45
     $couch->selectDb($this->getDatabase());
46 46
 
47
-    if ($designDoc = $input->getOption('design-doc'))
48
-      $couch->compactView($designDoc);
49
-    else
50
-      $couch->compactDb();
47
+    if ($designDoc = $input->getOption('design-doc')) {
48
+          $couch->compactView($designDoc);
49
+    } else {
50
+          $couch->compactDb();
51
+    }
51 52
   }
52 53
 
53 54
 }
54 55
\ No newline at end of file
Please login to merge, or discard this patch.
src/EoC/CLI/Command/AbstractCommand.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,6 @@
 block discarded – undo
15 15
 use Symfony\Component\Console\Input\InputOption;
16 16
 use Symfony\Component\Console\Input\InputInterface;
17 17
 use Symfony\Component\Console\Output\OutputInterface;
18
-
19 18
 use EoC\Opt\ViewQueryOpts;
20 19
 
21 20
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@
 block discarded – undo
128 128
     elseif ($this->isFormatted($arg))
129 129
       return $arg;
130 130
     else
131
-      return (string)$arg ;
131
+      return (string)$arg;
132 132
   }
133 133
 
134 134
 
Please login to merge, or discard this patch.
Braces   +29 added lines, -26 removed lines patch added patch discarded remove patch
@@ -39,10 +39,11 @@  discard block
 block discarded – undo
39 39
    * @return bool
40 40
    */
41 41
   protected function isArray($arg) {
42
-    if (preg_match('/\A[\[]([^\[\]]+)[\]]\z/i', $arg, $matches))
43
-      return TRUE;
44
-    else
45
-      return FALSE;
42
+    if (preg_match('/\A[\[]([^\[\]]+)[\]]\z/i', $arg, $matches)) {
43
+          return TRUE;
44
+    } else {
45
+          return FALSE;
46
+    }
46 47
   }
47 48
 
48 49
 
@@ -94,8 +95,7 @@  discard block
 block discarded – undo
94 95
       }
95 96
 
96 97
       return TRUE;
97
-    }
98
-    else {
98
+    } else {
99 99
       return FALSE;
100 100
     }
101 101
   }
@@ -117,18 +117,19 @@  discard block
 block discarded – undo
117 117
 
118 118
       $argument = [];
119 119
       foreach ($values as $value) {
120
-        if ($this->isFormatted($value))
121
-          $argument[] = $value;
122
-        else
123
-          $argument[] = (string)$value;
120
+        if ($this->isFormatted($value)) {
121
+                  $argument[] = $value;
122
+        } else {
123
+                  $argument[] = (string)$value;
124
+        }
124 125
       }
125 126
 
126 127
       return $argument;
128
+    } elseif ($this->isFormatted($arg)) {
129
+          return $arg;
130
+    } else {
131
+          return (string)$arg ;
127 132
     }
128
-    elseif ($this->isFormatted($arg))
129
-      return $arg;
130
-    else
131
-      return (string)$arg ;
132 133
   }
133 134
 
134 135
 
@@ -144,15 +145,16 @@  discard block
 block discarded – undo
144 145
       $shmSize = shmop_size($shmId);
145 146
 
146 147
       // Now lets read the memory segment.
147
-      if ($buffer = shmop_read($shmId, 0, $shmSize))
148
-        $connection = unserialize($buffer);
149
-      else
150
-        throw new \RuntimeException("You are not connected to the server.");
148
+      if ($buffer = shmop_read($shmId, 0, $shmSize)) {
149
+              $connection = unserialize($buffer);
150
+      } else {
151
+              throw new \RuntimeException("You are not connected to the server.");
152
+      }
151 153
 
152 154
       shmop_close($shmId);
155
+    } else {
156
+          throw new \RuntimeException("You are not connected to the server.");
153 157
     }
154
-    else
155
-      throw new \RuntimeException("You are not connected to the server.");
156 158
 
157 159
     return new Couch(new CurlAdapter($connection['server'], $connection['user'], $connection['password']));
158 160
   }
@@ -170,15 +172,16 @@  discard block
 block discarded – undo
170 172
       $shmSize = shmop_size($shmId);
171 173
 
172 174
       // Now lets read the memory segment.
173
-      if ($buffer = shmop_read($shmId, 0, $shmSize))
174
-        $database = $buffer;
175
-      else
176
-        throw new \RuntimeException("No database selected.");
175
+      if ($buffer = shmop_read($shmId, 0, $shmSize)) {
176
+              $database = $buffer;
177
+      } else {
178
+              throw new \RuntimeException("No database selected.");
179
+      }
177 180
 
178 181
       shmop_close($shmId);
182
+    } else {
183
+          throw new \RuntimeException("No database selected.");
179 184
     }
180
-    else
181
-      throw new \RuntimeException("No database selected.");
182 185
 
183 186
     return $database;
184 187
   }
Please login to merge, or discard this patch.
src/EoC/CLI/Command/DeleteCommand.php 1 patch
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,15 +48,15 @@
 block discarded – undo
48 48
     // In case there is a database in use, we select it, because you the selected database can't be deleted.
49 49
     try {
50 50
       $couch->selectDb($this->getDatabase());
51
-    }
52
-    catch (\RuntimeException $e) {}
51
+    } catch (\RuntimeException $e) {}
53 52
 
54 53
     $question = new ConfirmationQuestion('Are you sure you want delete the database? [Y/n]', FALSE);
55 54
 
56 55
     $helper = $this->getHelper('question');
57 56
 
58
-    if ($helper->ask($input, $output, $question))
59
-      $couch->deleteDb($database);
57
+    if ($helper->ask($input, $output, $question)) {
58
+          $couch->deleteDb($database);
59
+    }
60 60
   }
61 61
 
62 62
 }
63 63
\ No newline at end of file
Please login to merge, or discard this patch.