Lines
100.00%
6 / 6
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| parse | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| reveal | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| __toString | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 12 | final readonly class StoreDsn implements Stringable | |
| 13 | { | |
| 14 | private const string SCHEME_PATTERN = '~^([a-z][a-z0-9+.-]*)://~i'; | |
| 15 | ||
| 16 | private function __construct( | |
| 17 | #[SensitiveParameter] | |
| 18 | private string $dsn, | |
| 19 | public string $scheme, | |
| 20 | private string $redacted, | |
| 21 | ) {} | |
| 22 | ||
| 23 | /** @throws StoreSetupException */ | |
| 24 | public static function parse(#[SensitiveParameter] string $dsn): self | |
| 25 | { | |
| 26 | if (preg_match(self::SCHEME_PATTERN, $dsn, $matches) !== 1) { | |
| 27 | throw StoreSetupException::dsnInvalid($dsn); | |
| 28 | } | |
| 29 | ||
| 30 | return new self($dsn, strtolower($matches[1]), UrlRedactor::redactCredentials($dsn)); | |
| 31 | } | |
| 32 | ||
| 33 | public function reveal(): string | |
| 34 | { | |
| 35 | return $this->dsn; | |
| 36 | } | |
| 37 | ||
| 38 | public function __toString(): string | |
| 39 | { | |
| 40 | return $this->redacted; | |
| 41 | } | |
| 42 | } |