Skip to content

Commit

Permalink
fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Mar 22, 2024
1 parent 5af4962 commit 2f65f78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Config/TemporalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* }
*
* @property array{
* address?: non-empty-string|null,
* connection: non-empty-string,
* connections: array<non-empty-string, Connection>,
* temporalNamespace: non-empty-string,
Expand Down Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions src/Connection/DsnConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2f65f78

Please sign in to comment.