Skip to content

Commit e83b3bd

Browse files
authored
Merge pull request #9104 from kenjis/refactor-TableName
refactor: remove dependency on BaseConnection in TableName
2 parents bc61694 + 640de45 commit e83b3bd

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

system/Commands/Database/ShowTableInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private function showDataOfTable(string $tableName, int $limitRows, int $limitFi
200200
CLI::newLine();
201201

202202
$this->removeDBPrefix();
203-
$thead = $this->db->getFieldNames(TableName::fromActualName($this->db, $tableName));
203+
$thead = $this->db->getFieldNames(TableName::fromActualName($this->db->DBPrefix, $tableName));
204204
$this->restoreDBPrefix();
205205

206206
// If there is a field named `id`, sort by it.
@@ -278,7 +278,7 @@ private function makeTableRows(
278278
$this->tbody = [];
279279

280280
$this->removeDBPrefix();
281-
$builder = $this->db->table(TableName::fromActualName($this->db, $tableName));
281+
$builder = $this->db->table(TableName::fromActualName($this->db->DBPrefix, $tableName));
282282
$builder->limit($limitRows);
283283
if ($sortField !== null) {
284284
$builder->orderBy($sortField, $this->sortDesc ? 'DESC' : 'ASC');

system/Database/TableName.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ protected function __construct(
4444
* @param string $table Table name (w/o DB prefix)
4545
* @param string $alias Alias name
4646
*/
47-
public static function create(BaseConnection $db, string $table, string $alias = ''): self
47+
public static function create(string $dbPrefix, string $table, string $alias = ''): self
4848
{
4949
return new self(
50-
$db->DBPrefix . $table,
50+
$dbPrefix . $table,
5151
$table,
5252
'',
5353
'',
@@ -61,9 +61,9 @@ public static function create(BaseConnection $db, string $table, string $alias =
6161
* @param string $actualTable Actual table name with DB prefix
6262
* @param string $alias Alias name
6363
*/
64-
public static function fromActualName(BaseConnection $db, string $actualTable, string $alias = ''): self
64+
public static function fromActualName(string $dbPrefix, string $actualTable, string $alias = ''): self
6565
{
66-
$prefix = $db->DBPrefix;
66+
$prefix = $dbPrefix;
6767
$logicalTable = '';
6868

6969
if (str_starts_with($actualTable, $prefix)) {
@@ -87,14 +87,14 @@ public static function fromActualName(BaseConnection $db, string $actualTable, s
8787
* @param string $alias Alias name
8888
*/
8989
public static function fromFullName(
90-
BaseConnection $db,
90+
string $dbPrefix,
9191
string $table,
9292
string $schema = '',
9393
string $database = '',
9494
string $alias = ''
9595
): self {
9696
return new self(
97-
$db->DBPrefix . $table,
97+
$dbPrefix . $table,
9898
$table,
9999
$schema,
100100
$database,

tests/system/Database/Builder/AliasTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testAlias(): void
4444

4545
public function testTableName(): void
4646
{
47-
$tableName = TableName::create($this->db, 'jobs', 'j');
47+
$tableName = TableName::create($this->db->DBPrefix, 'jobs', 'j');
4848
$builder = $this->db->table($tableName);
4949

5050
$expectedSQL = 'SELECT * FROM "jobs" "j"';

tests/system/Database/TableNameTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testInstantiate(): void
3838
{
3939
$table = 'table';
4040

41-
$tableName = TableName::create($this->db, $table);
41+
$tableName = TableName::create($this->db->DBPrefix, $table);
4242

4343
$this->assertInstanceOf(TableName::class, $tableName);
4444
}
@@ -47,7 +47,7 @@ public function testCreateAndTableName(): void
4747
{
4848
$table = 'table';
4949

50-
$tableName = TableName::create($this->db, $table);
50+
$tableName = TableName::create($this->db->DBPrefix, $table);
5151

5252
$this->assertSame($table, $tableName->getTableName());
5353
$this->assertSame('db_table', $tableName->getActualTableName());
@@ -57,7 +57,7 @@ public function testFromActualNameAndTableNameWithPrefix(): void
5757
{
5858
$actualTable = 'db_table';
5959

60-
$tableName = TableName::fromActualName($this->db, $actualTable);
60+
$tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable);
6161

6262
$this->assertSame('table', $tableName->getTableName());
6363
$this->assertSame($actualTable, $tableName->getActualTableName());
@@ -67,7 +67,7 @@ public function testFromActualNameAndTableNameWithoutPrefix(): void
6767
{
6868
$actualTable = 'table';
6969

70-
$tableName = TableName::fromActualName($this->db, $actualTable);
70+
$tableName = TableName::fromActualName($this->db->DBPrefix, $actualTable);
7171

7272
$this->assertSame('', $tableName->getTableName());
7373
$this->assertSame($actualTable, $tableName->getActualTableName());
@@ -78,7 +78,7 @@ public function testGetAlias(): void
7878
$table = 'table';
7979
$alias = 't';
8080

81-
$tableName = TableName::create($this->db, $table, $alias);
81+
$tableName = TableName::create($this->db->DBPrefix, $table, $alias);
8282

8383
$this->assertSame($alias, $tableName->getAlias());
8484
}
@@ -89,7 +89,7 @@ public function testGetSchema(): void
8989
$schema = 'dbo';
9090
$database = 'test';
9191

92-
$tableName = TableName::fromFullName($this->db, $table, $schema, $database);
92+
$tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database);
9393

9494
$this->assertSame($schema, $tableName->getSchema());
9595
}
@@ -100,7 +100,7 @@ public function testGetDatabase(): void
100100
$schema = 'dbo';
101101
$database = 'test';
102102

103-
$tableName = TableName::fromFullName($this->db, $table, $schema, $database);
103+
$tableName = TableName::fromFullName($this->db->DBPrefix, $table, $schema, $database);
104104

105105
$this->assertSame($database, $tableName->getDatabase());
106106
}

0 commit comments

Comments
 (0)