@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | /** |
| 201 | 201 | * @param DB $db |
| 202 | 202 | */ |
| 203 | - public function __construct (DB $db) { |
|
| 203 | + public function __construct(DB $db) { |
|
| 204 | 204 | $this->db = $db; |
| 205 | 205 | $this->colDefs ??= self::COLUMN_DEFINITIONS[$db->getDriver()]; |
| 206 | 206 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @param int $type |
| 214 | 214 | * @return $this |
| 215 | 215 | */ |
| 216 | - public function addColumn (string $table, string $column, int $type = self::T_STRING) { |
|
| 216 | + public function addColumn(string $table, string $column, int $type = self::T_STRING) { |
|
| 217 | 217 | $type = $this->colDefs[$type & self::T_MASK]; |
| 218 | 218 | $this->db->exec("ALTER TABLE {$table} ADD COLUMN {$column} {$type}"); |
| 219 | 219 | unset($this->tables[$table]); |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param array[] $constraints `[ <TABLE_CONST> => spec ]` |
| 240 | 240 | * @return $this |
| 241 | 241 | */ |
| 242 | - public function createTable (string $table, array $columns, array $constraints = []) { |
|
| 242 | + public function createTable(string $table, array $columns, array $constraints = []) { |
|
| 243 | 243 | $defs = $this->toColumnDefinitions($columns); |
| 244 | 244 | |
| 245 | 245 | /** @var string[] $pk */ |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param string $column |
| 276 | 276 | * @return $this |
| 277 | 277 | */ |
| 278 | - public function dropColumn (string $table, string $column) { |
|
| 278 | + public function dropColumn(string $table, string $column) { |
|
| 279 | 279 | $this->db->exec("ALTER TABLE {$table} DROP COLUMN {$column}"); |
| 280 | 280 | unset($this->tables[$table]); |
| 281 | 281 | return $this; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @param string $table |
| 288 | 288 | */ |
| 289 | - public function dropTable (string $table): void { |
|
| 289 | + public function dropTable(string $table): void { |
|
| 290 | 290 | $this->db->exec("DROP TABLE IF EXISTS {$table}"); |
| 291 | 291 | unset($this->tables[$table]); |
| 292 | 292 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | /** |
| 295 | 295 | * @return DB |
| 296 | 296 | */ |
| 297 | - public function getDb () { |
|
| 297 | + public function getDb() { |
|
| 298 | 298 | return $this->db; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param string $name |
| 303 | 303 | * @return null|Table |
| 304 | 304 | */ |
| 305 | - public function getTable (string $name) { |
|
| 305 | + public function getTable(string $name) { |
|
| 306 | 306 | if (!isset($this->tables[$name])) { |
| 307 | 307 | if ($this->db->isSQLite()) { |
| 308 | 308 | $info = $this->db->query("PRAGMA table_info({$name})")->fetchAll(); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @param string $table |
| 328 | 328 | * @return bool |
| 329 | 329 | */ |
| 330 | - final public function offsetExists ($table): bool { |
|
| 330 | + final public function offsetExists($table): bool { |
|
| 331 | 331 | return (bool)$this->offsetGet($table); |
| 332 | 332 | } |
| 333 | 333 | |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param string $table |
| 338 | 338 | * @return null|Table |
| 339 | 339 | */ |
| 340 | - public function offsetGet ($table) { |
|
| 340 | + public function offsetGet($table) { |
|
| 341 | 341 | return $this->getTable($table); |
| 342 | 342 | } |
| 343 | 343 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @param $value |
| 347 | 347 | * @throws LogicException |
| 348 | 348 | */ |
| 349 | - final public function offsetSet ($offset, $value) { |
|
| 349 | + final public function offsetSet($offset, $value) { |
|
| 350 | 350 | throw new LogicException('The schema cannot be altered this way.'); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * @param $offset |
| 355 | 355 | * @throws LogicException |
| 356 | 356 | */ |
| 357 | - final public function offsetUnset ($offset) { |
|
| 357 | + final public function offsetUnset($offset) { |
|
| 358 | 358 | throw new LogicException('The schema cannot be altered this way.'); |
| 359 | 359 | } |
| 360 | 360 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @param string $newName |
| 367 | 367 | * @return $this |
| 368 | 368 | */ |
| 369 | - public function renameColumn (string $table, string $oldName, string $newName) { |
|
| 369 | + public function renameColumn(string $table, string $oldName, string $newName) { |
|
| 370 | 370 | $this->db->exec("ALTER TABLE {$table} RENAME COLUMN {$oldName} TO {$newName}"); |
| 371 | 371 | unset($this->tables[$table]); |
| 372 | 372 | return $this; |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | * @param string $newName |
| 380 | 380 | * @return $this |
| 381 | 381 | */ |
| 382 | - public function renameTable (string $oldName, string $newName) { |
|
| 382 | + public function renameTable(string $oldName, string $newName) { |
|
| 383 | 383 | $this->db->exec("ALTER TABLE {$oldName} RENAME TO {$newName}"); |
| 384 | 384 | unset($this->tables[$oldName]); |
| 385 | 385 | return $this; |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | * @param int[] $types |
| 392 | 392 | * @return int[] |
| 393 | 393 | */ |
| 394 | - protected function sortColumns (array $types): array { |
|
| 394 | + protected function sortColumns(array $types): array { |
|
| 395 | 395 | uksort($types, function(string $a, string $b) use ($types) { |
| 396 | 396 | // descending index priority, increasing size, name |
| 397 | 397 | return $types[$b] <=> $types[$a] ?: $a <=> $b; |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @param int[] $columns `[ name => <I_CONST> | <T_CONST> ]` |
| 404 | 404 | * @return string[] |
| 405 | 405 | */ |
| 406 | - protected function toColumnDefinitions (array $columns): array { |
|
| 406 | + protected function toColumnDefinitions(array $columns): array { |
|
| 407 | 407 | assert(count($columns) > 0); |
| 408 | 408 | $columns = $this->sortColumns($columns); |
| 409 | 409 | $defs = []; |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @param Column $foreign |
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | - protected function toForeignKeyConstraint (string $table, string $local, int $type, Column $foreign): string { |
|
| 432 | + protected function toForeignKeyConstraint(string $table, string $local, int $type, Column $foreign): string { |
|
| 433 | 433 | return sprintf( |
| 434 | 434 | 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s) ON UPDATE CASCADE ON DELETE %s', |
| 435 | 435 | $this->toForeignKeyConstraint_name($table, $local), |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @param string $column |
| 448 | 448 | * @return string |
| 449 | 449 | */ |
| 450 | - protected function toForeignKeyConstraint_name (string $table, string $column): string { |
|
| 450 | + protected function toForeignKeyConstraint_name(string $table, string $column): string { |
|
| 451 | 451 | return 'FK_' . $table . '__' . $column; |
| 452 | 452 | } |
| 453 | 453 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * @param string[] $columns |
| 457 | 457 | * @return string |
| 458 | 458 | */ |
| 459 | - protected function toPrimaryKeyConstraint (string $table, array $columns): string { |
|
| 459 | + protected function toPrimaryKeyConstraint(string $table, array $columns): string { |
|
| 460 | 460 | return sprintf( |
| 461 | 461 | 'CONSTRAINT %s PRIMARY KEY (%s)', |
| 462 | 462 | $this->toPrimaryKeyConstraint_name($table, $columns), |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @param string[] $columns |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | - protected function toPrimaryKeyConstraint_name (string $table, array $columns): string { |
|
| 474 | + protected function toPrimaryKeyConstraint_name(string $table, array $columns): string { |
|
| 475 | 475 | sort($columns, SORT_STRING); |
| 476 | 476 | return 'PK_' . $table . '__' . implode('__', $columns); |
| 477 | 477 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @param string[] $columns |
| 482 | 482 | * @return string |
| 483 | 483 | */ |
| 484 | - protected function toUniqueKeyConstraint (string $table, array $columns): string { |
|
| 484 | + protected function toUniqueKeyConstraint(string $table, array $columns): string { |
|
| 485 | 485 | return sprintf( |
| 486 | 486 | 'CONSTRAINT %s UNIQUE (%s)', |
| 487 | 487 | $this->toUniqueKeyConstraint_name($table, $columns), |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | * @param string[] $columns |
| 497 | 497 | * @return string |
| 498 | 498 | */ |
| 499 | - protected function toUniqueKeyConstraint_name (string $table, array $columns): string { |
|
| 499 | + protected function toUniqueKeyConstraint_name(string $table, array $columns): string { |
|
| 500 | 500 | sort($columns, SORT_STRING); |
| 501 | 501 | return 'UQ_' . $table . '__' . implode('__', $columns); |
| 502 | 502 | } |