From d8bdd0b9a36cf31d939f377561b71c4193db4d1d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 May 2024 17:08:19 +1200 Subject: [PATCH 1/4] Allow constructing with null scheme --- src/DSN/DSN.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DSN/DSN.php b/src/DSN/DSN.php index 0eb0ef2..3e6f3e8 100644 --- a/src/DSN/DSN.php +++ b/src/DSN/DSN.php @@ -5,9 +5,9 @@ class DSN { /** - * @var string + * @var ?string */ - protected string $scheme; + protected ?string $scheme; /** * @var ?string From 09521c1fb6dc5488df5e89eeb6b3ca5e736fd97c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 May 2024 17:15:19 +1200 Subject: [PATCH 2/4] Add nullable to getScheme return type --- src/DSN/DSN.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DSN/DSN.php b/src/DSN/DSN.php index 3e6f3e8..c6d5746 100644 --- a/src/DSN/DSN.php +++ b/src/DSN/DSN.php @@ -71,9 +71,9 @@ public function __construct(string $dsn) /** * Return the scheme. * - * @return string + * @return ?string */ - public function getScheme(): string + public function getScheme(): ?string { return $this->scheme; } From 14701f62c5a2eeb91967badcda880b57834ec037 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 May 2024 18:06:37 +1200 Subject: [PATCH 3/4] Throw if no host or scheme --- src/DSN/DSN.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/DSN/DSN.php b/src/DSN/DSN.php index c6d5746..fd1111b 100644 --- a/src/DSN/DSN.php +++ b/src/DSN/DSN.php @@ -5,9 +5,9 @@ class DSN { /** - * @var ?string + * @var string */ - protected ?string $scheme; + protected string $scheme; /** * @var ?string @@ -53,16 +53,24 @@ class DSN */ public function __construct(string $dsn) { - $parts = parse_url($dsn); + $parts = \parse_url($dsn); - if (! $parts) { + if (!$parts) { throw new \InvalidArgumentException("Unable to parse DSN: $dsn"); } - $this->scheme = $parts['scheme'] ?? null; + if (empty($parts['scheme'])) { + throw new \InvalidArgumentException('Unable to parse DSN: scheme is required'); + } + + if (empty($parts['host'])) { + throw new \InvalidArgumentException('Unable to parse DSN: host is required'); + } + + $this->scheme = $parts['scheme']; $this->user = isset($parts['user']) ? \urldecode($parts['user']) : null; $this->password = isset($parts['pass']) ? \urldecode($parts['pass']) : null; - $this->host = $parts['host'] ?? ''; + $this->host = $parts['host']; $this->port = $parts['port'] ?? null; $this->path = isset($parts['path']) ? ltrim((string) $parts['path'], '/') : ''; $this->query = $parts['query'] ?? null; @@ -71,9 +79,9 @@ public function __construct(string $dsn) /** * Return the scheme. * - * @return ?string + * @return string */ - public function getScheme(): ?string + public function getScheme(): string { return $this->scheme; } From 8dea50e69b4d8da4820fcf8bf3dc63d3c0d4118c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 6 May 2024 21:21:28 +1200 Subject: [PATCH 4/4] Fix pint --- composer.json | 4 ++-- psalm.xml | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 psalm.xml diff --git a/composer.json b/composer.json index 8db0b4d..ae388fa 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ "psr-4": {"Utopia\\DSN\\": "src/DSN"} }, "scripts": { - "lint": "./vendor/bin/pint --test", - "format": "./vendor/bin/pint", + "lint": "./vendor/bin/pint --test --preset psr12", + "format": "./vendor/bin/pint --preset psr12", "test": "./vendor/bin/phpunit --configuration phpunit.xml tests" }, "require": { diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index b5d5891..0000000 --- a/psalm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - \ No newline at end of file