diff --git a/src/ConnectionConfig.php b/src/ConnectionConfig.php index a4bcde4..cba4361 100644 --- a/src/ConnectionConfig.php +++ b/src/ConnectionConfig.php @@ -21,7 +21,7 @@ final class ConnectionConfig extends SqlConnectionConfig return new self( $parts["host"], - $parts["port"] ?? self::DEFAULT_PORT, + (int) ($parts["port"] ?? self::DEFAULT_PORT), $parts["user"] ?? null, $parts["password"] ?? null, $parts["db"] ?? null diff --git a/src/TimeoutConnector.php b/src/TimeoutConnector.php index 8aa98e1..d0adfe6 100644 --- a/src/TimeoutConnector.php +++ b/src/TimeoutConnector.php @@ -3,7 +3,7 @@ namespace Amp\Postgres; use Amp\Promise; -use Amp\Sql\ConnectionConfig; +use Amp\Sql\ConnectionConfig as SqlConnectionConfig; use Amp\Sql\Connector; use Amp\Sql\FailureException; use Amp\TimeoutCancellationToken; @@ -30,8 +30,12 @@ final class TimeoutConnector implements Connector * * @throws \Error If neither ext-pgsql or pecl-pq is loaded. */ - public function connect(ConnectionConfig $connectionConfig): Promise + public function connect(SqlConnectionConfig $connectionConfig): Promise { + if (!$connectionConfig instanceof ConnectionConfig) { + throw new \TypeError(\sprintf("Must provide an instance of %s to Postgres connectors", ConnectionConfig::class)); + } + $token = new TimeoutCancellationToken($this->timeout); if (\extension_loaded("pq")) {