Completed
Push — master ( a6612e...d54d1c )
by Filippo
06:58 queued 04:31
created
src/EoC/CLI/Command/QueryCommand.php 2 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.
Braces   +70 added lines, -52 removed lines patch added patch discarded remove patch
@@ -188,81 +188,98 @@  discard block
 block discarded – undo
188 188
       $args = $input->getArgument('keys');
189 189
 
190 190
       $keys = [];
191
-      foreach ($args as $key)
192
-        $keys[] = $this->castArg($key, FALSE);
191
+      foreach ($args as $key) {
192
+              $keys[] = $this->castArg($key, FALSE);
193
+      }
194
+    } else {
195
+          $keys = NULL;
193 196
     }
194
-    else
195
-      $keys = NULL;
196 197
 
197 198
     // Sets the options.
198 199
     $opts = new ViewQueryOpts();
199 200
 
200 201
     // Key.
201
-    if ($key = $input->getOption('key'))
202
-      $opts->setKey($this->castArg($key), FALSE);
202
+    if ($key = $input->getOption('key')) {
203
+          $opts->setKey($this->castArg($key), FALSE);
204
+    }
203 205
 
204 206
     // Start key.
205
-    if ($startkey = $input->getOption('startkey'))
206
-      $opts->setStartKey($this->castArg($startkey), FALSE);
207
+    if ($startkey = $input->getOption('startkey')) {
208
+          $opts->setStartKey($this->castArg($startkey), FALSE);
209
+    }
207 210
 
208 211
     // End key.
209
-    if ($endkey = $input->getOption('endkey'))
210
-      $opts->setEndKey($this->castArg($endkey), FALSE);
212
+    if ($endkey = $input->getOption('endkey')) {
213
+          $opts->setEndKey($this->castArg($endkey), FALSE);
214
+    }
211 215
 
212 216
     // Start doc id.
213
-    if ($docId = $input->getOption('startkey-docid'))
214
-      $opts->setStartDocId($docId);
217
+    if ($docId = $input->getOption('startkey-docid')) {
218
+          $opts->setStartDocId($docId);
219
+    }
215 220
 
216 221
     // End doc id.
217
-    if ($docId = $input->getOption('endkey-docid'))
218
-      $opts->setEndDocId($docId);
222
+    if ($docId = $input->getOption('endkey-docid')) {
223
+          $opts->setEndDocId($docId);
224
+    }
219 225
 
220 226
     // Limit.
221 227
     $limit = (int)$input->getOption('limit');
222
-    if ($limit > 0)
223
-      $opts->setLimit($limit);
228
+    if ($limit > 0) {
229
+          $opts->setLimit($limit);
230
+    }
224 231
 
225 232
     // Group results.
226
-    if ($input->getOption('group-results'))
227
-      $opts->groupResults();
233
+    if ($input->getOption('group-results')) {
234
+          $opts->groupResults();
235
+    }
228 236
 
229 237
     // Sets group level.
230 238
     $level = (int)$input->getOption('group-level');
231
-    if ($level > 0)
232
-      $opts->setGroupLevel($level);
239
+    if ($level > 0) {
240
+          $opts->setGroupLevel($level);
241
+    }
233 242
 
234 243
     // Do not reduce.
235
-    if ($input->getOption('do-not-reduce'))
236
-      $opts->doNotReduce();
244
+    if ($input->getOption('do-not-reduce')) {
245
+          $opts->doNotReduce();
246
+    }
237 247
 
238 248
     // Includes docs.
239
-    if ($input->getOption('include-docs'))
240
-      $opts->includeDocs();
249
+    if ($input->getOption('include-docs')) {
250
+          $opts->includeDocs();
251
+    }
241 252
 
242 253
     // Excludes results.
243
-    if ($input->getOption('exclude-results'))
244
-      $opts->excludeResults();
254
+    if ($input->getOption('exclude-results')) {
255
+          $opts->excludeResults();
256
+    }
245 257
 
246 258
     // Excludes endkey.
247
-    if ($input->getOption('exclude-endkey'))
248
-      $opts->excludeEndKey();
259
+    if ($input->getOption('exclude-endkey')) {
260
+          $opts->excludeEndKey();
261
+    }
249 262
 
250 263
     // Reverses order of results.
251
-    if ($input->getOption('reverse-order'))
252
-      $opts->reverseOrderOfResults();
264
+    if ($input->getOption('reverse-order')) {
265
+          $opts->reverseOrderOfResults();
266
+    }
253 267
 
254 268
     // Skips the defined number of documents.
255 269
     $skip = (int)$input->getOption('skip');
256
-    if ($skip > 0)
257
-      $opts->skipDocs($skip);
270
+    if ($skip > 0) {
271
+          $opts->skipDocs($skip);
272
+    }
258 273
 
259 274
     // Includes conflicts.
260
-    if ($input->getOption('include-conflicts'))
261
-      $opts->includeConflicts();
275
+    if ($input->getOption('include-conflicts')) {
276
+          $opts->includeConflicts();
277
+    }
262 278
 
