@@ -29,7 +29,7 @@ |
||
29 | 29 | /** |
30 | 30 | * @return GeneratorFinderBuilder |
31 | 31 | */ |
32 | - public static function buildDefaultFinderBuilder(){ |
|
32 | + public static function buildDefaultFinderBuilder() { |
|
33 | 33 | $builder = new GeneratorFinderBuilder([]); |
34 | 34 | |
35 | 35 | $typeFactories = [ |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | $this->max = $max; |
27 | 27 | } |
28 | 28 | |
29 | - protected function generateRandomValue(Column $column){ |
|
30 | - switch ($column->getType()->getName()){ |
|
29 | + protected function generateRandomValue(Column $column) { |
|
30 | + switch ($column->getType()->getName()) { |
|
31 | 31 | case Type::BIGINT: |
32 | 32 | return $this->bigRandomNumber($this->min, $this->max); |
33 | 33 | case Type::INTEGER: |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | case Type::FLOAT: |
38 | 38 | return $this->faker->randomFloat(10, $this->min, $this->max); |
39 | 39 | default: |
40 | - throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '".$column->getType()->getName()."'"); |
|
40 | + throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '" . $column->getType()->getName() . "'"); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | private function bigRandomNumber($min, $max) { |
45 | - $difference = bcadd(bcsub($max,$min),1); |
|
45 | + $difference = bcadd(bcsub($max, $min), 1); |
|
46 | 46 | $rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8); // 0 - 1.0 |
47 | 47 | return bcadd($min, bcmul($difference, $rand_percent, 8), 0); |
48 | 48 | } |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | { |
33 | 33 | $object = $this->generateRandomValue(); |
34 | 34 | $iterations = 1; |
35 | - while (!$this->isUnique($object)){ |
|
35 | + while (!$this->isUnique($object)) { |
|
36 | 36 | $object = $this->generateRandomValue($column); |
37 | 37 | $iterations++; |
38 | - if ($iterations > DBFaker::MAX_ITERATIONS_FOR_UNIQUE_VALUE){ |
|
38 | + if ($iterations > DBFaker::MAX_ITERATIONS_FOR_UNIQUE_VALUE) { |
|
39 | 39 | throw new MaxNbOfIterationsForUniqueValueException("Unable to generate a unique value in less then maximumn allowed iterations."); |
40 | 40 | } |
41 | 41 | } |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | |
49 | 49 | private function storeObjectInGeneratedValues($object) |
50 | 50 | { |
51 | - if ($this->generateUniqueValues){ |
|
51 | + if ($this->generateUniqueValues) { |
|
52 | 52 | $this->generatedValues[] = $object; |
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | 56 | private function isUnique($object) |
57 | 57 | { |
58 | - if (!$this->generateUniqueValues){ |
|
58 | + if (!$this->generateUniqueValues) { |
|
59 | 59 | return true; |
60 | 60 | } |
61 | 61 |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function __construct($generateUniqueValues = false) |
23 | 23 | { |
24 | 24 | $this->faker = Factory::create(); |
25 | - if ($generateUniqueValues){ |
|
25 | + if ($generateUniqueValues) { |
|
26 | 26 | $this->faker->unique(); |
27 | 27 | } |
28 | 28 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | public function __construct($generateUniqueValues = false) |
18 | 18 | { |
19 | 19 | $this->faker = Factory::create(); |
20 | - if ($generateUniqueValues){ |
|
20 | + if ($generateUniqueValues) { |
|
21 | 21 | $this->faker->unique(); |
22 | 22 | } |
23 | 23 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function __construct($generateUniqueValues = false) |
23 | 23 | { |
24 | 24 | $this->faker = Factory::create(); |
25 | - if ($generateUniqueValues){ |
|
25 | + if ($generateUniqueValues) { |
|
26 | 26 | $this->faker->unique(); |
27 | 27 | } |
28 | 28 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function fakeDB() : void |
107 | 107 | { |
108 | - set_time_limit(0);//Import may take a looooooong time :) |
|
108 | + set_time_limit(0); //Import may take a looooooong time :) |
|
109 | 109 | $this->generateFakeData(); |
110 | 110 | $this->dropForeignKeys(); |
111 | 111 | $this->dropMultipleUniqueContraints(); |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | //Other data will be Faked depending of column's type and attributes. FKs to, but their values wil be overridden. |
146 | 146 | else { |
147 | - if (!$column->getNotnull() && $this->nullProbabilityOccured()){ |
|
147 | + if (!$column->getNotnull() && $this->nullProbabilityOccured()) { |
|
148 | 148 | $value = null; |
149 | - }else{ |
|
149 | + }else { |
|
150 | 150 | $generator = $this->generatorFinder->findGenerator($table, $column); |
151 | 151 | $value = $generator($column); |
152 | 152 | } |
153 | - if ($this->schemaHelper->isPrimaryKeyColumn($table, $column)){ |
|
153 | + if ($this->schemaHelper->isPrimaryKeyColumn($table, $column)) { |
|
154 | 154 | $this->getPkRegistry($table)->addValue($column->getName(), $value); |
155 | 155 | } |
156 | 156 | } |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | private function insertWithoutFksAndUniqueIndexes() |
187 | 187 | { |
188 | 188 | $plateform = $this->connection->getDatabasePlatform(); |
189 | - foreach ($this->data as $tableName => $rows){ |
|
189 | + foreach ($this->data as $tableName => $rows) { |
|
190 | 190 | $table = $this->schemaManager->listTableDetails($tableName); |
191 | 191 | |
192 | 192 | //initiate column types for insert |
193 | 193 | $types = []; |
194 | 194 | $first = reset($rows); |
195 | - if ($first){ |
|
196 | - foreach ($first as $columnName => $value){ |
|
195 | + if ($first) { |
|
196 | + foreach ($first as $columnName => $value) { |
|
197 | 197 | /** @var $column Column */ |
198 | 198 | $column = $table->getColumn($columnName); |
199 | 199 | $types[] = $column->getType()->getBindingType(); |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | //insert faked data |
204 | - foreach ($rows as $row){ |
|
204 | + foreach ($rows as $row) { |
|
205 | 205 | $dbRow = []; |
206 | - foreach ($row as $columnName => $value){ |
|
206 | + foreach ($row as $columnName => $value) { |
|
207 | 207 | $column = $table->getColumn($columnName); |
208 | 208 | $newVal = $column->getType()->convertToDatabaseValue($value, $plateform); |
209 | 209 | $dbRow[$columnName] = $newVal; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | //if autoincrement, add the new ID to the PKRegistry |
214 | 214 | $pkColumnName = $table->getPrimaryKeyColumns()[0]; |
215 | 215 | $pkColumn = $table->getColumn($pkColumnName); |
216 | - if ($this->schemaHelper->isPrimaryKeyColumn($table, $pkColumn)){ |
|
216 | + if ($this->schemaHelper->isPrimaryKeyColumn($table, $pkColumn)) { |
|
217 | 217 | $this->getPkRegistry($table)->addValue([$pkColumnName => $this->connection->lastInsertId()]); |
218 | 218 | } |
219 | 219 | } |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | private function dropForeignKeys() : void |
265 | 265 | { |
266 | 266 | $tables = $this->schemaManager->listTables(); |
267 | - foreach ($tables as $table){ |
|
268 | - foreach ($table->getForeignKeys() as $fk){ |
|
267 | + foreach ($tables as $table) { |
|
268 | + foreach ($table->getForeignKeys() as $fk) { |
|
269 | 269 | $this->foreignKeyStore[$table->getName()][] = $fk; |
270 | 270 | $this->schemaManager->dropForeignKey($fk, $table); |
271 | 271 | } |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | */ |
278 | 278 | private function restoreForeignKeys() : void |
279 | 279 | { |
280 | - foreach ($this->foreignKeyStore as $tableName => $fks){ |
|
281 | - foreach ($fks as $fk){ |
|
280 | + foreach ($this->foreignKeyStore as $tableName => $fks) { |
|
281 | + foreach ($fks as $fk) { |
|
282 | 282 | $this->schemaManager->createForeignKey($fk, $tableName); |
283 | 283 | } |
284 | 284 | } |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | private function dropMultipleUniqueContraints() |
288 | 288 | { |
289 | 289 | $tables = $this->schemaManager->listTables(); |
290 | - foreach ($tables as $table){ |
|
291 | - foreach ($table->getIndexes() as $index){ |
|
290 | + foreach ($tables as $table) { |
|
291 | + foreach ($table->getIndexes() as $index) { |
|
292 | 292 | if ($index->isUnique() && count($index->getColumns()) > 1) |
293 | 293 | $this->multipleUniqueContraintStore[$table->getName()][] = $index; |
294 | 294 | $this->schemaManager->dropIndex($index->getName(), $table->getName()); |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | |
299 | 299 | private function restoreMultipleUniqueContraints() |
300 | 300 | { |
301 | - foreach ($this->multipleUniqueContraintStore as $tableName => $indexes){ |
|
302 | - foreach ($indexes as $index){ |
|
301 | + foreach ($this->multipleUniqueContraintStore as $tableName => $indexes) { |
|
302 | + foreach ($indexes as $index) { |
|
303 | 303 | $this->schemaManager->createIndex($index, $tableName); |
304 | 304 | } |
305 | 305 | } |
@@ -314,16 +314,16 @@ discard block |
||
314 | 314 | { |
315 | 315 | $handledColumns = []; |
316 | 316 | |
317 | - foreach ($this->multipleUniqueContraintStore as $tableName => $indexes){ |
|
317 | + foreach ($this->multipleUniqueContraintStore as $tableName => $indexes) { |
|
318 | 318 | $table = $this->schemaManager->listTableDetails($tableName); |
319 | 319 | |
320 | - foreach ($indexes as $index){ |
|
320 | + foreach ($indexes as $index) { |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
324 | 324 | //Get all the PKs in the table (ie all the lines to update), and update the FKs with random PK values |
325 | 325 | $pkValues = $this->getPkRegistry($table)->loadValuesFromTable()->getAllValues(); |
326 | - foreach ($pkValues as $pkValue){ |
|
326 | + foreach ($pkValues as $pkValue) { |
|
327 | 327 | //TODO generate and insert data |
328 | 328 | $newValues = []; |
329 | 329 | $this->connection->update($tableName, $newValues, $pkValue); |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | |
337 | 337 | private function updateRemainingForeignKeys($handledColumns) |
338 | 338 | { |
339 | - foreach ($this->foreignKeyStore as $tableName => $fks){ |
|
340 | - if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false){ |
|
339 | + foreach ($this->foreignKeyStore as $tableName => $fks) { |
|
340 | + if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false) { |
|
341 | 341 | //only update tables where data has been inserted |
342 | 342 | continue; |
343 | 343 | } |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | |
347 | 347 | //Get all the PKs in the table (ie all the lines to update), and update the FKs with random PK values |
348 | 348 | $pkValues = $this->getPkRegistry($table)->loadValuesFromTable()->getAllValues(); |
349 | - foreach ($pkValues as $pkValue){ |
|
349 | + foreach ($pkValues as $pkValue) { |
|
350 | 350 | $newValues = []; |
351 | 351 | foreach ($fks as $fk) { |
352 | 352 | $foreignTable = $this->schemaManager->listTableDetails($fk->getForeignTableName()); |
353 | 353 | $localColums = $fk->getLocalColumns(); |
354 | 354 | foreach ($localColums as $index => $localColumn) { |
355 | - if (array_search($localColumn, $handledColumns) === false){ |
|
355 | + if (array_search($localColumn, $handledColumns) === false) { |
|
356 | 356 | continue; |
357 | 357 | } |
358 | 358 | $column = $table->getColumn($localColumn); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | else { |
147 | 147 | if (!$column->getNotnull() && $this->nullProbabilityOccured()){ |
148 | 148 | $value = null; |
149 | - }else{ |
|
149 | + } else{ |
|
150 | 150 | $generator = $this->generatorFinder->findGenerator($table, $column); |
151 | 151 | $value = $generator($column); |
152 | 152 | } |
@@ -289,8 +289,9 @@ discard block |
||
289 | 289 | $tables = $this->schemaManager->listTables(); |
290 | 290 | foreach ($tables as $table){ |
291 | 291 | foreach ($table->getIndexes() as $index){ |
292 | - if ($index->isUnique() && count($index->getColumns()) > 1) |
|
293 | - $this->multipleUniqueContraintStore[$table->getName()][] = $index; |
|
292 | + if ($index->isUnique() && count($index->getColumns()) > 1) { |
|
293 | + $this->multipleUniqueContraintStore[$table->getName()][] = $index; |
|
294 | + } |
|
294 | 295 | $this->schemaManager->dropIndex($index->getName(), $table->getName()); |
295 | 296 | } |
296 | 297 | } |
@@ -47,26 +47,26 @@ |
||
47 | 47 | |
48 | 48 | public function getForeignColumn(Table $table, Column $column) |
49 | 49 | { |
50 | - if (isset($this->foreignKeyMappings[$table->getName()][$column->getName()])){ |
|
50 | + if (isset($this->foreignKeyMappings[$table->getName()][$column->getName()])) { |
|
51 | 51 | return $this->foreignKeyMappings[$table->getName()][$column->getName()]["column"]; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $lookupColumn = null; |
55 | 55 | $foreignKeys = $table->getForeignKeys(); |
56 | - foreach ($foreignKeys as $foreignKeyConstraint){ |
|
56 | + foreach ($foreignKeys as $foreignKeyConstraint) { |
|
57 | 57 | $localColumns = $foreignKeyConstraint->getLocalColumns(); |
58 | 58 | $foreignColumns = $foreignKeyConstraint->getForeignColumns(); |
59 | 59 | $foreignTable = $this->schemaManager->listTableDetails($foreignKeyConstraint->getForeignTableName()); |
60 | - foreach ($localColumns as $index => $localColumn){ |
|
60 | + foreach ($localColumns as $index => $localColumn) { |
|
61 | 61 | $foreignColumn = $foreignColumns[$index]; |
62 | 62 | $this->foreignKeyMappings[$table->getName()][$localColumn] = ["table" => $foreignTable, "column" => $foreignTable->getColumn($foreignColumn)]; |
63 | - if ($localColumn == $column->getName()){ |
|
63 | + if ($localColumn == $column->getName()) { |
|
64 | 64 | $lookupColumn = $foreignTable->getColumn($foreignColumn); |
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | - if (!$lookupColumn){ |
|
69 | + if (!$lookupColumn) { |
|
70 | 70 | throw new |
71 | 71 | } |
72 | 72 | } |