Skip to content

Commit 7af92f0

Browse files
committed
Fix return null statement in fetchDbHost()
1 parent 633a56e commit 7af92f0

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/Instrumentation/Laravel/src/Watchers/RedisCommand/RedisCommandWatcher.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,19 @@ private function fetchDbIndex(Connection $connection): ?int
8989
}
9090
}
9191

92-
private function fetchDbHost(Connection $connection): string
92+
private function fetchDbHost(Connection $connection): ?string
9393
{
94-
if ($connection instanceof PhpRedisConnection) {
95-
$host = $connection->client()->getHost();
96-
97-
if ($host === false) {
98-
throw new RuntimeException('Cannot fetch database host.');
99-
}
100-
101-
return $host;
102-
} elseif ($connection instanceof PredisConnection) {
103-
/** @psalm-suppress PossiblyUndefinedMethod */
104-
$host = $connection->client()->getConnection()->getParameters()->host;
105-
106-
if (is_int($host)) {
107-
throw new RuntimeException('Cannot fetch database index.');
94+
try {
95+
if ($connection instanceof PhpRedisConnection) {
96+
return $connection->client()->getHost();
97+
} elseif ($connection instanceof PredisConnection) {
98+
/** @psalm-suppress PossiblyUndefinedMethod */
99+
return $connection->client()->getConnection()->getParameters()->host;
108100
}
109101

110-
return $host;
102+
return null;
103+
} catch (Throwable $e) {
104+
return null;
111105
}
112-
113-
throw new RangeException('Unknown Redis connection instance: ' . get_class($connection));
114-
115106
}
116107
}

0 commit comments

Comments
 (0)