Passed
Branch master (915ae8)
by David
02:31
created
src/DBFaker.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function fakeDB() : void
92 92
     {
93
-        set_time_limit(0);//Import may take a looooong time
93
+        set_time_limit(0); //Import may take a looooong time
94 94
         $this->generateFakeData();
95 95
         $this->dropForeignKeys();
96 96
         $this->insertFakeData();
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
                 }
128 128
                 //Other data will be Faked depending of column's type and attributes
129 129
                 else {
130
-                    if (!$column->getNotnull() && $this->nullProbabilityOccured()){
130
+                    if (!$column->getNotnull() && $this->nullProbabilityOccured()) {
131 131
                         $value = null;
132
-                    }else{
132
+                    }else {
133 133
                         $value = $this->generatorFactory->getGenerator($table, $column)($column);
134 134
                     }
135 135
                 }
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
     {
149 149
         $this->foreignKeyStore = [];
150 150
         $tables = $this->schemaManager->listTables();
151
-        foreach ($tables as $table){
152
-            foreach ($table->getForeignKeys() as $fk){
151
+        foreach ($tables as $table) {
152
+            foreach ($table->getForeignKeys() as $fk) {
153 153
                 $this->foreignKeyStore[$table->getName()][] = $fk;
154 154
                 $this->schemaManager->dropForeignKey($fk, $table);
155 155
             }
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
      */
162 162
     private function restoreForeignKeys() : void
163 163
     {
164
-        foreach ($this->foreignKeyStore as $tableName => $fks){
165
-            foreach ($fks as $fk){
164
+        foreach ($this->foreignKeyStore as $tableName => $fks) {
165
+            foreach ($fks as $fk) {
166 166
                 $this->schemaManager->createForeignKey($fk, $tableName);
167 167
             }
168 168
         }
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
     {
178 178
         $plateform = $this->connection->getDatabasePlatform();
179 179
         //1 - First insert data with no FKs, and null PKs. This will generate primary keys
180
-        foreach ($this->data as $tableName => $rows){
180
+        foreach ($this->data as $tableName => $rows) {
181 181
             $table = $this->schemaManager->listTableDetails($tableName);
182 182
 
183 183
             //initiate column types for insert
184 184
             $types = [];
185 185
             $first = reset($rows);
186
-            if ($first){
187
-                foreach ($first as $columnName => $value){
186
+            if ($first) {
187
+                foreach ($first as $columnName => $value) {
188 188
                     /** @var $column Column */
189 189
                     $column = $table->getColumn($columnName);
190 190
                     $types[] = $column->getType()->getBindingType();
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
             }
193 193
 
194 194
             //insert faked data
195
-            foreach ($rows as $row){
195
+            foreach ($rows as $row) {
196 196
                 $dbRow = [];
197
-                foreach ($row as $columnName => $value){
197
+                foreach ($row as $columnName => $value) {
198 198
                     $column = $table->getColumn($columnName);
199 199
                     $newVal = $column->getType()->convertToDatabaseValue($value, $plateform);
200 200
                     $dbRow[$columnName] = $newVal;
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
         }
208 208
 
209 209
         //2 - loop again on table to set FKs now that all PK have been loaded
210
-        foreach ($this->foreignKeyStore as $tableName => $fks){
211
-            if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false){
210
+        foreach ($this->foreignKeyStore as $tableName => $fks) {
211
+            if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false) {
212 212
                 //only update tables where data has been inserted
213 213
                 continue;
214 214
             }
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
              * foreign tables' PKRegistries will provide final values for local FKs columns
225 225
              */
226 226
             $fkInfo = [];
227
-            foreach ($fks as $fk){
227
+            foreach ($fks as $fk) {
228 228
                 $localColums = $fk->getLocalColumns();
229 229
                 $foreignColumns = $fk->getForeignColumns();
230 230
                 $foreignTable = $this->schemaManager->listTableDetails($fk->getForeignTableName());
231
-                foreach ($localColums as $index => $localColumn){
231
+                foreach ($localColums as $index => $localColumn) {
232 232
                     $foreignColumn = $foreignColumns[$index];
233 233
                     $fkInfo[$localColumn] = [
234 234
                         "table" => $foreignTable,
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 
240 240
             //Get all the PKs in the table (ie all the lines to update), and update the FKs with random PK values
241 241
             $pkValues = $this->getPkRegistry($table)->loadValuesFromTable()->getAllValues();
242
-            foreach ($pkValues as $pkValue){
242
+            foreach ($pkValues as $pkValue) {
243 243
                 $newValues = [];
244
-                foreach ($fkInfo as $localColumn => $foreignData){
244
+                foreach ($fkInfo as $localColumn => $foreignData) {
245 245
                     $foreignTable = $foreignData["table"];
246 246
                     $foreignColumn = $foreignData["column"];
247 247
                     $fkPkRegistry = $this->getPkRegistry($foreignTable);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@
 block discarded – undo
129 129
                 else {
130 130
                     if (!$column->getNotnull() && $this->nullProbabilityOccured()){
131 131
                         $value = null;
132
-                    }else{
132
+                    } else{
133 133
                         $value = $this->generatorFactory->getGenerator($table, $column)($column);
134 134
                     }
135 135
                 }
Please login to merge, or discard this patch.
src/Helpers/PrimaryKeyRegistry.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
         $this->values = [];
52 52
         $colNames = implode(",", $this->columns);
53 53
         $rows = $this->connection->query("SELECT $colNames FROM " . $this->table->getName())->fetchAll();
54
-        foreach ($rows as $row){
54
+        foreach ($rows as $row) {
55 55
             $pk = [];
56
-            foreach ($this->columns as $column){
56
+            foreach ($this->columns as $column) {
57 57
                 $pk[$column] = $row[$column];
58 58
             }
59 59
             $this->values[] = $pk;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     {
72 72
         $keys = array_keys($value);
73 73
         sort($keys);
74
-        if ($this->columns == $keys){
74
+        if ($this->columns == $keys) {
75 75
             throw new PrimaryKeyColumnMismatchException("PrimaryKeys do not match between PKStore and addValue");
76 76
         }
77 77
         $this->values[] = $value;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getRandomValue() : array
84 84
     {
85
-        return $this->values[random_int(0, count($this->values) -1)];
85
+        return $this->values[random_int(0, count($this->values) - 1)];
86 86
     }
87 87
 
88 88
     /**
Please login to merge, or discard this patch.
src/Helpers/NumericColumnLimitHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function __construct(Column $column)
43 43
     {
44
-        if (array_search($column->getType()->getName(), self::$handledNumberTypes) === false){
44
+        if (array_search($column->getType()->getName(), self::$handledNumberTypes) === false) {
45 45
             throw new UnsupportedDataTypeException("Unsupported column type : " .
46 46
                 $column->getType()->getName() . "only " .
47
-                implode("', '", self::$handledNumberTypes) ." types are supported."
47
+                implode("', '", self::$handledNumberTypes) . " types are supported."
48 48
             );
49 49
         }
50 50
         $this->column = $column;
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
     public function getMinNumericValue()
58 58
     {
59 59
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
60
-        switch ($this->column->getType()->getName()){
60
+        switch ($this->column->getType()->getName()) {
61 61
             case Type::BIGINT:
62 62
                 return $this->column->getUnsigned() ? 0 : bcpow(2, 63);
63 63
                 break;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     public function getMaxNumericValue()
84 84
     {
85 85
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
86
-        switch ($this->column->getType()->getName()){
86
+        switch ($this->column->getType()->getName()) {
87 87
             case Type::BIGINT:
88 88
                 return $this->column->getUnsigned() ? bcpow(2, 64) : bcpow(2, 63) - 1;
89 89
                 break;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     private function getAbsValueByLengthPrecision(Column $column)
110 110
     {
111
-        switch ($column->getType()->getName()){
111
+        switch ($column->getType()->getName()) {
112 112
             case Type::DECIMAL:
113 113
                 $str = str_repeat(9, $column->getScale());
114 114
                 return (double) substr_replace($str, ".", $column->getScale() - $column->getPrecision(), 0);
Please login to merge, or discard this patch.
src/Generators/ComplexObjectGenerator.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function __invoke(Column $column)
43 43
     {
44
-        if ($this->depth === null){
44
+        if ($this->depth === null) {
45 45
             $this->depth = random_int(2, 5);
46 46
         }
47 47
         $object = $this->generateRandomObject($this->depth);
48
-        if ($this->toArray){
48
+        if ($this->toArray) {
49 49
             $object = json_decode(json_encode($object, JSON_OBJECT_AS_ARRAY), true);
50 50
         }
51 51
         return $object;
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
         $obj = new \stdClass();
61 61
         $nbProps = random_int(2, 5);
62 62
         $hasGoneDeeper = false;
63
-        for ($i = 0; $i < $nbProps; $i++){
63
+        for ($i = 0; $i < $nbProps; $i++) {
64 64
             $propName = $this->randomPropName();
65
-            $goDeeper = $depth != 0 && (random_int(0,10) > 7 || !$hasGoneDeeper);
66
-            if ($goDeeper){
65
+            $goDeeper = $depth != 0 && (random_int(0, 10) > 7 || !$hasGoneDeeper);
66
+            if ($goDeeper) {
67 67
                 $hasGoneDeeper = true;
68 68
                 $value = $this->generateRandomObject($depth - 1);
69
-            }else{
69
+            }else {
70 70
                 $value = $this->randomValue();
71 71
             }
72 72
             $obj->$propName = $value;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
             if ($goDeeper){
67 67
                 $hasGoneDeeper = true;
68 68
                 $value = $this->generateRandomObject($depth - 1);
69
-            }else{
69
+            } else{
70 70
                 $value = $this->randomValue();
71 71
             }
72 72
             $obj->$propName = $value;
Please login to merge, or discard this patch.
src/Generators/GeneratorFactory.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
     {
65 65
         $generator = null;
66 66
         $identifier = $table->getName() . "." . $column->getName();
67
-        foreach ($this->dynamicGenerators as $dynamicGenerator){
68
-            if ($dynamicGenerator["conditionCallback"]($column)){
67
+        foreach ($this->dynamicGenerators as $dynamicGenerator) {
68
+            if ($dynamicGenerator["conditionCallback"]($column)) {
69 69
                 $generator = $dynamicGenerator["generator"];
70 70
             }
71 71
         }
72
-        if (!$generator){
72
+        if (!$generator) {
73 73
             if (isset($this->columnGenerators[$identifier])) {
74 74
                 $generator = $this->columnGenerators[$identifier];
75
-            }else{
75
+            }else {
76 76
                 $generator = $this->getDefaultGenerator($column->getType());
77 77
             }
78 78
         }
79
-        if ($generator === null){
80
-            throw new \RuntimeException("No colum, type nor default generator found for column '".$identifier."' of type '".$column->getType()->getName()."', you must provide it !");
79
+        if ($generator === null) {
80
+            throw new \RuntimeException("No colum, type nor default generator found for column '" . $identifier . "' of type '" . $column->getType()->getName() . "', you must provide it !");
81 81
         }
82 82
         return $generator;
83 83
     }
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
     {
91 91
         $faker = $this->faker;
92 92
         $type = $type->getName();
93
-        if (!isset($this->defaultGenerators[$type])){
94
-            switch ($type){
93
+        if (!isset($this->defaultGenerators[$type])) {
94
+            switch ($type) {
95 95
                 case Type::TARRAY :
96 96
                     $generator = new ComplexObjectGenerator($faker);
97 97
                     break;
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
                 case Type::GUID :
129 129
                     $generator = new SimpleGenerator(function() {
130 130
                         $chars = "0123456789abcdef";
131
-                        $groups = [8 ,4, 4, 4, 12];
131
+                        $groups = [8, 4, 4, 4, 12];
132 132
                         $guid = [];
133
-                        foreach ($groups as $length){
133
+                        foreach ($groups as $length) {
134 134
                             $sub = "";
135
-                            for ($i = 0; $i < $length; $i++){
135
+                            for ($i = 0; $i < $length; $i++) {
136 136
                                 $sub .= $chars[random_int(0, count($chars) - 1)];
137 137
                             }
138 138
                             $guid[] = $sub;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function setGeneratorForColumn(string $table, string $column, callable $generator) : void
168 168
     {
169
-        if (!$generator instanceof FakeDataGeneratorInterface){
169
+        if (!$generator instanceof FakeDataGeneratorInterface) {
170 170
             $generator = new SimpleGenerator($generator);
171 171
         }
172 172
         $this->columnGenerators[$table . "." . $column] = $generator;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function setGenerator(callable $conditionCallback, callable $generator) : void
180 180
     {
181
-        if (!$generator instanceof FakeDataGeneratorInterface){
181
+        if (!$generator instanceof FakeDataGeneratorInterface) {
182 182
             $generator = new SimpleGenerator($generator);
183 183
         }
184 184
         $this->dynamicGenerators[] = [
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
         if (!$generator){
73 73
             if (isset($this->columnGenerators[$identifier])) {
74 74
                 $generator = $this->columnGenerators[$identifier];
75
-            }else{
75
+            } else{
76 76
                 $generator = $this->getDefaultGenerator($column->getType());
77 77
             }
78 78
         }
Please login to merge, or discard this patch.
test.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 /* Don't hesitate to use the Faker package to generate random data,
38 38
    there is plenty of data types available (IBAN, address, country code, ...).
39 39
 */
40
-$generator = \Faker\Factory::create();//you could pass the locale to generate localized data !
40
+$generator = \Faker\Factory::create(); //you could pass the locale to generate localized data !
41 41
 
42 42
 // address.postal_code column is a varchar, so default generated data will be text. Here we want a postal code :
43 43
 $generatorFactory->setGeneratorForColumn(
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 // all columns that end with "_email" or are named exactly "email" should be emails
48 48
 $generatorFactory->setGenerator(
49
-    function(\Doctrine\DBAL\Schema\Column $column){
49
+    function(\Doctrine\DBAL\Schema\Column $column) {
50 50
         return preg_match("/([(.*_)|_|]|^)email$/", $column->getName()) === 1;
51 51
     }, function() use ($generator){
52 52
         return $generator->email;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     "community_spending" => 100,
62 62
     "cron_flag" => 10,
63 63
     "project" => 50,
64
-    "project_note" => 200 ,
64
+    "project_note" => 200,
65 65
     "project_steps" => 10,
66 66
     "project_tasks" => 35,
67 67
     "request_hollidays" => 20,
Please login to merge, or discard this patch.