@@ -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 |
@@ -169,110 +169,128 @@ |
||
169 | 169 | $args = $input->getArgument('keys'); |
170 | 170 | |
171 | 171 | $keys = []; |
172 | - foreach ($args as $key) |
|
173 | - $keys[] = $this->castArg($key, FALSE); |
|
172 | + foreach ($args as $key) { |
|
173 | + $keys[] = $this->castArg($key, FALSE); |
|
174 | + } |
|
175 | + } else { |
|
176 | + $keys = NULL; |
|
174 | 177 | } |
175 | - else |
|
176 | - $keys = NULL; |
|
177 | 178 | |
178 | 179 | // Sets the options. |
179 | 180 | $opts = new ViewQueryOpts(); |
180 | 181 | |
181 | 182 | // Key. |
182 | - if ($key = $input->getOption('key')) |
|
183 | - $opts->setKey($this->castArg($key), FALSE); |
|
183 | + if ($key = $input->getOption('key')) { |
|
184 | + $opts->setKey($this->castArg($key), FALSE); |
|
185 | + } |
|
184 | 186 | |
185 | 187 | // Start key. |
186 | - if ($startkey = $input->getOption('startkey')) |
|
187 | - $opts->setStartKey($this->castArg($startkey), FALSE); |
|
188 | + if ($startkey = $input->getOption('startkey')) { |
|
189 | + $opts->setStartKey($this->castArg($startkey), FALSE); |
|
190 | + } |
|
188 | 191 | |
189 | 192 | // End key. |
190 | - if ($endkey = $input->getOption('endkey')) |
|
191 | - $opts->setEndKey($this->castArg($endkey), FALSE); |
|
193 | + if ($endkey = $input->getOption('endkey')) { |
|
194 | + $opts->setEndKey($this->castArg($endkey), FALSE); |
|
195 | + } |
|
192 | 196 | |
193 | 197 | // Start doc id. |
194 | - if ($docId = $input->getOption('startkey-docid')) |
|
195 | - $opts->setStartDocId($docId); |
|
198 | + if ($docId = $input->getOption('startkey-docid')) { |
|
199 | + $opts->setStartDocId($docId); |
|
200 | + } |
|
196 | 201 | |
197 | 202 | // End doc id. |
198 | - if ($docId = $input->getOption('endkey-docid')) |
|
199 | - $opts->setEndDocId($docId); |
|
203 | + if ($docId = $input->getOption('endkey-docid')) { |
|
204 | + $opts->setEndDocId($docId); |
|
205 | + } |
|
200 | 206 | |
201 | 207 | // Limit. |
202 | 208 | $limit = (int)$input->getOption('limit'); |
203 | - if ($limit > 0) |
|
204 | - $opts->setLimit($limit); |
|
209 | + if ($limit > 0) { |
|
210 | + $opts->setLimit($limit); |
|
211 | + } |
|
205 | 212 | |
206 | 213 | // Group results. |
207 | - if ($input->getOption('group-results')) |
|
208 | - $opts->groupResults(); |
|
214 | + if ($input->getOption('group-results')) { |
|
215 | + $opts->groupResults(); |
|
216 | + } |
|
209 | 217 | |
210 | 218 | // Sets group level. |
211 | 219 | $level = (int)$input->getOption('group-level'); |
212 | - if ($level > 0) |
|
213 | - $opts->setGroupLevel($level); |
|
220 | + if ($level > 0) { |
|
221 | + $opts->setGroupLevel($level); |
|
222 | + } |
|
214 | 223 | |
215 | 224 | // Do not reduce. |
216 | - if ($input->getOption('do-not-reduce')) |
|
217 | - $opts->doNotReduce(); |
|
225 | + if ($input->getOption('do-not-reduce')) { |
|
226 | + $opts->doNotReduce(); |
|
227 | + } |
|
218 | 228 | |
219 | 229 | // Includes docs. |
220 | - if ($input->getOption('include-docs')) |
|
221 | - $opts->includeDocs(); |
|
230 | + if ($input->getOption('include-docs')) { |
|
231 | + $opts->includeDocs(); |
|
232 | + } |
|
222 | 233 | |
223 | 234 | // Excludes results. |
224 | - if ($input->getOption('exclude-results')) |
|
225 | - $opts->excludeResults(); |
|
235 | + if ($input->getOption('exclude-results')) { |
|
236 | + $opts->excludeResults(); |
|
237 | + } |
|
226 | 238 | |
227 | 239 | // Excludes endkey. |
228 | - if ($input->getOption('exclude-endkey')) |
|
229 | - $opts->excludeEndKey(); |
|
240 | + if ($input->getOption('exclude-endkey')) { |
|
241 | + $opts->excludeEndKey(); |
|
242 | + } |
|
230 | 243 | |
231 | 244 | // Reverses order of results. |
232 | - if ($input->getOption('reverse-order')) |
|
233 | - $opts->reverseOrderOfResults(); |
|
245 | + if ($input->getOption('reverse-order')) { |
|
246 | + $opts->reverseOrderOfResults(); |
|
247 | + } |
|
234 | 248 | |
235 | 249 | // Skips the defined number of documents. |
236 | 250 | $skip = (int)$input->getOption('skip'); |
237 | - if ($skip > 0) |
|
238 | - $opts->skipDocs($skip); |
|
251 | + if ($skip > 0) { |
|
252 | + $opts->skipDocs($skip); |
|
253 | + } |
|
239 | 254 | |
240 | 255 | // Includes conflicts. |
241 | - if ($input->getOption('include-conflicts')) |
|
242 | - $opts->includeConflicts(); |
|
256 | + if ($input->getOption('include-conflicts')) { |
|
257 | + $opts->includeConflicts(); |
|
258 | + } |
|
243 | 259 | |
244 | 260 | // Includes missing keys. |
245 | - if ($input->getOption('include-missing-keys')) |
|
246 | - $opts->includeMissingKeys(); |
|
261 | + if ($input->getOption('include-missing-keys')) { |
|
262 | + $opts->includeMissingKeys(); |
|
263 | + } |
|
247 | 264 | |
248 | 265 | |
249 | 266 | // Map and reduce functions. |
250 | 267 | if ($fileName = $input->getOption('map')) { |
251 | 268 | $map = file_get_contents($fileName); |
252 | 269 | |
253 | - if ($fileName = $input->getOption('reduce')) |
|
254 | - $reduce = file_get_contents($fileName); |
|
255 | - else |
|
256 | - $reduce = ""; |
|
270 | + if ($fileName = $input->getOption('reduce')) { |
|
271 | + $reduce = file_get_contents($fileName); |
|
272 | + } else { |
|
273 | + $reduce = ""; |
|
274 | + } |
|
257 | 275 | |
258 | 276 | $language = $input->getOption('language'); |
259 | - if (empty($language)) |
|
260 | - $language = "php"; |
|
277 | + if (empty($language)) { |
|
278 | + $language = "php"; |
|
279 | + } |
|
261 | 280 | } |
262 | 281 | |
263 | 282 | if ($view == "_temp_view") { |
264 | 283 | print_r($couch->queryTempView($map, $reduce, $keys, $opts, $language)); |
265 | - } |
|
266 | - elseif ($view == "_all_docs") { |
|
284 | + } elseif ($view == "_all_docs") { |
|
267 | 285 | print_r($couch->queryAllDocs($keys, $opts)); |
268 | - } |
|
269 | - else { |
|
286 | + } else { |
|
270 | 287 | $names = explode('/', $view, 2); |
271 | 288 | |
272 | - if (count($names) == 2) |
|
273 | - var_dump($couch->queryView($names[0], $names[1], $keys, $opts)); |
|
274 | - else |
|
275 | - throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
289 | + if (count($names) == 2) { |
|
290 | + var_dump($couch->queryView($names[0], $names[1], $keys, $opts)); |
|
291 | + } else { |
|
292 | + throw new \InvalidArgumentException("You have to specify design-doc/view-name."); |
|
293 | + } |
|
276 | 294 | } |
277 | 295 | |
278 | 296 | } |
@@ -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 |
@@ -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 |
@@ -44,10 +44,11 @@ |
||
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 |
@@ -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 |
@@ -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 | } |
@@ -109,16 +109,17 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -48,15 +48,15 @@ |
||
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 |