From 877127f07b36aface557b7def4e66a3cacaec73c Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 18 Oct 2024 14:50:06 +0700 Subject: [PATCH] Refactor `Dsn` class (#323) --- CHANGELOG.md | 1 + src/Dsn.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8380729..95627281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - New #318: Realize `ColumnBuilder` class (@Tigrov) - Enh #320: Update according changes in `ColumnSchemaInterface` (@Tigrov) - New #322: Add `ColumnDefinitionBuilder` class (@Tigrov) +- Enh #323: Refactor `Dsn` class (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Dsn.php b/src/Dsn.php index 8806397a..8f8c356e 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -13,10 +13,7 @@ */ final class Dsn extends AbstractDsn { - /** - * @psalm-param string[] $options - */ - public function __construct(private string $driver, private string|null $databaseName = null) + public function __construct(string $driver = 'sqlite', string|null $databaseName = null) { parent::__construct($driver, '', $databaseName); } @@ -39,11 +36,14 @@ public function __construct(private string $driver, private string|null $databas */ public function asString(): string { - return match ($this->databaseName) { - '' => $this->driver . ':', - 'memory' => $this->driver . '::memory:', - null => $this->driver . ':', - default => $this->driver . ':' . $this->databaseName, + $driver = $this->getDriver(); + $databaseName = $this->getDatabaseName(); + + return match ($databaseName) { + '' => "$driver:", + null => "$driver:", + 'memory' => "$driver::memory:", + default => "$driver:$databaseName", }; } }