From 2f65f78fc3c175d4b634015589d47d3aa12aaccd Mon Sep 17 00:00:00 2001 From: butschster Date: Fri, 22 Mar 2024 10:43:17 +0400 Subject: [PATCH] fix psalm issues --- src/Config/TemporalConfig.php | 12 ++++-------- src/Connection/DsnConnection.php | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Config/TemporalConfig.php b/src/Config/TemporalConfig.php index 04b7d63..f6f40e9 100644 --- a/src/Config/TemporalConfig.php +++ b/src/Config/TemporalConfig.php @@ -24,6 +24,7 @@ * } * * @property array{ + * address?: non-empty-string|null, * connection: non-empty-string, * connections: array, * temporalNamespace: non-empty-string, @@ -63,17 +64,12 @@ public function getDefaultConnection(): string public function getConnection(string $name): Connection { if (isset($this->config['connections'][$name])) { - \assert( - $this->config['connections'][$name] instanceof Connection, - 'Connection must be an instance of Connection.', - ); - return $this->config['connections'][$name]; } - - if ($this->config['connections'] === [] && $this->config['address'] !== null) { - return new DsnConnection($this->config['address']); + $address = $this->config['address'] ?? null; + if ($this->config['connections'] === [] && $address !== null) { + return new DsnConnection(address: $address); } throw new \InvalidArgumentException(\sprintf('Connection `%s` is not defined.', $name)); diff --git a/src/Connection/DsnConnection.php b/src/Connection/DsnConnection.php index 78a428a..92efc17 100644 --- a/src/Connection/DsnConnection.php +++ b/src/Connection/DsnConnection.php @@ -6,10 +6,15 @@ class DsnConnection extends Connection { + /** + * @param non-empty-string $address Address in format host:port + */ public function __construct( public readonly string $address, ) { [$host, $port] = \explode(':', $address); + \assert($host !== '', 'Host must be a non-empty string'); + parent::__construct($host, (int)$port); } }