263 279
     // Includes missing keys.
264
-    if ($input->getOption('include-missing-keys'))
265
-      $opts->includeMissingKeys();
280
+    if ($input->getOption('include-missing-keys')) {
281
+          $opts->includeMissingKeys();
282
+    }
266 283
 
267 284
     if ($view == "_temp_view") {
268 285
 
@@ -270,30 +287,31 @@  discard block
 block discarded – undo
270 287
       if ($fileName = $input->getOption('map')) {
271 288
         $map = file_get_contents($fileName);
272 289
 
273
-        if ($fileName = $input->getOption('reduce'))
274
-          $reduce = file_get_contents($fileName);
275
-        else
276
-          $reduce = "";
290
+        if ($fileName = $input->getOption('reduce')) {
291
+                  $reduce = file_get_contents($fileName);
292
+        } else {
293
+                  $reduce = "";
294
+        }
277 295
 
278 296
         $language = $input->getOption('language');
279
-        if (empty($language))
280
-          $language = "php";
297
+        if (empty($language)) {
298
+                  $language = "php";
299
+        }
300
+      } else {
301
+              throw new \InvalidArgumentException("You have to specify map, reduce and language options.");
281 302
       }
282
-      else
283
-        throw new \InvalidArgumentException("You have to specify map, reduce and language options.");
284 303
 
285 304
       print_r($couch->queryTempView($map, $reduce, $keys, $opts, $language));
286
-    }
287
-    elseif ($view == "_all_docs") {
305
+    } elseif ($view == "_all_docs") {
288 306
       print_r($couch->queryAllDocs($keys, $opts));
289
-    }
290
-    else {
307
+    } else {
291 308
       $names = explode('/', $view, 2);
292 309
 
293
-      if (count($names) == 2)
294
-        var_dump($couch->queryView($names[0], $names[1], $keys, $opts));
295
-      else
296
-        throw new \InvalidArgumentException("You have to specify design-doc/view-name.");
310
+      if (count($names) == 2) {
311
+              var_dump($couch->queryView($names[0], $names[1], $keys, $opts));
312
+      } else {
313
+              throw new \InvalidArgumentException("You have to specify design-doc/view-name.");
314
+      }
297 315
     }
298 316
 
299 317
   }
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 2 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.
Braces   +30 added lines, -27 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
   }
@@ -109,16 +109,17 @@  discard block
 block discarded – undo
109 109
    */
110 110
   protected function castArg($arg, $encode = TRUE) {
111 111
     echo "Original argument: ".$arg.PHP_EOL;
112
-    if ($this->isArray($arg))
113
-      return $arg;
114
-    elseif ($this->isFormatted($arg)) {
115
-      if ($encode)
116
-        return json_encode($arg);
117
-      else
118
-        return $arg;
112
+    if ($this->isArray($arg)) {
113
+          return $arg;
114
+    } elseif ($this->isFormatted($arg)) {
115
+      if ($encode) {
116
+              return json_encode($arg);
117
+      } else {
118
+              return $arg;
119
+      }
120
+    } else {
121
+          return $arg + 0;
119 122
     }
120
-    else
121
-      return $arg + 0;
122 123
   }
123 124
 
124 125
 
@@ -134,15 +135,16 @@  discard block
 block discarded – undo
134 135
       $shmSize = shmop_size($shmId);
135 136
 
136 137
       // Now lets read the memory segment.
137
-      if ($buffer = shmop_read($shmId, 0, $shmSize))
138
-        $connection = unserialize($buffer);
139
-      else
140
-        throw new \RuntimeException("You are not connected to the server.");
138
+      if ($buffer = shmop_read($shmId, 0, $shmSize)) {
139
+              $connection = unserialize($buffer);
140
+      } else {
141
+              throw new \RuntimeException("You are not connected to the server.");
142
+      }
141 143
 
142 144
       shmop_close($shmId);
145
+    } else {
146
+          throw new \RuntimeException("You are not connected to the server.");
143 147
     }
144
-    else
145
-      throw new \RuntimeException("You are not connected to the server.");
146 148
 
147 149
     return new Couch(new CurlAdapter($connection['server'], $connection['user'], $connection['password']));
148 150
   }
@@ -160,15 +162,16 @@  discard block
 block discarded – undo
160 162
       $shmSize = shmop_size($shmId);
161 163
 
162 164
       // Now lets read the memory segment.
163
-      if ($buffer = shmop_read($shmId, 0, $shmSize))
164
-        $database = $buffer;
165
-      else
166
-        throw new \RuntimeException("No database selected.");
165
+      if ($buffer = shmop_read($shmId, 0, $shmSize)) {
166
+              $database = $buffer;
167
+      } else {
168
+              throw new \RuntimeException("No database selected.");
169
+      }
167 170
 
168 171
       shmop_close($shmId);
172
+    } else {
173
+          throw new \RuntimeException("No database selected.");
169 174
     }
170
-    else
171
-      throw new \RuntimeException("No database selected.");
172 175
 
173 176
     return $database;
174 177
   }
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.