@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | class CheckTypeConditionTest extends TestCase |
10 | 10 | { |
11 | - public function testCanApply(){ |
|
11 | + public function testCanApply() { |
|
12 | 12 | $table = new Table("foo"); |
13 | 13 | $column = new Column("bar", Type::getType(Type::DECIMAL)); |
14 | 14 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ->column("population")->bigInt() |
64 | 64 | ->column("birthrate")->float() |
65 | 65 | ->column("president_id")->references("persons") |
66 | - ->column("population_density")->decimal(10,2) |
|
66 | + ->column("population_density")->decimal(10, 2) |
|
67 | 67 | ->column("summary")->text(); |
68 | 68 | |
69 | 69 | $users->column("country_id")->references("countries"); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | // address.postal_code column is a varchar, so default generated data will be text. Here we want a postal code : |
112 | 112 | $generatorFinderBuilder->addGenerator( |
113 | - new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column){ |
|
113 | + new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) { |
|
114 | 114 | return $table->getName() == "address" && $column->getName() == "postal_code"; |
115 | 115 | }), |
116 | 116 | new SimpleGeneratorFactory("postcode") |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | // all columns that end with "_email" or are named exactly "email" should be emails |
120 | 120 | $generatorFinderBuilder->addGenerator( |
121 | - new CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column){ |
|
121 | + new CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) { |
|
122 | 122 | return preg_match("/([(.*_)|_|]|^)email$/", $column->getName()) === 1; |
123 | 123 | }), |
124 | 124 | new SimpleGeneratorFactory("email") |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $faker->setFakeTableRowNumbers($tableRowNumbers); |
147 | 147 | $faker->fakeDB(); |
148 | 148 | |
149 | - foreach ($tableRowNumbers as $tableName => $expectedCount){ |
|
149 | + foreach ($tableRowNumbers as $tableName => $expectedCount) { |
|
150 | 150 | $count = $conn->fetchColumn('SELECT count(*) from ' . $tableName); |
151 | 151 | $this->assertEquals($expectedCount, $count); |
152 | 152 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | protected function generateRandomValue(Column $column) |
54 | 54 | { |
55 | - switch ($column->getType()->getName()){ |
|
55 | + switch ($column->getType()->getName()) { |
|
56 | 56 | case Type::BIGINT: |
57 | 57 | return $this->bigRandomNumber(); |
58 | 58 | case Type::INTEGER: |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | case Type::FLOAT: |
63 | 63 | return $this->faker->randomFloat(10, $this->min, $this->max); |
64 | 64 | default: |
65 | - throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '".$column->getType()->getName()."'"); |
|
65 | + throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '" . $column->getType()->getName() . "'"); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | private function bigRandomNumber() : string |
73 | 73 | { |
74 | - $difference = bcadd(bcsub($this->max,$this->min),"1"); |
|
74 | + $difference = bcadd(bcsub($this->max, $this->min), "1"); |
|
75 | 75 | $rand_percent = bcdiv((string) mt_rand(), (string) mt_getrandmax(), 8); // 0 - 1.0 |
76 | 76 | return bcadd($this->min, bcmul($difference, $rand_percent, 8), 0); |
77 | 77 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | public function __construct(string $fakerProperty, bool $generateUniqueValues = false) |
27 | 27 | { |
28 | 28 | $this->faker = Factory::create(); |
29 | - if ($generateUniqueValues){ |
|
29 | + if ($generateUniqueValues) { |
|
30 | 30 | $this->faker->unique(); |
31 | 31 | } |
32 | 32 | $this->fakerProperty = $fakerProperty; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function __construct(string $globExpression) |
20 | 20 | { |
21 | - $this->globExpression= $globExpression; |
|
21 | + $this->globExpression = $globExpression; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -27,7 +27,7 @@ |
||
27 | 27 | public function __construct(Column $column, bool $generateUniqueValues = false) |
28 | 28 | { |
29 | 29 | $this->faker = Factory::create(); |
30 | - if ($generateUniqueValues){ |
|
30 | + if ($generateUniqueValues) { |
|
31 | 31 | $this->faker->unique(); |
32 | 32 | } |
33 | 33 | $this->column = $column; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @throws \Doctrine\DBAL\DBALException |
46 | 46 | * @throws \Doctrine\DBAL\Schema\SchemaException |
47 | 47 | */ |
48 | - public function __construct(Table $table, Column $column, PrimaryKeyRegistry $foreignPkRegistry, ForeignKeyConstraint $fk, DBFakerSchemaManager $schemaManager, SchemaHelper $schemaHelper) |
|
48 | + public function __construct(Table $table, Column $column, PrimaryKeyRegistry $foreignPkRegistry, ForeignKeyConstraint $fk, DBFakerSchemaManager $schemaManager, SchemaHelper $schemaHelper) |
|
49 | 49 | { |
50 | 50 | $this->foreignColumn = $schemaManager->getForeignColumn($table, $column); |
51 | 51 | $this->foreignPkRegistry = $foreignPkRegistry; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | { |
62 | 62 | $randomPk = $this->foreignPkRegistry->loadValuesFromTable()->getRandomValue($this->alreadyGeneratedValues); |
63 | 63 | $value = $randomPk[$this->foreignColumn->getName()]; |
64 | - if ($this->generateUniqueValues){ |
|
64 | + if ($this->generateUniqueValues) { |
|
65 | 65 | $this->alreadyGeneratedValues[] = $randomPk; |
66 | 66 | } |
67 | 67 | return $value; |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function __construct(Table $table, Index $index, SchemaHelper $schemaHelper, DBFaker $dbFaker, AbstractSchemaManager $schemaManager, DBFakerSchemaManager $fakerManagerHelper, int $valuesCount) |
42 | 42 | { |
43 | - foreach ($index->getColumns() as $columnName){ |
|
43 | + foreach ($index->getColumns() as $columnName) { |
|
44 | 44 | //FK or normal column ? |
45 | 45 | $column = $table->getColumn($columnName); |
46 | - if ($schemaHelper->isColumnPartOfForeignKeyConstraint($table, $column)){ |
|
46 | + if ($schemaHelper->isColumnPartOfForeignKeyConstraint($table, $column)) { |
|
47 | 47 | $fkConstraint = $schemaHelper->getForeignKeyConstraintByLocal($table, $column); |
48 | - if ($fkConstraint === null){ |
|
48 | + if ($fkConstraint === null) { |
|
49 | 49 | throw new SchemaLogicException($column->getName() . ' was detected as foreign key but could not get it'); |
50 | 50 | } |
51 | 51 | $foreignTableName = $fkConstraint->getForeignTableName(); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | $foreignTable = $schemaManager->listTableDetails($foreignTableName); |
54 | 54 | $pkRegistry = $dbFaker->getPkRegistry($foreignTable); |
55 | 55 | $values = $pkRegistry->loadValuesFromTable()->getAllValues(); |
56 | - $this->possibleValues[$columnName] = array_map(function ($value) use ($foreignColumn) { |
|
56 | + $this->possibleValues[$columnName] = array_map(function($value) use ($foreignColumn) { |
|
57 | 57 | return $value[$foreignColumn->getName()]; |
58 | 58 | }, $values); |
59 | - }else{ |
|
59 | + }else { |
|
60 | 60 | $generator = $dbFaker->getSimpleColumnGenerator($table, $column); |
61 | - for($i = 0; $i < $valuesCount; $i++) { |
|
61 | + for ($i = 0; $i < $valuesCount; $i++) { |
|
62 | 62 | $this->possibleValues[$columnName][] = $generator(); |
63 | 63 | } |
64 | 64 | } |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | public function __invoke() : array |
71 | 71 | { |
72 | 72 | $returnVal = []; |
73 | - foreach ($this->possibleValues as $columnName => $values){ |
|
73 | + foreach ($this->possibleValues as $columnName => $values) { |
|
74 | 74 | $returnVal[$columnName] = $values[array_rand($values)]; |
75 | 75 | } |
76 | - if (!\in_array($returnVal, $this->generatedValues, true)){ |
|
76 | + if (!\in_array($returnVal, $this->generatedValues, true)) { |
|
77 | 77 | $this->generatedValues[] = $returnVal; |
78 | 78 | return $returnVal; |
79 | 79 | } |
@@ -58,21 +58,21 @@ |
||
58 | 58 | $obj = new \stdClass(); |
59 | 59 | $nbProps = \random_int(2, 5); |
60 | 60 | $hasGoneDeeper = false; |
61 | - for ($i = 0; $i < $nbProps; $i++){ |
|
61 | + for ($i = 0; $i < $nbProps; $i++) { |
|
62 | 62 | $propName = $this->randomPropName(); |
63 | - $goDeeper = $depth !== 0 && (\random_int(0,10) > 7 || !$hasGoneDeeper); |
|
64 | - if ($goDeeper){ |
|
63 | + $goDeeper = $depth !== 0 && (\random_int(0, 10) > 7 || !$hasGoneDeeper); |
|
64 | + if ($goDeeper) { |
|
65 | 65 | $hasGoneDeeper = true; |
66 | 66 | $value = $this->generateRandomObject($depth - 1); |
67 | - }else{ |
|
67 | + }else { |
|
68 | 68 | $value = $this->randomValue(); |
69 | 69 | } |
70 | 70 | $obj->$propName = $value; |
71 | 71 | } |
72 | 72 | |
73 | - if ($this->toArray){ |
|
73 | + if ($this->toArray) { |
|
74 | 74 | $obj = json_encode($obj, JSON_OBJECT_AS_ARRAY); |
75 | - if (!$obj){ |
|
75 | + if (!$obj) { |
|
76 | 76 | throw new DBFakerException('Could not convert generated object to Json String'); |
77 | 77 | } |
78 | 78 | $obj = json_decode($obj, true); |