Skip to content

Commit a038670

Browse files
authored
Rename Db\Table\Table to TableMetadata (#911)
Having both `Migrations\Db\Table` and `Migrations\Db\Table\Table` can make reading migrations code confusing to read. Renaming one of the classes to TableMetadata avoids confusion.
1 parent 81aa362 commit a038670

29 files changed

Lines changed: 194 additions & 190 deletions

src/Db/Action/Action.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88

99
namespace Migrations\Db\Action;
1010

11-
use Migrations\Db\Table\Table;
11+
use Migrations\Db\Table\TableMetadata;
1212

1313
abstract class Action
1414
{
1515
/**
16-
* @var \Migrations\Db\Table\Table
16+
* @var \Migrations\Db\Table\TableMetadata
1717
*/
18-
protected Table $table;
18+
protected TableMetadata $table;
1919

2020
/**
2121
* Constructor
2222
*
23-
* @param \Migrations\Db\Table\Table $table the Table to apply the action to
23+
* @param \Migrations\Db\Table\TableMetadata $table the Table to apply the action to
2424
*/
25-
public function __construct(Table $table)
25+
public function __construct(TableMetadata $table)
2626
{
2727
$this->table = $table;
2828
}
2929

3030
/**
3131
* The table this action will be applied to
3232
*
33-
* @return \Migrations\Db\Table\Table
33+
* @return \Migrations\Db\Table\TableMetadata
3434
*/
35-
public function getTable(): Table
35+
public function getTable(): TableMetadata
3636
{
3737
return $this->table;
3838
}

src/Db/Action/AddColumn.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Migrations\Db\Literal;
1212
use Migrations\Db\Table\Column;
13-
use Migrations\Db\Table\Table;
13+
use Migrations\Db\Table\TableMetadata;
1414

1515
class AddColumn extends Action
1616
{
@@ -24,10 +24,10 @@ class AddColumn extends Action
2424
/**
2525
* Constructor
2626
*
27-
* @param \Migrations\Db\Table\Table $table The table to add the column to
27+
* @param \Migrations\Db\Table\TableMetadata $table The table to add the column to
2828
* @param \Migrations\Db\Table\Column $column The column to add
2929
*/
30-
public function __construct(Table $table, Column $column)
30+
public function __construct(TableMetadata $table, Column $column)
3131
{
3232
parent::__construct($table);
3333
$this->column = $column;
@@ -36,13 +36,13 @@ public function __construct(Table $table, Column $column)
3636
/**
3737
* Returns a new AddColumn object after assembling the given commands
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table to add the column to
39+
* @param \Migrations\Db\Table\TableMetadata $table The table to add the column to
4040
* @param string $columnName The column name
4141
* @param string|\Migrations\Db\Literal $type The column type
4242
* @param array<string, mixed> $options The column options
4343
* @return self
4444
*/
45-
public static function build(Table $table, string $columnName, string|Literal $type, array $options = []): self
45+
public static function build(TableMetadata $table, string $columnName, string|Literal $type, array $options = []): self
4646
{
4747
$column = new Column();
4848
$column->setName($columnName);

src/Db/Action/AddForeignKey.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Migrations\Db\Action;
1010

1111
use Migrations\Db\Table\ForeignKey;
12-
use Migrations\Db\Table\Table;
12+
use Migrations\Db\Table\TableMetadata;
1313

1414
class AddForeignKey extends Action
1515
{
@@ -23,10 +23,10 @@ class AddForeignKey extends Action
2323
/**
2424
* Constructor
2525
*
26-
* @param \Migrations\Db\Table\Table $table The table to add the foreign key to
26+
* @param \Migrations\Db\Table\TableMetadata $table The table to add the foreign key to
2727
* @param \Migrations\Db\Table\ForeignKey $fk The foreign key to add
2828
*/
29-
public function __construct(Table $table, ForeignKey $fk)
29+
public function __construct(TableMetadata $table, ForeignKey $fk)
3030
{
3131
parent::__construct($table);
3232
$this->foreignKey = $fk;
@@ -36,22 +36,28 @@ public function __construct(Table $table, ForeignKey $fk)
3636
* Creates a new AddForeignKey object after building the foreign key with
3737
* the passed attributes
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table object to add the foreign key to
39+
* @param \Migrations\Db\Table\TableMetadata $table The table object to add the foreign key to
4040
* @param string|string[] $columns The columns for the foreign key
41-
* @param \Migrations\Db\Table\Table|string $referencedTable The table the foreign key references
41+
* @param \Migrations\Db\Table\TableMetadata|string $referencedTable The table the foreign key references
4242
* @param string|string[] $referencedColumns The columns in the referenced table
4343
* @param array<string, mixed> $options Extra options for the foreign key
4444
* @param string|null $name The name of the foreign key
4545
* @return self
4646
*/
47-
public static function build(Table $table, string|array $columns, Table|string $referencedTable, string|array $referencedColumns = ['id'], array $options = [], ?string $name = null): self
48-
{
47+
public static function build(
48+
TableMetadata $table,
49+
string|array $columns,
50+
TableMetadata|string $referencedTable,
51+
string|array $referencedColumns = ['id'],
52+
array $options = [],
53+
?string $name = null,
54+
): self {
4955
if (is_string($referencedColumns)) {
5056
$referencedColumns = [$referencedColumns]; // str to array
5157
}
5258

5359
if (is_string($referencedTable)) {
54-
$referencedTable = new Table($referencedTable);
60+
$referencedTable = new TableMetadata($referencedTable);
5561
}
5662

5763
// Shimming old 4.x

src/Db/Action/AddIndex.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Migrations\Db\Action;
1010

1111
use Migrations\Db\Table\Index;
12-
use Migrations\Db\Table\Table;
12+
use Migrations\Db\Table\TableMetadata;
1313

1414
class AddIndex extends Action
1515
{
@@ -23,10 +23,10 @@ class AddIndex extends Action
2323
/**
2424
* Constructor
2525
*
26-
* @param \Migrations\Db\Table\Table $table The table to add the index to
26+
* @param \Migrations\Db\Table\TableMetadata $table The table to add the index to
2727
* @param \Migrations\Db\Table\Index $index The index to be added
2828
*/
29-
public function __construct(Table $table, Index $index)
29+
public function __construct(TableMetadata $table, Index $index)
3030
{
3131
parent::__construct($table);
3232
$this->index = $index;
@@ -36,12 +36,12 @@ public function __construct(Table $table, Index $index)
3636
* Creates a new AddIndex object after building the index object with the
3737
* provided arguments
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table to add the index to
39+
* @param \Migrations\Db\Table\TableMetadata $table The table to add the index to
4040
* @param string|string[]|\Migrations\Db\Table\Index $columns The columns to index
4141
* @param array<string, mixed> $options Additional options for the index creation
4242
* @return self
4343
*/
44-
public static function build(Table $table, string|array|Index $columns, array $options = []): self
44+
public static function build(TableMetadata $table, string|array|Index $columns, array $options = []): self
4545
{
4646
// create a new index object if strings or an array of strings were supplied
4747
if (!($columns instanceof Index)) {

src/Db/Action/ChangeColumn.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Migrations\Db\Literal;
1212
use Migrations\Db\Table\Column;
13-
use Migrations\Db\Table\Table;
13+
use Migrations\Db\Table\TableMetadata;
1414

1515
class ChangeColumn extends Action
1616
{
@@ -31,11 +31,11 @@ class ChangeColumn extends Action
3131
/**
3232
* Constructor
3333
*
34-
* @param \Migrations\Db\Table\Table $table The table to alter
34+
* @param \Migrations\Db\Table\TableMetadata $table The table to alter
3535
* @param string $columnName The name of the column to change
3636
* @param \Migrations\Db\Table\Column $column The column definition
3737
*/
38-
public function __construct(Table $table, string $columnName, Column $column)
38+
public function __construct(TableMetadata $table, string $columnName, Column $column)
3939
{
4040
parent::__construct($table);
4141
$this->columnName = $columnName;
@@ -51,13 +51,13 @@ public function __construct(Table $table, string $columnName, Column $column)
5151
* Creates a new ChangeColumn object after building the column definition
5252
* out of the provided arguments
5353
*
54-
* @param \Migrations\Db\Table\Table $table The table to alter
54+
* @param \Migrations\Db\Table\TableMetadata $table The table to alter
5555
* @param string $columnName The name of the column to change
5656
* @param string|\Migrations\Db\Literal $type The type of the column
5757
* @param array<string, mixed> $options Additional options for the column
5858
* @return self
5959
*/
60-
public static function build(Table $table, string $columnName, string|Literal $type, array $options = []): self
60+
public static function build(TableMetadata $table, string $columnName, string|Literal $type, array $options = []): self
6161
{
6262
$column = new Column();
6363
$column->setName($columnName);

src/Db/Action/ChangeComment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Migrations\Db\Action;
1010

11-
use Migrations\Db\Table\Table;
11+
use Migrations\Db\Table\TableMetadata;
1212

1313
class ChangeComment extends Action
1414
{
@@ -22,10 +22,10 @@ class ChangeComment extends Action
2222
/**
2323
* Constructor
2424
*
25-
* @param \Migrations\Db\Table\Table $table The table to be changed
25+
* @param \Migrations\Db\Table\TableMetadata $table The table to be changed
2626
* @param string|null $newComment The new comment for the table
2727
*/
28-
public function __construct(Table $table, ?string $newComment)
28+
public function __construct(TableMetadata $table, ?string $newComment)
2929
{
3030
parent::__construct($table);
3131
$this->newComment = $newComment;

src/Db/Action/ChangePrimaryKey.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Migrations\Db\Action;
1010

11-
use Migrations\Db\Table\Table;
11+
use Migrations\Db\Table\TableMetadata;
1212

1313
class ChangePrimaryKey extends Action
1414
{
@@ -22,10 +22,10 @@ class ChangePrimaryKey extends Action
2222
/**
2323
* Constructor
2424
*
25-
* @param \Migrations\Db\Table\Table $table The table to be changed
25+
* @param \Migrations\Db\Table\TableMetadata $table The table to be changed
2626
* @param string|string[]|null $newColumns The new columns for the primary key
2727
*/
28-
public function __construct(Table $table, string|array|null $newColumns)
28+
public function __construct(TableMetadata $table, string|array|null $newColumns)
2929
{
3030
parent::__construct($table);
3131
$this->newColumns = $newColumns;

src/Db/Action/DropForeignKey.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Migrations\Db\Action;
1010

1111
use Migrations\Db\Table\ForeignKey;
12-
use Migrations\Db\Table\Table;
12+
use Migrations\Db\Table\TableMetadata;
1313

1414
class DropForeignKey extends Action
1515
{
@@ -23,10 +23,10 @@ class DropForeignKey extends Action
2323
/**
2424
* Constructor
2525
*
26-
* @param \Migrations\Db\Table\Table $table The table to remove the constraint from
26+
* @param \Migrations\Db\Table\TableMetadata $table The table to remove the constraint from
2727
* @param \Migrations\Db\Table\ForeignKey $foreignKey The foreign key to remove
2828
*/
29-
public function __construct(Table $table, ForeignKey $foreignKey)
29+
public function __construct(TableMetadata $table, ForeignKey $foreignKey)
3030
{
3131
parent::__construct($table);
3232
$this->foreignKey = $foreignKey;
@@ -36,12 +36,12 @@ public function __construct(Table $table, ForeignKey $foreignKey)
3636
* Creates a new DropForeignKey object after building the ForeignKey
3737
* definition out of the passed arguments.
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table to delete the foreign key from
39+
* @param \Migrations\Db\Table\TableMetadata $table The table to delete the foreign key from
4040
* @param string|string[] $columns The columns participating in the foreign key
4141
* @param string|null $constraint The constraint name
4242
* @return self
4343
*/
44-
public static function build(Table $table, string|array $columns, ?string $constraint = null): self
44+
public static function build(TableMetadata $table, string|array $columns, ?string $constraint = null): self
4545
{
4646
if (is_string($columns)) {
4747
$columns = [$columns];

src/Db/Action/DropIndex.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Migrations\Db\Action;
1010

1111
use Migrations\Db\Table\Index;
12-
use Migrations\Db\Table\Table;
12+
use Migrations\Db\Table\TableMetadata;
1313

1414
class DropIndex extends Action
1515
{
@@ -23,10 +23,10 @@ class DropIndex extends Action
2323
/**
2424
* Constructor
2525
*
26-
* @param \Migrations\Db\Table\Table $table The table owning the index
26+
* @param \Migrations\Db\Table\TableMetadata $table The table owning the index
2727
* @param \Migrations\Db\Table\Index $index The index to be dropped
2828
*/
29-
public function __construct(Table $table, Index $index)
29+
public function __construct(TableMetadata $table, Index $index)
3030
{
3131
parent::__construct($table);
3232
$this->index = $index;
@@ -36,11 +36,11 @@ public function __construct(Table $table, Index $index)
3636
* Creates a new DropIndex object after assembling the passed
3737
* arguments.
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table where the index is
39+
* @param \Migrations\Db\Table\TableMetadata $table The table where the index is
4040
* @param string[] $columns the indexed columns
4141
* @return self
4242
*/
43-
public static function build(Table $table, array $columns = []): self
43+
public static function build(TableMetadata $table, array $columns = []): self
4444
{
4545
$index = new Index();
4646
$index->setColumns($columns);
@@ -52,11 +52,11 @@ public static function build(Table $table, array $columns = []): self
5252
* Creates a new DropIndex when the name of the index to drop
5353
* is known.
5454
*
55-
* @param \Migrations\Db\Table\Table $table The table where the index is
55+
* @param \Migrations\Db\Table\TableMetadata $table The table where the index is
5656
* @param string $name The name of the index
5757
* @return self
5858
*/
59-
public static function buildFromName(Table $table, string $name): self
59+
public static function buildFromName(TableMetadata $table, string $name): self
6060
{
6161
$index = new Index();
6262
$index->setName($name);

src/Db/Action/RemoveColumn.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Migrations\Db\Action;
1010

1111
use Migrations\Db\Table\Column;
12-
use Migrations\Db\Table\Table;
12+
use Migrations\Db\Table\TableMetadata;
1313

1414
class RemoveColumn extends Action
1515
{
@@ -23,10 +23,10 @@ class RemoveColumn extends Action
2323
/**
2424
* Constructor
2525
*
26-
* @param \Migrations\Db\Table\Table $table The table where the column is
26+
* @param \Migrations\Db\Table\TableMetadata $table The table where the column is
2727
* @param \Migrations\Db\Table\Column $column The column to be removed
2828
*/
29-
public function __construct(Table $table, Column $column)
29+
public function __construct(TableMetadata $table, Column $column)
3030
{
3131
parent::__construct($table);
3232
$this->column = $column;
@@ -36,11 +36,11 @@ public function __construct(Table $table, Column $column)
3636
* Creates a new RemoveColumn object after assembling the
3737
* passed arguments.
3838
*
39-
* @param \Migrations\Db\Table\Table $table The table where the column is
39+
* @param \Migrations\Db\Table\TableMetadata $table The table where the column is
4040
* @param string $columnName The name of the column to drop
4141
* @return self
4242
*/
43-
public static function build(Table $table, string $columnName): self
43+
public static function build(TableMetadata $table, string $columnName): self
4444
{
4545
$column = new Column();
4646
$column->setName($columnName);

0 commit comments

Comments
 (0)