Skip to content

Commit e6af179

Browse files
committed
fix codeql
1 parent edc2150 commit e6af179

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ public function logBatch(array $metrics, int $batchSize = self::INSERT_BATCH_SIZ
891891
* Prepare a row for JSONEachRow insert.
892892
*
893893
* @param array<string, mixed> $metricData
894-
* @return array<string, mixed>|null
894+
* @return array<string, mixed>
895895
*/
896-
private function prepareMetricRow(array $metricData): ?array
896+
private function prepareMetricRow(array $metricData): array
897897
{
898898
/** @var string $period */
899899
$period = $metricData['period'] ?? Usage::PERIOD_1H;
@@ -1078,7 +1078,7 @@ public function count(array $queries = []): int
10781078
$result = $this->query($sql, $params);
10791079
$json = json_decode($result, true);
10801080

1081-
if (!isset($json['data'][0]['total'])) {
1081+
if (!is_array($json) || !isset($json['data'][0]['total'])) {
10821082
return 0;
10831083
}
10841084

@@ -1334,14 +1334,18 @@ private function parseResults(string $result): array
13341334
}
13351335

13361336
$json = json_decode($result, true);
1337-
if (!isset($json['data'])) {
1337+
1338+
if (!is_array($json) || !isset($json['data']) || !is_array($json['data'])) {
13381339
return [];
13391340
}
13401341

13411342
$rows = $json['data'];
13421343
$metrics = [];
13431344

13441345
foreach ($rows as $row) {
1346+
if (!is_array($row)) {
1347+
continue;
1348+
}
13451349
$document = [];
13461350

13471351
foreach ($row as $key => $value) {
@@ -1350,7 +1354,7 @@ private function parseResults(string $result): array
13501354
$document[$key] = $value !== null ? (int) $value : null;
13511355
} elseif ($key === 'time') {
13521356
// Time comes as string in JSON format, convert to ISO 8601 if needed
1353-
$parsedTime = $value;
1357+
$parsedTime = (string)$value;
13541358
if (strpos($parsedTime, 'T') === false) {
13551359
$parsedTime = str_replace(' ', 'T', $parsedTime) . '+00:00';
13561360
}
@@ -1557,9 +1561,10 @@ public function sumByPeriod(string $metric, string $period, array $queries = [])
15571561
";
15581562

15591563
$result = $this->query($sql, $parsed['params']);
1564+
15601565
$json = json_decode($result, true);
15611566

1562-
if (!isset($json['data'][0]['grand_total'])) {
1567+
if (!is_array($json) || !isset($json['data'][0]['grand_total'])) {
15631568
return 0;
15641569
}
15651570

0 commit comments

Comments
 (0)