@@ -27,14 +27,14 @@ |
||
27 | 27 | public function findGenerator(Table $table, Column $column) : FakeDataGeneratorInterface |
28 | 28 | { |
29 | 29 | $generator = null; |
30 | - if (!isset($this->generators[$table->getName() . "." . $column->getName()])){ |
|
31 | - foreach ($this->generatorFactories as list($condition, $generatorFactory)){ |
|
30 | + if (!isset($this->generators[$table->getName() . "." . $column->getName()])) { |
|
31 | + foreach ($this->generatorFactories as list($condition, $generatorFactory)) { |
|
32 | 32 | /** @var $condition ConditionInterface */ |
33 | - if ($condition->canApply($table, $column)){ |
|
33 | + if ($condition->canApply($table, $column)) { |
|
34 | 34 | $generator = $generatorFactory->create($table, $column); |
35 | 35 | } |
36 | 36 | } |
37 | - if (!$generator){ |
|
37 | + if (!$generator) { |
|
38 | 38 | throw new UnsupportedDataTypeException("Could not find suitable generator for column " . $table->getName() . "." . $column->getName() . " of type : " . $column->getType()->getName()); |
39 | 39 | } |
40 | 40 | $this->generators[$table->getName() . "." . $column->getName()] = $generator; |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function __construct(string $fakerProperty, $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 | $this->fakerProperty = $fakerProperty; |
@@ -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 | } |
@@ -52,19 +52,19 @@ |
||
52 | 52 | $obj = new \stdClass(); |
53 | 53 | $nbProps = random_int(2, 5); |
54 | 54 | $hasGoneDeeper = false; |
55 | - for ($i = 0; $i < $nbProps; $i++){ |
|
55 | + for ($i = 0; $i < $nbProps; $i++) { |
|
56 | 56 | $propName = $this->randomPropName(); |
57 | - $goDeeper = $depth != 0 && (random_int(0,10) > 7 || !$hasGoneDeeper); |
|
58 | - if ($goDeeper){ |
|
57 | + $goDeeper = $depth != 0 && (random_int(0, 10) > 7 || !$hasGoneDeeper); |
|
58 | + if ($goDeeper) { |
|
59 | 59 | $hasGoneDeeper = true; |
60 | 60 | $value = $this->generateRandomObject($depth - 1); |
61 | - }else{ |
|
61 | + }else { |
|
62 | 62 | $value = $this->randomValue(); |
63 | 63 | } |
64 | 64 | $obj->$propName = $value; |
65 | 65 | } |
66 | 66 | |
67 | - if ($this->toArray){ |
|
67 | + if ($this->toArray) { |
|
68 | 68 | $obj = json_decode(json_encode($obj, JSON_OBJECT_AS_ARRAY), true); |
69 | 69 | } |
70 | 70 | return $obj; |