Passed
Pull Request — master (#6)
by
unknown
12:12
created
app/src/Command/SqlExecute.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
 
83 83
             /// @todo inject more randomness in the username, by allowing more chars than bin2hex produces
84 84
 
85
-            $userName = 'db3v4l_' . substr(bin2hex(random_bytes(5)), 0, 9); // some mysql versions have a limitation of 16 chars for usernames
85
+            $userName = 'db3v4l_'.substr(bin2hex(random_bytes(5)), 0, 9); // some mysql versions have a limitation of 16 chars for usernames
86 86
             $password = bin2hex(random_bytes(16));
87 87
             //$dbName = bin2hex(random_bytes(31));
88 88
             $dbName = $userName; // $userName will be used as db name
89 89
 
90 90
             $tempDbSpecs = [];
91
-            foreach($instanceList as $instanceName => $instanceSpecs) {
91
+            foreach ($instanceList as $instanceName => $instanceSpecs) {
92 92
                 $tempDbSpecs[$instanceName] = [
93 93
                     'dbname' => $dbName,
94 94
                     'user' => $userName,
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             }
98 98
 
99 99
             if (($charset = $input->getOption('charset')) != '') {
100
-                foreach($instanceList as $instanceName) {
100
+                foreach ($instanceList as $instanceName) {
101 101
                     $tempDbSpecs[$instanceName]['charset'] = $charset;
102 102
                 }
103 103
             }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
             ];
125 125
 
126 126
             $dbConnectionSpecs = [];
127
-            foreach($instanceList as $instanceName => $instanceSpecs) {
127
+            foreach ($instanceList as $instanceName => $instanceSpecs) {
128 128
                 $dbConnectionSpecs[$instanceName] = array_merge($instanceSpecs, $dbConfig);
129 129
             }
130 130
         }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             if ($createDB) {
140 140
                 $results['failed'] += $creationResults['failed'];
141 141
 
142
-                foreach($instanceList as $instanceName  => $instanceSpecs) {
142
+                foreach ($instanceList as $instanceName  => $instanceSpecs) {
143 143
                     if (!isset($dbConnectionSpecs[$instanceName])) {
144 144
                         unset($instanceList[$instanceName]);
145 145
                     }
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
                 $this->executionStrategy = $previousStrategy;
152 152
             }
153 153
         } else {
154
-            $results = ['succeeded' => 0,  'failed' => 0, 'data' => null];
154
+            $results = ['succeeded' => 0, 'failed' => 0, 'data' => null];
155 155
         }
156 156
 
157 157
         $time = microtime(true) - $start;
158 158
 
159 159
         $this->writeResults($results, $time);
160 160
 
161
-        return (int)$results['failed'];
161
+        return (int) $results['failed'];
162 162
     }
163 163
 
164 164
     /**
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
         return $this->executeSqlAction(
177 177
             $dbConnectionSpecs,
178 178
             'Execution of SQL',
179
-            function ($schemaManager, $instanceName) use ($sql, $filename) {
179
+            function($schemaManager, $instanceName) use ($sql, $filename) {
180 180
                 if ($sql != null) {
181 181
                     return new Command(
182 182
                         $sql,
183
-                        function ($output, $executor) {
183
+                        function($output, $executor) {
184 184
                             /** @var TimedExecutor $executor */
185 185
                             return array_merge(['stdout' => $output], $executor->getTimingData());
186 186
                         }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                     }
194 194
                     return new File(
195 195
                         $realFileName,
196
-                        function ($output, $executor) {
196
+                        function($output, $executor) {
197 197
                             /** @var TimedExecutor $executor */
198 198
                             return array_merge(['stdout' => $output], $executor->getTimingData());
199 199
                         }
@@ -228,13 +228,13 @@  discard block
 block discarded – undo
228 228
             if (trim($line) !== '') {
229 229
                 if ($type === 'err') {
230 230
                     $this->writeErrorln(
231
-                        '[' . $processIndex . '][' . $pid . '] ' . trim($line),
231
+                        '['.$processIndex.']['.$pid.'] '.trim($line),
232 232
                         OutputInterface::VERBOSITY_VERBOSE,
233 233
                         OutputInterface::OUTPUT_RAW
234 234
                     );
235 235
                 } else {
236 236
                     $this->writeln(
237
-                        '[' . $processIndex . '][' . $pid . '] ' . trim($line),
237
+                        '['.$processIndex.']['.$pid.'] '.trim($line),
238 238
                         OutputInterface::VERBOSITY_VERBOSE,
239 239
                         OutputInterface::OUTPUT_RAW
240 240
                     );
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             return;
278 278
         }
279 279
 
280
-        foreach($results['data'] as $instanceName => $data) {
280
+        foreach ($results['data'] as $instanceName => $data) {
281 281
             $formattedData = $this->formatResults(array('data' => $data));
282 282
             $outputFile = $this->replaceDBSpecTokens($this->outputFile, $instanceName, $this->dbConfigurationManager->getInstanceConfiguration($instanceName));
283 283
             file_put_contents($outputFile, $formattedData);
Please login to merge, or discard this patch.
app/src/Core/DatabaseSchemaManager.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             case 'percona':
50 50
                 /// @todo if mysql version is bigger than 8.0, add `WITH mysql_native_password`
51 51
                 $statements = [
52
-                    "CREATE DATABASE `$dbName`" . ($collation !== null ? " CHARACTER SET $collation" : '') . ';'
52
+                    "CREATE DATABASE `$dbName`".($collation !== null ? " CHARACTER SET $collation" : '').';'
53 53
                 ];
54 54
                 if ($userName != '') {
55 55
                     $statements[] = "CREATE USER '$userName'@'%' IDENTIFIED BY '$password';";
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                     // Also, by default connections are in autocommit mode...
65 65
                     // And yet, we need a GO to commit the db creation...
66 66
                     "SET QUOTED_IDENTIFIER ON;",
67
-                    "CREATE DATABASE \"$dbName\"" . ($collation !== null ? " COLLATE $collation" : '') . ';'
67
+                    "CREATE DATABASE \"$dbName\"".($collation !== null ? " COLLATE $collation" : '').';'
68 68
                 ];
69 69
                 if ($userName != '') {
70 70
                     $statements[] = "CREATE LOGIN \"$userName\" WITH PASSWORD = '$password', DEFAULT_DATABASE = \"$dbName\", CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF;";
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
                 $statements = [
82 82
                     // q: do we need to add 'TEMPLATE template0' ?
83 83
                     //    see f.e. https://www.vertabelo.com/blog/collations-in-postgresql/
84
-                    "CREATE DATABASE \"$dbName\"" . ($collation !== null ? " ENCODING $collation" : '') . ';',
84
+                    "CREATE DATABASE \"$dbName\"".($collation !== null ? " ENCODING $collation" : '').';',
85 85
                 ];
86 86
                 if ($userName != '') {
87 87
                     $statements[] = "COMMIT;";
88
-                    $statements[] = "CREATE USER \"$userName\" WITH PASSWORD '$password'" . ';';
88
+                    $statements[] = "CREATE USER \"$userName\" WITH PASSWORD '$password'".';';
89 89
                     $statements[] = "GRANT ALL ON DATABASE \"$dbName\" TO \"$userName\""; // q: should we avoid granting CREATE?
90 90
                 }
91 91
                 return new Command($statements);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
             case 'sqlite':
94 94
                 /// @todo this does not support creation of the new db with a different character encoding...
95 95
                 ///       see https://stackoverflow.com/questions/21348459/set-pragma-encoding-utf-16-for-main-database-in-sqlite
96
-                $filename = dirname($this->databaseConfiguration['path']) . '/' . $dbName . '.sqlite';
96
+                $filename = dirname($this->databaseConfiguration['path']).'/'.$dbName.'.sqlite';
97 97
                 return new Command(
98 98
                     "ATTACH '$filename' AS \"$dbName\";"
99 99
                 );
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                 return new Command($statements);
161 161
 
162 162
             case 'sqlite':
163
-                $filename = dirname($this->databaseConfiguration['path']) . '/' . $dbName . '.sqlite';
163
+                $filename = dirname($this->databaseConfiguration['path']).'/'.$dbName.'.sqlite';
164 164
                 return new Command(
165 165
                     null,
166 166
                     function() use($filename, $dbName, $ifExists) {
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
             case 'percona':
248 248
                 return new Command(
249 249
                     'SHOW COLLATION;',
250
-                    function ($output, $executor) {
250
+                    function($output, $executor) {
251 251
                         /** @var Executor $executor */
252 252
                         $lines = $executor->resultSetToArray($output);
253 253
                         $out = [];
254
-                        foreach($lines as $line) {
254
+                        foreach ($lines as $line) {
255 255
                             $parts = explode("|", $line, 3);
256
-                            $out[] = trim($parts[0]) . ' (' . trim($parts[1]) .')';
256
+                            $out[] = trim($parts[0]).' ('.trim($parts[1]).')';
257 257
                         }
258 258
                         return $out;
259 259
                     }
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
             case 'postgresql':
265 265
                 return new Command(
266 266
                     'SELECT collname AS Collation FROM pg_collation ORDER BY collname',
267
-                    function ($output, $executor) {
267
+                    function($output, $executor) {
268 268
                         /** @var Executor $executor */
269 269
                         return $executor->resultSetToArray($output);
270 270
                     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                 return new Command(
275 275
                     null,
276 276
                     /// @todo list the supported utf16 variants as soon as allow using them
277
-                    function () {
277
+                    function() {
278 278
                         return [];
279 279
                     }
280 280
                 );
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
             case 'mssql':
295 295
                 return new Command(
296 296
                     'SELECT name AS Collation FROM fn_helpcollations();',
297
-                    function ($output, $executor) {
297
+                    function($output, $executor) {
298 298
                         /** @var Executor $executor */
299 299
                         return $executor->resultSetToArray($output);
300 300
                     }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
                 return new Command(
322 322
                     /// @todo use 'SHOW DATABASES' for versions < 5
323 323
                     "SELECT SCHEMA_NAME AS 'Database' FROM information_schema.SCHEMATA ORDER BY SCHEMA_NAME;",
324
-                    function ($output, $executor) {
324
+                    function($output, $executor) {
325 325
                         /** @var Executor $executor */
326 326
                         return $executor->resultSetToArray($output);
327 327
                     }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
                     // the way we create it, the user account is contained in the db
333 333
                     // @todo add "WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')" ?
334 334
                     "SELECT name AS 'Database' FROM sys.databases ORDER BY name;",
335
-                    function ($output, $executor) {
335
+                    function($output, $executor) {
336 336
                         /** @var Executor $executor */
337 337
                         return $executor->resultSetToArray($output);
338 338
                     }
@@ -343,20 +343,20 @@  discard block
 block discarded – undo
343 343
             case 'postgresql':
344 344
                 return new Command(
345 345
                     'SELECT datname AS "Database" FROM pg_database ORDER BY datname;',
346
-                    function ($output, $executor) {
346
+                    function($output, $executor) {
347 347
                         /** @var Executor $executor */
348 348
                         return $executor->resultSetToArray($output);
349 349
                     }
350 350
                 );
351 351
 
352 352
             case 'sqlite':
353
-                $fileGlob = dirname($this->databaseConfiguration['path']) . '/*.sqlite';
353
+                $fileGlob = dirname($this->databaseConfiguration['path']).'/*.sqlite';
354 354
                 return new Command(
355 355
                     null,
356 356
                     function() use ($fileGlob) {
357 357
                         $out = [];
358 358
                         foreach (glob($fileGlob) as $filename) {
359
-                            $out[] =  basename($filename);
359
+                            $out[] = basename($filename);
360 360
                         }
361 361
                         return $out;
362 362
                     }
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             case 'percona':
382 382
                 return new Command(
383 383
                     'SELECT DISTINCT User FROM mysql.user ORDER BY User;',
384
-                    function ($output, $executor) {
384
+                    function($output, $executor) {
385 385
                         /** @var Executor $executor */
386 386
                         return $executor->resultSetToArray($output);
387 387
                     }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
             case 'mssql':
391 391
                 return new Command(
392 392
                     "SELECT name AS 'User' FROM sys.sql_logins ORDER BY name",
393
-                    function ($output, $executor) {
393
+                    function($output, $executor) {
394 394
                         /** @var Executor $executor */
395 395
                         return $executor->resultSetToArray($output);
396 396
                     }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
             case 'postgresql':
402 402
                 return new Command(
403 403
                     'SELECT usename AS "User" FROM pg_catalog.pg_user ORDER BY usename;',
404
-                    function ($output, $executor) {
404
+                    function($output, $executor) {
405 405
                         /** @var Executor $executor */
406 406
                         return $executor->resultSetToArray($output);
407 407
                     }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
             case 'sqlite':
411 411
                 return new Command(
412 412
                     null,
413
-                    function () {
413
+                    function() {
414 414
                         // since sqlite does not support users, null seems more appropriate than an empty array...
415 415
                         return null;
416 416
                     }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
             case 'percona':
435 435
                 return new Command(
436 436
                     'SHOW VARIABLES LIKE "version";',
437
-                    function ($output, $executor) {
437
+                    function($output, $executor) {
438 438
                         /** @var Executor $executor */
439 439
                         $line = $executor->resultSetToArray($output)[0];
440 440
                         $parts = explode('|', $line);
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
             case 'postgresql':
448 448
                 return new Command(
449 449
                     'SHOW server_version;',
450
-                    function ($output, $executor) {
450
+                    function($output, $executor) {
451 451
                         /** @var Executor $executor */
452 452
                         return $executor->resultSetToArray($output)[0];
453 453
                     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
             case 'sqlite':
457 457
                 return new Command(
458 458
                     "select sqlite_version();",
459
-                    function ($output, $executor) {
459
+                    function($output, $executor) {
460 460
                         /** @var Executor $executor */
461 461
                         return $executor->resultSetToArray($output)[0];
462 462
                     }
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
             case 'mssql':
466 466
                 return new Command(
467 467
                     "SELECT @@version",
468
-                    function ($output, $executor) {
468
+                    function($output, $executor) {
469 469
                         /** @var Executor $executor */
470 470
                         $output = $executor->resultSetToArray($output);
471 471
                         $line = $output[0];
472 472
                         preg_match('/Microsoft SQL Server +([^ ]+) +([^ ]+) +/', $line, $matches);
473
-                        return $matches[1] . ' ' . $matches[2];
473
+                        return $matches[1].' '.$matches[2];
474 474
                     }
475 475
                 );
476 476
 
Please login to merge, or discard this patch.