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 diff --git a/src/DSN/DSN.php b/src/DSN/DSN.php index 0eb0ef2..fd1111b 100644 --- a/src/DSN/DSN.php +++ b/src/DSN/DSN.php @@ -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;