@@ -14,7 +14,6 @@ |
||
14 | 14 | |
15 | 15 | use EoC\Adapter\CurlAdapter; |
16 | 16 | use EoC\Couch; |
17 | - |
|
18 | 17 | use Symfony\Component\Console\Command\Command; |
19 | 18 | |
20 | 19 |
@@ -128,7 +128,7 @@ |
||
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 |
@@ -39,10 +39,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -15,7 +15,6 @@ |
||
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 |
@@ -58,7 +58,7 @@ |
||
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", |
@@ -207,81 +207,98 @@ discard block |
||
207 | 207 | $args = $input->getArgument('keys'); |
208 | 208 | |
209 | 209 | $keys = []; |
210 | - foreach ($args as $key) |
|
211 | - $keys[] = $this->castArg($key, FALSE); |
|
210 | + foreach ($args as $key) { |
|
211 | + $keys[] = $this->castArg($key, FALSE); |
|
212 | + } |
|
213 | + } else { |
|
214 | + $keys = NULL; |
|
212 | 215 | } |
213 | - else |
|
214 | - $keys = NULL; |
|
215 | 216 | |
216 | 217 | // Sets the options. |
217 | 218 | $opts = new ViewQueryOpts(); |
218 | 219 | |
219 | 220 | // Key. |
220 | - if ($key = $input->getOption('key')) |
|
221 | - $opts->setKey($this->castArg($key)); |
|
221 | + if ($key = $input->getOption('key')) { |
|
222 | + $opts->setKey($this->castArg($key)); |
|
223 | + } |
|
222 | 224 | |
223 | 225 | // Start key. |
224 | - if ($startkey = $input->getOption('startkey')) |
|
225 | - $opts->setStartKey($this->castArg($startkey)); |
|
226 | + if ($startkey = $input->getOption('startkey')) { |
|
227 | + $opts->setStartKey($this->castArg($startkey)); |
|
228 | + } |
|
226 | 229 | |
227 | 230 | // End key. |
228 | - if ($endkey = $input->getOption('endkey')) |
|
229 | - $opts->setEndKey($this->castArg($endkey)); |
|
231 | + if ($endkey = $input->getOption('endkey')) { |
|
232 | + $opts->setEndKey($this->castArg($endkey)); |
|
233 | + } |
|
230 | 234 | |
231 | 235 | // Start doc id. |
232 | - if ($docId = $input->getOption('startkey-docid')) |
|
233 | - $opts->setStartDocId($docId); |
|
236 | + if ($docId = $input->getOption('startkey-docid')) { |
|
237 | + $opts->setStartDocId($docId); |
|
238 | + } |
|
234 | 239 | |
235 | 240 | // End doc id. |
236 | - if ($docId = $input->getOption('endkey-docid')) |
|
237 | - $opts->setEndDocId($docId); |
|
241 | + if ($docId = $input->getOption('endkey-docid')) { |
|
242 | + $opts->setEndDocId($docId); |
|
243 | + } |
|
238 | 244 | |
239 | 245 | // Limit. |
240 | 246 | $limit = (int)$input->getOption('limit'); |
241 | - if ($limit > 0) |
|
242 | - $opts->setLimit($limit); |
|
247 | + if ($limit > 0) { |
|
248 | + $opts->setLimit($limit); |
|
249 | + } |
|
243 | 250 | |
244 | 251 | // Group results. |
245 | - if ($input->getOption('group-results')) |
|
246 | - $opts->groupResults(); |
|
252 | + if ($input->getOption('group-results')) { |
|
253 | + $opts->groupResults(); |
|
254 | + } |
|
247 | 255 | |
248 | 256 | // Sets group level. |
249 | 257 | $level = (int)$input->getOption('group-level'); |
250 | - if ($level > 0) |
|
251 | - $opts->setGroupLevel($level); |
|
258 | + if ($level > 0) { |
|
259 | + $opts->setGroupLevel($level); |
|
260 | + } |
|
252 | 261 | |
253 | 262 | // Do not reduce. |
254 | - if ($input->getOption('do-not-reduce')) |
|
255 | - $opts->doNotReduce(); |
|
263 | + if ($input->getOption('do-not-reduce')) { |
|
264 | + $opts->doNotReduce(); |
|
265 | + } |
|
256 | 266 | |
257 | 267 | // Includes docs. |
258 | - if ($input->getOption('include-docs')) |
|
259 | - $opts->includeDocs(); |
|
268 | + if ($input->getOption('include-docs')) { |
|
269 | + $opts->includeDocs(); |
|
270 | + } |
|
260 | 271 | |
261 | 272 | // Excludes results. |
262 | - if ($input->getOption('exclude-results')) |
|
263 | - $opts->excludeResults(); |
|
273 | + if ($input->getOption('exclude-results')) { |
|
274 | + $opts->excludeResults(); |
|
275 | + } |
|
264 | 276 | |
265 | 277 | // Excludes endkey. |
266 | - if ($input->getOption('exclude-endkey')) |
|
267 | - $opts->excludeEndKey(); |
|
278 | + if ($input->getOption('exclude-endkey')) { |
|
279 | + $opts->excludeEndKey(); |
|
280 | + } |
|
268 | 281 | |
269 | 282 | // Reverses order of results. |
270 | - if ($input->getOption('reverse-order')) |
|
271 | - $opts->reverseOrderOfResults(); |
|
283 | + if ($input->getOption('reverse-order')) { |
|
284 | + $opts->reverseOrderOfResults(); |
|
285 | + } |
|
272 | 286 | |
273 | 287 | // Skips the defined number of documents. |
274 | 288 | $skip = (int)$input->getOption('skip'); |
275 | - if ($skip > 0) |
|
276 | - $opts->skipDocs($skip); |
|
289 | + if ($skip > 0) { |
|
290 | + $opts->skipDocs($skip); |
|
291 | + } |
|
277 | 292 | |
278 | 293 | // Includes conflicts. |
279 | - if ($input->getOption('include-conflicts')) |
|
280 | - $opts->includeConflicts(); |
|
294 | + if ($input->getOption('include-conflicts')) { |
|
295 | + $opts->includeConflicts(); |
|
296 | + } |
|
281 | 297 | |
282 | 298 | // Includes missing keys. |
283 | - if ($input->getOption('include-missing-keys')) |
|
284 | - $opts->includeMissingKeys(); |
|
299 | + if ($input->getOption('include-missing-keys')) { |
|
300 | + $opts->includeMissingKeys(); |
|
301 | + } |
|
285 | 302 | |
286 | 303 | if ($view == "_temp_view") { |
287 | 304 | |
@@ -289,30 +306,31 @@ discard block |
||
289 | 306 | if ($fileName = $input->getOption('map')) { |
290 | 307 | $map = file_get_contents($fileName); |
291 | 308 | |
292 | - if ($fileName = $input->getOption('reduce')) |
|
293 | - $reduce = file_get_contents($fileName); |
|
294 | - else |
|
295 | - $reduce = ""; |
|
309 | + if ($fileName = $input->getOption('reduce')) { |
|
310 | + $reduce = file_get_contents($fileName); |
|
311 | + } else { |
|
312 | + $reduce = ""; |
|
313 | + } |
|
296 | 314 | |
297 | 315 | $language = $input->getOption('language'); |
298 | - if (empty($language)) |
|
299 | - $language = "php"; |
|
316 | + if (empty($language)) { |
|
317 | + $language = "php"; |
|
318 | + } |
|
319 | + } else { |
|
320 | + throw new \InvalidArgumentException("You didn't provided the map function."); |
|
300 | 321 | } |
301 | - else |
|
302 | - throw new \InvalidArgumentException("You didn't provided the map function."); |
|
303 | 322 | |
304 | 323 | print_r($couch->queryTempView($this->getDatabase(), $map, $reduce, $keys, $opts, $language)); |
305 | - } |
|
306 | - elseif ($view == "_all_docs") { |
|
324 | + } elseif ($view == "_all_docs") { |
|
307 | 325 | print_r($couch->queryAllDocs($this->getDatabase(), $keys, $opts)); |
308 | - } |
|
309 | - else { |
|
326 | + } else { |
|
310 | 327 | $names = explode('/', $view, 2); |
311 | 328 | |
312 | - if (count($names) == 2) |
|
313 | - print_r($couch->queryView($this->getDatabase(), $names[0], $names[1], $keys, $opts)); |
|
314 | - else |
|
315 | - throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
329 | + if (count($names) == 2) { |
|
330 | + print_r($couch->queryView($this->getDatabase(), $names[0], $names[1], $keys, $opts)); |
|
331 | + } else { |
|
332 | + throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
333 | + } |
|
316 | 334 | } |
317 | 335 | |
318 | 336 | } |
@@ -45,20 +45,21 @@ |
||
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 |
@@ -41,8 +41,9 @@ |
||
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 |
@@ -74,26 +74,28 @@ |
||
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 |
@@ -16,7 +16,6 @@ |
||
16 | 16 | use Symfony\Component\Console\Input\InputInterface; |
17 | 17 | use Symfony\Component\Console\Output\OutputInterface; |
18 | 18 | use Symfony\Component\Console\Question\Question; |
19 | - |
|
20 | 19 | use EoC\Couch; |
21 | 20 | use EoC\Adapter; |
22 | 21 |
@@ -43,10 +43,11 @@ |
||
43 | 43 | protected function execute(InputInterface $input, OutputInterface $output) { |
44 | 44 | $couch = $this->getConnection(); |
45 | 45 | |
46 | - if ($designDoc = $input->getOption('design-doc')) |
|
47 | - $couch->compactView($this->getDatabase(), $designDoc); |
|
48 | - else |
|
49 | - $couch->compactDb($this->getDatabase()); |
|
46 | + if ($designDoc = $input->getOption('design-doc')) { |
|
47 | + $couch->compactView($this->getDatabase(), $designDoc); |
|
48 | + } else { |
|
49 | + $couch->compactDb($this->getDatabase()); |
|
50 | + } |
|
50 | 51 | } |
51 | 52 | |
52 | 53 | } |
53 | 54 | \ No newline at end of file |
@@ -48,20 +48,21 @@ |
||
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 | $selected = $this->getDatabase(); |
51 | - } |
|
52 | - catch (\RuntimeException $e) { |
|
51 | + } catch (\RuntimeException $e) { |
|
53 | 52 | $selected = NULL; |
54 | 53 | } |
55 | 54 | |
56 | - if ($database === $selected) |
|
57 | - throw new \RuntimeException('You cannot delete the selected database.'); |
|
55 | + if ($database === $selected) { |
|
56 | + throw new \RuntimeException('You cannot delete the selected database.'); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | $question = new ConfirmationQuestion('Are you sure you want delete the database? [Y/n]', FALSE); |
60 | 60 | |
61 | 61 | $helper = $this->getHelper('question'); |
62 | 62 | |
63 | - if ($helper->ask($input, $output, $question) || $input->getOption('no-interaction')) |
|
64 | - $couch->deleteDb($database); |
|
63 | + if ($helper->ask($input, $output, $question) || $input->getOption('no-interaction')) { |
|
64 | + $couch->deleteDb($database); |
|
65 | + } |
|
65 | 66 | } |
66 | 67 | |
67 | 68 | } |
68 | 69 | \ No newline at end of file |
@@ -13,7 +13,6 @@ |
||
13 | 13 | |
14 | 14 | use Symfony\Component\Console\Input\InputInterface; |
15 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
16 | - |
|
17 | 16 | use ToolBag\Helper\TimeHelper; |
18 | 17 | |
19 | 18 |