Completed
Push — master ( a074ca...1d756d )
by Kevin
14:37 queued 11:04
created
src/Helpers/SchemaHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
     public function getForeignKeyConstraintByLocal(Table $table, Column $column) : ?ForeignKeyConstraint
75 75
     {
76 76
         $table = $this->schema->getTable($table->getName());
77
-        foreach ($table->getForeignKeys() as $foreignKeyConstraint){
78
-            if (\in_array($column->getName(), $foreignKeyConstraint->getLocalColumns(), true)){
77
+        foreach ($table->getForeignKeys() as $foreignKeyConstraint) {
78
+            if (\in_array($column->getName(), $foreignKeyConstraint->getLocalColumns(), true)) {
79 79
                 return $foreignKeyConstraint;
80 80
             }
81 81
         }
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
     public function isForeignKeyAlsoUniqueIndex(ForeignKeyConstraint $fk) : bool
109 109
     {
110 110
         $table = $fk->getLocalTable();
111
-        foreach ($table->getIndexes() as $index){
112
-            if ($index->isUnique() && count($index->getColumns()) === count($fk->getLocalColumns())){
111
+        foreach ($table->getIndexes() as $index) {
112
+            if ($index->isUnique() && count($index->getColumns()) === count($fk->getLocalColumns())) {
113 113
                 $indexCols = $index->getColumns();
114 114
                 $fkCols = $fk->getColumns();
115 115
                 sort($indexCols);
116 116
                 sort($fkCols);
117
-                if ($indexCols == $fkCols){
117
+                if ($indexCols == $fkCols) {
118 118
                     return true;
119 119
                 }
120 120
             }
Please login to merge, or discard this patch.
src/Helpers/NumericColumnLimitHelper.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function __construct(Column $column)
36 36
     {
37
-        if (!\in_array($column->getType()->getName(), self::$handledNumberTypes, true)){
37
+        if (!\in_array($column->getType()->getName(), self::$handledNumberTypes, true)) {
38 38
             throw new UnsupportedDataTypeException('Unsupported column type : ' .
39 39
                 $column->getType()->getName() . 'only ' .
40 40
                 implode("', '", self::$handledNumberTypes) . ' types are supported.'
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
     public function getMinNumericValue()
51 51
     {
52 52
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
53
-        switch ($this->column->getType()->getName()){
53
+        switch ($this->column->getType()->getName()) {
54 54
             case Type::BIGINT:
55 55
                 return $this->column->getUnsigned() ? 0 : bcmul('-1', bcpow('2', '63'));
56 56
                 break;
57 57
             case Type::INTEGER:
58
-                return $this->column->getUnsigned() ? 0 : max(-1 * $precisionValue, bcmul('-1' , bcpow('2', '31')));
58
+                return $this->column->getUnsigned() ? 0 : max(-1 * $precisionValue, bcmul('-1', bcpow('2', '31')));
59 59
                 break;
60 60
             case Type::SMALLINT:
61
-                return $this->column->getUnsigned() ? 0 : bcmul('-1' , bcpow('2', '15'));
61
+                return $this->column->getUnsigned() ? 0 : bcmul('-1', bcpow('2', '15'));
62 62
                 break;
63 63
             case Type::DECIMAL:
64 64
                 return $this->column->getUnsigned() ? 0 : -1 * $precisionValue;
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
     public function getMaxNumericValue()
77 77
     {
78 78
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
79
-        switch ($this->column->getType()->getName()){
79
+        switch ($this->column->getType()->getName()) {
80 80
             case Type::BIGINT:
81
-                return $this->column->getUnsigned() ? bcsub(bcpow('2', '64'), '1') : bcsub(bcpow('2', '63') , '1');
81
+                return $this->column->getUnsigned() ? bcsub(bcpow('2', '64'), '1') : bcsub(bcpow('2', '63'), '1');
82 82
             case Type::INTEGER:
83
-                return $this->column->getUnsigned() ? bcsub(bcpow('2', '32'), '1') : min($precisionValue, bcsub( bcpow('2', '31') , '1'));
83
+                return $this->column->getUnsigned() ? bcsub(bcpow('2', '32'), '1') : min($precisionValue, bcsub(bcpow('2', '31'), '1'));
84 84
             case Type::SMALLINT:
85
-                return $this->column->getUnsigned() ? bcsub(bcpow('2', '16'), '1') : bcsub( bcpow('2', '15') , '1');
85
+                return $this->column->getUnsigned() ? bcsub(bcpow('2', '16'), '1') : bcsub(bcpow('2', '15'), '1');
86 86
             case Type::DECIMAL:
87 87
                 return $this->column->getUnsigned() ? 0 : $precisionValue;
88 88
             case Type::FLOAT:
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      */
97 97
     private function getAbsValueByLengthPrecision(Column $column)
98 98
     {
99
-        switch ($column->getType()->getName()){
99
+        switch ($column->getType()->getName()) {
100 100
             case Type::DECIMAL:
101 101
                 $str = str_repeat('9', $column->getScale());
102 102
                 return (double) substr_replace($str, '.', $column->getScale() - $column->getPrecision(), 0);
Please login to merge, or discard this patch.
src/DBFaker.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function fakeDB() : void
114 114
     {
115
-        set_time_limit(0);//Import may take a looooooong time :)
115
+        set_time_limit(0); //Import may take a looooooong time :)
116 116
         $data = $this->generateFakeData();
117 117
         $extensionContraints = $this->getExtensionConstraints();
118 118
         $foreignKeys = $this->dropForeignKeys();
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
                 }
166 166
                 //Other data will be Faked depending of column's type and attributes. FKs to, but their values wil be overridden.
167 167
                 else {
168
-                    if (!$column->getNotnull() && $this->nullProbabilityOccured()){
168
+                    if (!$column->getNotnull() && $this->nullProbabilityOccured()) {
169 169
                         $value = null;
170
-                    }else{
170
+                    }else {
171 171
                         $generator = $this->getSimpleColumnGenerator($table, $column);
172 172
                         $value = $generator();
173 173
                     }
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
     private function insertWithoutFksAndUniqueIndexes(array $data): void
221 221
     {
222 222
         $plateform = $this->connection->getDatabasePlatform();
223
-        foreach ($data as $tableName => $rows){
223
+        foreach ($data as $tableName => $rows) {
224 224
             $table = $this->schemaManager->listTableDetails($tableName);
225 225
 
226 226
             //initiate column types for insert : only get the first array to retrieve column names
227 227
             $types = [];
228 228
             $first = reset($rows);
229
-            if ($first){
230
-                foreach ($first as $columnName => $value){
229
+            if ($first) {
230
+                foreach ($first as $columnName => $value) {
231 231
                     /** @var Column $column */
232 232
                     $column = $table->getColumn($columnName);
233 233
                     $types[] = $column->getType()->getBindingType();
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 
237 237
             //insert faked data
238 238
             $cnt = count($rows);
239
-            foreach ($rows as $index => $row){
239
+            foreach ($rows as $index => $row) {
240 240
                 $dbRow = [];
241
-                foreach ($row as $columnName => $value){
241
+                foreach ($row as $columnName => $value) {
242 242
                     $column = $table->getColumn($columnName);
243 243
                     $newVal = $column->getType()->convertToDatabaseValue($value, $plateform);
244 244
                     $dbRow[$column->getQuotedName($this->connection->getDatabasePlatform())] = $newVal;
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
                 $this->connection->insert($table->getName(), $dbRow, $types);
248 248
             }
249 249
             //if autoincrement, add the new ID to the PKRegistry
250
-            if ($table->hasPrimaryKey()){
250
+            if ($table->hasPrimaryKey()) {
251 251
                 $pkColumnName = $table->getPrimaryKeyColumns()[0];
252 252
                 $pkColumn = $table->getColumn($pkColumnName);
253
-                if ($pkColumn->getAutoincrement() && $this->schemaHelper->isPrimaryKeyColumn($table, $pkColumn)){
253
+                if ($pkColumn->getAutoincrement() && $this->schemaHelper->isPrimaryKeyColumn($table, $pkColumn)) {
254 254
                     $this->getPkRegistry($table)->addValue([$pkColumnName => $this->connection->lastInsertId()]);
255 255
                 }
256 256
             }
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public function getPkRegistry(Table $table, bool $isSelfReferencing = false) : PrimaryKeyRegistry
267 267
     {
268
-        $index = $table->getName().($isSelfReferencing ? 'dbfacker_self_referencing' :'');
268
+        $index = $table->getName() . ($isSelfReferencing ? 'dbfacker_self_referencing' : '');
269 269
         if (!isset($this->primaryKeyRegistries[$index])) {
270 270
             $this->primaryKeyRegistries[$index] = new PrimaryKeyRegistry($this->connection, $table, $this->schemaHelper, $isSelfReferencing);
271 271
         }
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
         $this->log->info('Step 2.1 : Drop FKs ...');
313 313
         $foreignKeys = [];
314 314
         $tables = $this->schemaManager->listTables();
315
-        foreach ($tables as $table){
316
-            foreach ($table->getForeignKeys() as $fk){
315
+        foreach ($tables as $table) {
316
+            foreach ($table->getForeignKeys() as $fk) {
317 317
                 $foreignTable = $this->schemaManager->listTableDetails($fk->getForeignTableName());
318
-                foreach ($fk->getColumns() as $localColumnName){
318
+                foreach ($fk->getColumns() as $localColumnName) {
319 319
                     $localColumn = $table->getColumn($localColumnName);
320 320
                     $selfReferencing = $fk->getForeignTableName() === $table->getName();
321 321
                     $fkValueGenerator = new ForeignKeyColumnGenerator($table, $localColumn, $this->getPkRegistry($foreignTable, $selfReferencing), $fk, $this->fakerManagerHelper, $this->schemaHelper);
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
     private function restoreForeignKeys($foreignKeys) : void
336 336
     {
337 337
         $this->log->info('Step 4 : restore foreign keys');
338
-        foreach ($foreignKeys as $tableName => $fks){
339
-            foreach ($fks as $fk){
338
+        foreach ($foreignKeys as $tableName => $fks) {
339
+            foreach ($fks as $fk) {
340 340
                 $this->schemaManager->createForeignKey($fk, $tableName);
341 341
             }
342 342
         }
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
         $this->log->info('Step 2.2 : Drop Multiple indexes ...');
352 352
         $multipleUniqueContraints = [];
353 353
         $tables = $this->schemaManager->listTables();
354
-        foreach ($tables as $table){
355
-            foreach ($table->getIndexes() as $index){
356
-                if ($index->isUnique() && count($index->getColumns()) > 1){
354
+        foreach ($tables as $table) {
355
+            foreach ($table->getIndexes() as $index) {
356
+                if ($index->isUnique() && count($index->getColumns()) > 1) {
357 357
                     $multipleUniqueContraints[$table->getName()][] = $index;
358 358
                     $this->schemaManager->dropIndex($index->getQuotedName($this->connection->getDatabasePlatform()), $table->getName());
359 359
                 }
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
     private function restoreMultipleUniqueContraints(array $multipleUniqueContraints): void
369 369
     {
370 370
         $this->log->info('Step 5 : restore multiple unique indexes keys');
371
-        foreach ($multipleUniqueContraints as $tableName => $indexes){
372
-            foreach ($indexes as $index){
371
+        foreach ($multipleUniqueContraints as $tableName => $indexes) {
372
+            foreach ($indexes as $index) {
373 373
                 $this->schemaManager->createIndex($index, $tableName);
374 374
             }
375 375
         }
@@ -387,24 +387,24 @@  discard block
 block discarded – undo
387 387
     private function updateMultipleUniqueIndexedColumns(array $multipleUniqueContraints, array $handledFKColumns) : array
388 388
     {
389 389
 
390
-        foreach ($multipleUniqueContraints as $tableName => $indexes){
390
+        foreach ($multipleUniqueContraints as $tableName => $indexes) {
391 391
             $table = $this->schemaManager->listTableDetails($tableName);
392 392
 
393
-            foreach ($indexes as $index){
394
-                foreach ($index->getColumns() as $columnName){
395
-                    $fullColumnName = $tableName. '.' .$columnName;
396
-                    if (!\in_array($fullColumnName, $handledFKColumns, true)){
393
+            foreach ($indexes as $index) {
394
+                foreach ($index->getColumns() as $columnName) {
395
+                    $fullColumnName = $tableName . '.' . $columnName;
396
+                    if (!\in_array($fullColumnName, $handledFKColumns, true)) {
397 397
                         $handledFKColumns[] = $fullColumnName;
398 398
                     }
399 399
                 }
400 400
             }
401 401
 
402
-            $stmt = $this->connection->query('SELECT * FROM ' .$tableName);
403
-            $count = $this->connection->fetchColumn('SELECT count(*) FROM ' .$tableName);
402
+            $stmt = $this->connection->query('SELECT * FROM ' . $tableName);
403
+            $count = $this->connection->fetchColumn('SELECT count(*) FROM ' . $tableName);
404 404
             $i = 1;
405 405
             while ($row = $stmt->fetch()) {
406 406
                 $newValues = [];
407
-                foreach ($indexes as $index){
407
+                foreach ($indexes as $index) {
408 408
                     /** @var Index $index */
409 409
                     $compoundColumnGenerator = $this->getCompoundColumnGenerator($table, $index, $count);
410 410
                     $newValues = array_merge($newValues, $compoundColumnGenerator());
@@ -426,23 +426,23 @@  discard block
 block discarded – undo
426 426
      */
427 427
     private function updateRemainingForeignKeys(array $foreignKeys, array $handledFKColumns): void
428 428
     {
429
-        foreach ($foreignKeys as $tableName => $fks){
430
-            if (!array_key_exists($tableName, $this->fakeTableRowNumbers)){
429
+        foreach ($foreignKeys as $tableName => $fks) {
430
+            if (!array_key_exists($tableName, $this->fakeTableRowNumbers)) {
431 431
                 //only update tables where data has been inserted
432 432
                 continue;
433 433
             }
434 434
 
435 435
             $table = $this->schemaManager->listTableDetails($tableName);
436 436
 
437
-            $stmt = $this->connection->query('SELECT * FROM ' .$tableName);
438
-            $count = $this->connection->fetchColumn("SELECT count(*) FROM ".$tableName);
437
+            $stmt = $this->connection->query('SELECT * FROM ' . $tableName);
438
+            $count = $this->connection->fetchColumn("SELECT count(*) FROM " . $tableName);
439 439
             $i = 1;
440 440
             while ($row = $stmt->fetch()) {
441 441
                 $newValues = [];
442 442
                 foreach ($fks as $fk) {
443 443
                     $localColumns = $fk->getLocalColumns();
444 444
                     foreach ($localColumns as $index => $localColumn) {
445
-                        if (\in_array($tableName . '.' . $localColumn, $handledFKColumns)){
445
+                        if (\in_array($tableName . '.' . $localColumn, $handledFKColumns)) {
446 446
                             continue;
447 447
                         }
448 448
                         $column = $table->getColumn($localColumn);
@@ -451,8 +451,8 @@  discard block
 block discarded – undo
451 451
                     }
452 452
                 }
453 453
                 $row = $this->stripUnselectableColumns($table, $row);
454
-                if (count($newValues) && $this->connection->update($tableName, $newValues, $row) === 0){
455
-                    throw new DBFakerException("Row has not been updated $tableName - ". var_export($newValues,true) . ' - ' . var_export($row, true));
454
+                if (count($newValues) && $this->connection->update($tableName, $newValues, $row) === 0) {
455
+                    throw new DBFakerException("Row has not been updated $tableName - " . var_export($newValues, true) . ' - ' . var_export($row, true));
456 456
                 };
457 457
                 $this->log->info("Step 3.3 : updated $i of $count for $tableName");
458 458
                 $i++;
@@ -471,10 +471,10 @@  discard block
 block discarded – undo
471 471
     private function updateExtensionContraints(array $extensionConstraints) : array
472 472
     {
473 473
         $handledFKColumns = [];
474
-        foreach ($extensionConstraints as $fk){
474
+        foreach ($extensionConstraints as $fk) {
475 475
             $localTableName = $fk->getLocalTable()->getQuotedName($this->connection->getDatabasePlatform());
476 476
             $stmt = $this->connection->query('SELECT * FROM ' . $localTableName);
477
-            $count = $this->connection->fetchColumn('SELECT count(*) FROM ' .$localTableName);
477
+            $count = $this->connection->fetchColumn('SELECT count(*) FROM ' . $localTableName);
478 478
             $i = 1;
479 479
             while ($row = $stmt->fetch()) {
480 480
                 $newValues = [];
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
                     $newValues[$localColumn] = $fkValueGenerator();
487 487
                 }
488 488
                 $row = $this->stripUnselectableColumns($fk->getLocalTable(), $row);
489
-                if ($this->connection->update($localTableName, $newValues, $row) === 0){
490
-                    throw new DBFakerException("Row has not been updated $localTableName - ". var_export($newValues,true) . ' - ' . var_export($row, true));
489
+                if ($this->connection->update($localTableName, $newValues, $row) === 0) {
490
+                    throw new DBFakerException("Row has not been updated $localTableName - " . var_export($newValues, true) . ' - ' . var_export($row, true));
491 491
                 };
492 492
                 $this->log->info("Updated $i of $count for $localTableName");
493 493
                 $i++;
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      */
507 507
     private function getCompoundColumnGenerator(Table $table, Index $index, int $count): CompoundColumnGenerator
508 508
     {
509
-        if (!isset($this->compoundColumnGenerators[$table->getName() . "." . $index->getName()])){
509
+        if (!isset($this->compoundColumnGenerators[$table->getName() . "." . $index->getName()])) {
510 510
             $compoundGenerator = new CompoundColumnGenerator($table, $index, $this->schemaHelper, $this, $this->schemaManager, $this->fakerManagerHelper, $count);
511 511
             $this->compoundColumnGenerators[$table->getName() . '.' . $index->getName()] = $compoundGenerator;
512 512
         }
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
         return array_filter($row, function(string $columnName) use ($table) {
548 548
             return !\in_array($table->getColumn($columnName)->getType()->getName(), [
549 549
                 Type::BINARY, Type::JSON, Type::JSON_ARRAY, Type::SIMPLE_ARRAY, Type::TARRAY, Type::BLOB, Type::JSON, Type::OBJECT
550
-            ],true);
550
+            ], true);
551 551
         }, ARRAY_FILTER_USE_KEY);
552 552
     }
553 553
 
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
         $this->log->info('Step 2.1 : store extension constraints ...');
561 561
         $extensionConstraints = [];
562 562
         $tables = $this->schemaManager->listTables();
563
-        foreach ($tables as $table){
564
-            foreach ($table->getForeignKeys() as $fk){
565
-                if ($this->schemaHelper->isExtendingKey($fk)){
563
+        foreach ($tables as $table) {
564
+            foreach ($table->getForeignKeys() as $fk) {
565
+                if ($this->schemaHelper->isExtendingKey($fk)) {
566 566
                     $extensionConstraints[] = $fk;
567 567
                 }
568 568
             }
Please login to merge, or discard this patch.