@@ -188,7 +188,7 @@ |
||
| 188 | 188 | { |
| 189 | 189 | $statements = []; |
| 190 | 190 | foreach ($modificationsBetweenTable as $modifications) { |
| 191 | - foreach ((array)$modifications as $modification) { |
|
| 191 | + foreach ((array) $modifications as $modification) { |
|
| 192 | 192 | $statements[] = $modification; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | try { |
| 47 | 47 | $export = $factoryJsonDatabase->generate(); |
| 48 | 48 | } catch (\Exception $e) { |
| 49 | - throw new \LogicException('Un expected error with json.' . $e->getMessage()); |
|
| 49 | + throw new \LogicException('Un expected error with json.'.$e->getMessage()); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | return $export; |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | } catch (\Exception $e) { |
| 58 | 58 | continue; |
| 59 | 59 | } |
| 60 | - foreach ((array)$dataTable['columns'] as $columnName => $row) { |
|
| 60 | + foreach ((array) $dataTable['columns'] as $columnName => $row) { |
|
| 61 | 61 | $table->addColumn(new MysqlDatabaseColumn($columnName, $row['type'], $row['length'], $row['nullable'], $row['defaultValue'], $row['extra'])); |
| 62 | 62 | } |
| 63 | - foreach ((array)$dataTable['indexes'] as $row) { |
|
| 63 | + foreach ((array) $dataTable['indexes'] as $row) { |
|
| 64 | 64 | $table->addIndex($row['columns'], $row['name']); |
| 65 | 65 | } |
| 66 | 66 | if (isset($dataTable['primary'])) { |
| 67 | - $table->addPrimary((array)$dataTable['primary']); |
|
| 67 | + $table->addPrimary((array) $dataTable['primary']); |
|
| 68 | 68 | } |
| 69 | - foreach ((array)$dataTable['uniques'] as $row) { |
|
| 69 | + foreach ((array) $dataTable['uniques'] as $row) { |
|
| 70 | 70 | $table->addUnique($row['columns'], $row['name']); |
| 71 | 71 | } |
| 72 | 72 | $tables[] = $table; |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | $export = []; |
| 130 | 130 | foreach ($data as $nomTable => $table) { |
| 131 | 131 | $dataTable = $resolverTable->resolve($table); |
| 132 | - foreach ((array)$dataTable['columns'] as $columnName => $column) { |
|
| 132 | + foreach ((array) $dataTable['columns'] as $columnName => $column) { |
|
| 133 | 133 | $dataTable['columns'][$columnName] = $resolverColumns->resolve($column); |
| 134 | 134 | } |
| 135 | - foreach ((array)$dataTable['indexes'] as $keyIndex => $index) { |
|
| 135 | + foreach ((array) $dataTable['indexes'] as $keyIndex => $index) { |
|
| 136 | 136 | $dataTable['indexes'][$keyIndex] = $resolverIndex->resolve($index); |
| 137 | 137 | } |
| 138 | - foreach ((array)$dataTable['uniques'] as $keyIndex => $index) { |
|
| 138 | + foreach ((array) $dataTable['uniques'] as $keyIndex => $index) { |
|
| 139 | 139 | $dataTable['uniques'][$keyIndex] = $resolverIndex->resolve($index); |
| 140 | 140 | } |
| 141 | 141 | $export[$nomTable] = $dataTable; |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | return strtolower($this->name) == 'primary'; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function getIndexType(){ |
|
| 110 | - if($this->isPrimary()){ |
|
| 109 | + public function getIndexType() { |
|
| 110 | + if ($this->isPrimary()) { |
|
| 111 | 111 | return 'PRIMARY'; |
| 112 | 112 | } |
| 113 | - if($this->isUnique()){ |
|
| 113 | + if ($this->isUnique()) { |
|
| 114 | 114 | return 'UNIQUE'; |
| 115 | 115 | } |
| 116 | 116 | return ''; |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | throw new TableHasNotDefinedException('table not defined'); |
| 128 | 128 | } |
| 129 | 129 | if ($this->isPrimary()) { |
| 130 | - return [sprintf('ALTER TABLE `%s` ADD PRIMARY KEY (%s);', $this->getTable(), '`' . implode('`, `', $this->getColumns()) . '`')]; |
|
| 130 | + return [sprintf('ALTER TABLE `%s` ADD PRIMARY KEY (%s);', $this->getTable(), '`'.implode('`, `', $this->getColumns()).'`')]; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return [sprintf('ALTER TABLE `%s` ADD %s INDEX `%s` (%s);', $this->getTable(), $this->getIndexType() ,$this->getName(), '`' . implode('`, `', $this->getColumns()) . '`')]; |
|
| 133 | + return [sprintf('ALTER TABLE `%s` ADD %s INDEX `%s` (%s);', $this->getTable(), $this->getIndexType(), $this->getName(), '`'.implode('`, `', $this->getColumns()).'`')]; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | private function formatCreateStatement(array $modifications) |
| 177 | 177 | { |
| 178 | - if(!$finalStatement = array_shift($modifications)){ |
|
| 178 | + if (!$finalStatement = array_shift($modifications)) { |
|
| 179 | 179 | return []; |
| 180 | 180 | } |
| 181 | 181 | $tmp = []; |
| 182 | 182 | foreach ($modifications as $modification) { |
| 183 | - $tmp[] = str_replace(['ALTER TABLE `'.$this->getTable().'` ADD COLUMN', 'ALTER TABLE `'.$this->getTable().'` ADD ', ';',], '', $modification); |
|
| 183 | + $tmp[] = str_replace(['ALTER TABLE `'.$this->getTable().'` ADD COLUMN', 'ALTER TABLE `'.$this->getTable().'` ADD ', ';', ], '', $modification); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return [$finalStatement.'('.implode(',', $tmp).');']; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | { |
| 196 | 196 | $statements = []; |
| 197 | 197 | foreach ($modificationsBetweenTable as $modifications) { |
| 198 | - foreach ((array)$modifications as $modification) { |
|
| 198 | + foreach ((array) $modifications as $modification) { |
|
| 199 | 199 | $statements[] = $modification; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $isEnum = explode('enum', $this->type); |
| 54 | 54 | if ($isEnum) { |
| 55 | - $numberElements = substr_count(str_replace(['(', ')', "'",], '', $isEnum[1]), ',') + 1; |
|
| 55 | + $numberElements = substr_count(str_replace(['(', ')', "'", ], '', $isEnum[1]), ',') + 1; |
|
| 56 | 56 | if ($numberElements == 2) { |
| 57 | 57 | $this->type = 'tinyint'; |
| 58 | 58 | $this->length = 1; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | $baseType = $this->type; |
| 133 | 133 | if (in_array($baseType, ['int', 'mediumint', 'tinyint', 'smallint', 'binary', 'varchar', 'bigint', 'char', 'float'], false)) { |
| 134 | - $baseType = $baseType . '(' . $this->length . ')'; |
|
| 134 | + $baseType = $baseType.'('.$this->length.')'; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return $baseType; |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | throw new TableHasNotDefinedException('table not defined'); |
| 149 | 149 | } |
| 150 | 150 | $null = $this->getNullable() ? '' : 'NOT'; |
| 151 | - $default = $this->getDefaultValue() == false ? '' : ' DEFAULT ' . $this->getDefaultValue(); |
|
| 151 | + $default = $this->getDefaultValue() == false ? '' : ' DEFAULT '.$this->getDefaultValue(); |
|
| 152 | 152 | $modification = sprintf('ALTER TABLE `%s` ADD COLUMN `%s` %s %s NULL %s %s;', $this->getTable(), $this->getName(), $this->getColonneType(), $null, $default, $this->getExtra()); |
| 153 | 153 | |
| 154 | - return [str_replace([' ', ' ',], ' ', $modification)]; |
|
| 154 | + return [str_replace([' ', ' ', ], ' ', $modification)]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | throw new TableHasNotDefinedException('table not defined'); |
| 166 | 166 | } |
| 167 | 167 | $null = $this->getNullable() ? '' : 'NOT'; |
| 168 | - $default = $this->getDefaultValue() == false ? '' : ' DEFAULT ' . $this->getDefaultValue(); |
|
| 169 | - $columnName = '`' . $this->getName() . '`'; |
|
| 168 | + $default = $this->getDefaultValue() == false ? '' : ' DEFAULT '.$this->getDefaultValue(); |
|
| 169 | + $columnName = '`'.$this->getName().'`'; |
|
| 170 | 170 | $modification = sprintf('ALTER TABLE `%s` CHANGE COLUMN %s %s %s %s NULL %s %s;', $this->getTable(), $columnName, $columnName, $this->getColonneType(), $null, $default, $this->getExtra()); |
| 171 | 171 | |
| 172 | - return [str_replace([' ', ' ',], ' ', $modification)]; |
|
| 172 | + return [str_replace([' ', ' ', ], ' ', $modification)]; |
|
| 173 | 173 | } |
| 174 | 174 | } |