Skip to content

Commit b5bf5f2

Browse files
committed
fix: improve type hinting and documentation for ClickHouse metrics handling
1 parent b14345a commit b5bf5f2

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,7 @@ private function formatDateTime($dateTime): string
559559
throw new Exception("Invalid datetime string: {$dateTime}");
560560
}
561561
}
562-
563-
// For any other type, try to convert to DateTime
564-
throw new Exception("Invalid datetime value type: " . gettype($dateTime));
565562
}
566-
567563
/**
568564
* Get ClickHouse-specific SQL column definition for a given attribute ID.
569565
*
@@ -706,6 +702,7 @@ private function buildInsertValuesForMetric(
706702

707703
// Add attributes dynamically - must include ALL attributes in schema order
708704
foreach ($this->getAttributes() as $attribute) {
705+
/** @var string $attrId */
709706
$attrId = $attribute['$id'];
710707

711708
$attrKey = $attrId . ($paramCounter > 0 ? '_' . $paramCounter : '');
@@ -746,6 +743,7 @@ private function buildInsertColumns(): array
746743
$insertColumns[] = 'tenant';
747744
}
748745

746+
/** @var array<string> */
749747
return $insertColumns;
750748
}
751749

@@ -848,10 +846,14 @@ public function logBatchCounter(array $metrics, int $batchSize = self::INSERT_BA
848846
$valueClauses = [];
849847

850848
foreach ($metricsBatch as $metricData) {
849+
/** @var string $period */
851850
$period = $metricData['period'] ?? Usage::PERIOD_1H;
851+
/** @var string $metric */
852852
$metric = $metricData['metric'];
853+
/** @var int $value */
853854
$value = $metricData['value'];
854-
$tags = (array) ($metricData['tags'] ?? []);
855+
/** @var array<string, mixed> $tags */
856+
$tags = $metricData['tags'] ?? [];
855857

856858
// Build values for this metric
857859
$tenant = $this->sharedTables ? $this->resolveTenantFromMetric($metricData) : null;
@@ -906,6 +908,7 @@ private function validateMetricsBatch(array $metrics): void
906908
throw new Exception("Metric #{$index}: 'period' must be a string, got " . gettype($period));
907909
}
908910

911+
/** @var array<string, mixed> */
909912
$tags = $metricData['tags'] ?? [];
910913
$this->validateMetricData($metric, $value, $period, $tags, $index);
911914

@@ -964,10 +967,14 @@ public function logBatch(array $metrics, int $batchSize = self::INSERT_BATCH_SIZ
964967
$valueClauses = [];
965968

966969
foreach ($metricsBatch as $metricData) {
970+
/** @var string $period */
967971
$period = $metricData['period'] ?? Usage::PERIOD_1H;
972+
/** @var string $metric */
968973
$metric = $metricData['metric'];
974+
/** @var int $value */
969975
$value = $metricData['value'];
970-
$tags = (array) ($metricData['tags'] ?? []);
976+
/** @var array<string, mixed> $tags */
977+
$tags = $metricData['tags'] ?? [];
971978

972979
// Build values for this metric
973980
$tenant = $this->sharedTables ? $this->resolveTenantFromMetric($metricData) : null;

0 commit comments

Comments
 (0)