Skip to content

Commit

Permalink
Merge pull request #6 from utopia-php/feat-throw-on-no-scheme
Browse files Browse the repository at this point in the history
Feat throw on no scheme or host
  • Loading branch information
abnegate authored May 7, 2024
2 parents c11f37a + 8dea50e commit 42ee37a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 0 additions & 15 deletions psalm.xml

This file was deleted.

16 changes: 12 additions & 4 deletions src/DSN/DSN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 42ee37a

Please sign in to comment.