Skip to content

Commit c5492e7

Browse files
Add phpdoc, minor improvements. (#64)
1 parent dc7c95d commit c5492e7

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/DbCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* DbCache stores cache data in a database table.
3131
*
32-
* Use {@see DbHelper::ensureTable()} to initialize database schema.
32+
* Use {@see DbSchemaManager::ensureTable()} to initialize database schema.
3333
*/
3434
final class DbCache implements CacheInterface
3535
{

src/DbSchemaManager.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
use Yiisoft\Db\Exception\NotSupportedException;
1212
use Yiisoft\Db\Schema\SchemaInterface;
1313

14+
/**
15+
* Manages the cache table schema in the database.
16+
*/
1417
final class DbSchemaManager
1518
{
1619
public function __construct(private ConnectionInterface $db)
1720
{
1821
}
1922

2023
/**
24+
* Ensures that the cache table exists in the database.
25+
*
26+
* @param string $table The name of the cache table. Defaults to '{{%yii_cache}}'.
27+
*
2128
* @throws Exception
2229
* @throws NotSupportedException
2330
* @throws InvalidConfigException
@@ -26,14 +33,13 @@ public function __construct(private ConnectionInterface $db)
2633
public function ensureTable(string $table = '{{%yii_cache}}'): void
2734
{
2835
$schema = $this->db->getSchema();
29-
$command = $this->db->createCommand();
3036
$tableRawName = $schema->getRawTableName($table);
3137

3238
if ($this->hasTable($table)) {
3339
return;
3440
}
3541

36-
$command->createTable(
42+
$this->db->createCommand()->createTable(
3743
$table,
3844
[
3945
'id' => $schema->createColumn(SchemaInterface::TYPE_STRING, 128)->notNull(),
@@ -45,6 +51,10 @@ public function ensureTable(string $table = '{{%yii_cache}}'): void
4551
}
4652

4753
/**
54+
* Ensures that the cache table does not exist in the database.
55+
*
56+
* @param string $table The name of the cache table. Defaults to '{{%yii_cache}}'.
57+
*
4858
* @throws Exception
4959
* @throws InvalidConfigException
5060
* @throws Throwable
@@ -58,6 +68,13 @@ public function ensureNoTable(string $table = '{{%yii_cache}}'): void
5868
}
5969
}
6070

71+
/**
72+
* Checks if the given table exists in the database.
73+
*
74+
* @param string $table The name of the table to check.
75+
*
76+
* @return bool Whether the table exists or not.
77+
*/
6178
private function hasTable(string $table): bool
6279
{
6380
return $this->db->getTableSchema($table, true) !== null;

tests/Common/AbstractDbSchemaManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ protected function tearDown(): void
3636
{
3737
parent::tearDown();
3838

39+
$this->db->close();
40+
3941
unset($this->db, $this->dbSchemaManager);
4042
}
4143

tests/Common/AbstractSQLDumpFileTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ protected function tearDown(): void
3535
{
3636
parent::tearDown();
3737

38+
$this->db->close();
39+
3840
unset($this->db, $this->driverName);
3941
}
4042

tests/Common/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function tearDown(): void
5454
// close db connection
5555
$this->db->close();
5656

57-
unset($this->db, $this->dbCache, $this->logger);
57+
unset($this->db, $this->dbCache, $this->dbSchemaManager, $this->logger);
5858
}
5959

6060
protected function getLogger(): Logger

0 commit comments

Comments
 (0)