@@ -19,7 +19,7 @@ |
||
19 | 19 | public function __construct(bool $generateUniqueValues = false) |
20 | 20 | { |
21 | 21 | $this->faker = Factory::create(); |
22 | - if ($generateUniqueValues){ |
|
22 | + if ($generateUniqueValues) { |
|
23 | 23 | $this->faker->unique(); |
24 | 24 | } |
25 | 25 | } |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | { |
42 | 42 | $object = $this->generateRandomValue($this->column); |
43 | 43 | $iterations = 1; |
44 | - while (!$this->isUnique($object)){ |
|
44 | + while (!$this->isUnique($object)) { |
|
45 | 45 | $object = $this->generateRandomValue($this->column); |
46 | 46 | $iterations++; |
47 | - if ($iterations > DBFaker::MAX_ITERATIONS_FOR_UNIQUE_VALUE){ |
|
47 | + if ($iterations > DBFaker::MAX_ITERATIONS_FOR_UNIQUE_VALUE) { |
|
48 | 48 | throw new MaxNbOfIterationsForUniqueValueException('Unable to generate a unique value in less then maximumn allowed iterations.'); |
49 | 49 | } |
50 | 50 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | private function storeObjectInGeneratedValues($object) : void |
66 | 66 | { |
67 | - if ($this->generateUniqueValues){ |
|
67 | + if ($this->generateUniqueValues) { |
|
68 | 68 | $this->generatedValues[] = $object; |
69 | 69 | } |
70 | 70 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | private function isUnique($object) : bool |
77 | 77 | { |
78 | - if (!$this->generateUniqueValues){ |
|
78 | + if (!$this->generateUniqueValues) { |
|
79 | 79 | return true; |
80 | 80 | } |
81 | 81 |
@@ -19,7 +19,7 @@ |
||
19 | 19 | public function __construct(bool $generateUniqueValues = false) |
20 | 20 | { |
21 | 21 | $this->faker = Factory::create(); |
22 | - if ($generateUniqueValues){ |
|
22 | + if ($generateUniqueValues) { |
|
23 | 23 | $this->faker->unique(); |
24 | 24 | } |
25 | 25 | } |
@@ -38,14 +38,14 @@ |
||
38 | 38 | public function findGenerator(Table $table, Column $column, SchemaHelper $helper) : FakeDataGeneratorInterface |
39 | 39 | { |
40 | 40 | $generator = null; |
41 | - if (!isset($this->generators[$table->getName() . '.' . $column->getName()])){ |
|
42 | - foreach ($this->generatorFactories as list($condition, $generatorFactory)){ |
|
41 | + if (!isset($this->generators[$table->getName() . '.' . $column->getName()])) { |
|
42 | + foreach ($this->generatorFactories as list($condition, $generatorFactory)) { |
|
43 | 43 | /** @var $condition ConditionInterface */ |
44 | - if ($condition->canApply($table, $column)){ |
|
44 | + if ($condition->canApply($table, $column)) { |
|
45 | 45 | $generator = $generatorFactory->create($table, $column, $helper); |
46 | 46 | } |
47 | 47 | } |
48 | - if (!$generator){ |
|
48 | + if (!$generator) { |
|
49 | 49 | throw new UnsupportedDataTypeException('Could not find suitable generator for column ' . $table->getName() . '.' . $column->getName() . ' of type : ' . $column->getType()->getName()); |
50 | 50 | } |
51 | 51 | $this->generators[$table->getName() . '.' . $column->getName()] = $generator; |
@@ -23,11 +23,11 @@ |
||
23 | 23 | public function __invoke() |
24 | 24 | { |
25 | 25 | $files = glob($this->globExpression, GLOB_MARK); |
26 | - $files = array_filter($files, function ($fileName){ |
|
26 | + $files = array_filter($files, function($fileName) { |
|
27 | 27 | return strrpos($fileName, DIRECTORY_SEPARATOR) !== \strlen($fileName) - 1; |
28 | 28 | }); |
29 | - if (\count($files) === 0){ |
|
30 | - throw new NoTestFilesFoundException("No files found for glob expression '".$this->globExpression."'"); |
|
29 | + if (\count($files) === 0) { |
|
30 | + throw new NoTestFilesFoundException("No files found for glob expression '" . $this->globExpression . "'"); |
|
31 | 31 | } |
32 | 32 | $files = array_values($files); |
33 | 33 | $chosenFile = $files[random_int(0, \count($files) - 1)]; |
@@ -74,8 +74,8 @@ discard block |
||
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 | } |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | public function isForeignKetAlsoUniqueIndex($fk) : bool |
113 | 113 | { |
114 | 114 | $table = $fk->getLocalTable(); |
115 | - foreach ($table->getIndexes() as $index){ |
|
116 | - if ($index->isUnique() && count($index->getColumns()) === count($fk->getLocalColumns())){ |
|
115 | + foreach ($table->getIndexes() as $index) { |
|
116 | + if ($index->isUnique() && count($index->getColumns()) === count($fk->getLocalColumns())) { |
|
117 | 117 | $indexCols = $index->getColumns(); |
118 | 118 | $fkCols = $fk->getColumns(); |
119 | 119 | sort($indexCols); |
120 | 120 | sort($fkCols); |
121 | - if ($indexCols == $fkCols){ |
|
121 | + if ($indexCols == $fkCols) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | } |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | $this->connection = $connection; |
50 | 50 | $refTable = null; |
51 | 51 | $refCols = []; |
52 | - foreach ($table->getForeignKeys() as $fk){ |
|
53 | - if ($helper->isExtendingKey($fk) && $table->getName() !== $fk->getForeignTableName()){ |
|
52 | + foreach ($table->getForeignKeys() as $fk) { |
|
53 | + if ($helper->isExtendingKey($fk) && $table->getName() !== $fk->getForeignTableName()) { |
|
54 | 54 | $refTable = $fk->getForeignTableName(); |
55 | 55 | $refCols = $fk->getForeignColumns(); |
56 | 56 | } |
57 | 57 | } |
58 | - if ($isSelfReferencing || !$refTable){ |
|
58 | + if ($isSelfReferencing || !$refTable) { |
|
59 | 59 | $pk = $table->getPrimaryKey(); |
60 | - if ($pk === null){ |
|
60 | + if ($pk === null) { |
|
61 | 61 | throw new SchemaLogicException('No PK on table ' . $table->getName()); |
62 | 62 | } |
63 | 63 | $refTable = $table->getName(); |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function loadValuesFromTable() : PrimaryKeyRegistry |
76 | 76 | { |
77 | - if (!$this->valuesLoaded){ |
|
77 | + if (!$this->valuesLoaded) { |
|
78 | 78 | $this->values = []; |
79 | 79 | $colNames = implode(",", $this->columnNames); |
80 | 80 | $rows = $this->connection->query("SELECT $colNames FROM " . $this->tableName)->fetchAll(); |
81 | - foreach ($rows as $row){ |
|
81 | + foreach ($rows as $row) { |
|
82 | 82 | $pk = []; |
83 | - foreach ($this->columnNames as $column){ |
|
83 | + foreach ($this->columnNames as $column) { |
|
84 | 84 | $pk[$column] = $row[$column]; |
85 | 85 | } |
86 | 86 | $this->values[] = $pk; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $keys = array_keys($value); |
100 | 100 | sort($keys); |
101 | - if ($this->columnNames != $keys){ |
|
101 | + if ($this->columnNames != $keys) { |
|
102 | 102 | throw new PrimaryKeyColumnMismatchException('PrimaryKeys do not match between PKStore and addValue'); |
103 | 103 | } |
104 | 104 | $this->values[] = $value; |
@@ -45,27 +45,27 @@ |
||
45 | 45 | */ |
46 | 46 | public function getForeignColumn(Table $table, Column $column) : Column |
47 | 47 | { |
48 | - if (isset($this->foreignKeyMappings[$table->getName()][$column->getName()])){ |
|
48 | + if (isset($this->foreignKeyMappings[$table->getName()][$column->getName()])) { |
|
49 | 49 | return $this->foreignKeyMappings[$table->getName()][$column->getName()]["column"]; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $lookupColumn = null; |
53 | 53 | $foreignKeys = $table->getForeignKeys(); |
54 | - foreach ($foreignKeys as $foreignKeyConstraint){ |
|
54 | + foreach ($foreignKeys as $foreignKeyConstraint) { |
|
55 | 55 | $localColumns = $foreignKeyConstraint->getLocalColumns(); |
56 | 56 | $foreignColumns = $foreignKeyConstraint->getForeignColumns(); |
57 | 57 | $foreignTable = $this->schemaManager->listTableDetails($foreignKeyConstraint->getForeignTableName()); |
58 | - foreach ($localColumns as $index => $localColumn){ |
|
58 | + foreach ($localColumns as $index => $localColumn) { |
|
59 | 59 | $foreignColumn = $foreignColumns[$index]; |
60 | 60 | $this->foreignKeyMappings[$table->getName()][$localColumn] = ["table" => $foreignTable, "column" => $foreignTable->getColumn($foreignColumn)]; |
61 | - if ($localColumn === $column->getName()){ |
|
61 | + if ($localColumn === $column->getName()) { |
|
62 | 62 | $lookupColumn = $foreignTable->getColumn($foreignColumn); |
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | - if (!$lookupColumn){ |
|
68 | - throw new SchemaLogicException("Could not find foreign column for local column '".$table->getName().".".$column->getName()."'"); |
|
67 | + if (!$lookupColumn) { |
|
68 | + throw new SchemaLogicException("Could not find foreign column for local column '" . $table->getName() . "." . $column->getName() . "'"); |
|
69 | 69 | } |
70 | 70 | return $lookupColumn; |
71 | 71 | } |
@@ -34,7 +34,7 @@ discard block |
||
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 |
||
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 : 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 |
||
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() ? bcpow('2', '64') : bcsub(bcpow('2', '63') , '1'); |
|
81 | + return $this->column->getUnsigned() ? bcpow('2', '64') : bcsub(bcpow('2', '63'), '1'); |
|
82 | 82 | case Type::INTEGER: |
83 | - return $this->column->getUnsigned() ? bcpow('2', '32') : min($precisionValue, bcsub( bcpow('2', '31') , '1')); |
|
83 | + return $this->column->getUnsigned() ? bcpow('2', '32') : min($precisionValue, bcsub(bcpow('2', '31'), '1')); |
|
84 | 84 | case Type::SMALLINT: |
85 | - return $this->column->getUnsigned() ? bcpow('2', '16') : bcsub( bcpow('2', '15') , '1'); |
|
85 | + return $this->column->getUnsigned() ? bcpow('2', '16') : 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 |
||
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); |