Skip to content

Commit 5025a91

Browse files
lohanidamodarclaude
andcommitted
Fix PHPStan and PSR-12 linter errors
- Add array shape type to findAggregatedFromTable $parsed parameter so PHPStan recognizes typed keys (filters, params, orderBy) - Provide default for optional groupByInterval key access - Split compound type check for $interval to satisfy PHPStan string narrowing in exception message interpolation - Remove extra trailing blank line in UsageBase.php (PSR-12) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 143e2bb commit 5025a91

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/Usage/Adapter/ClickHouse.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ private function findFromTable(array $queries, string $type): array
14901490
* toStartOfInterval(time, INTERVAL 1 HOUR) as time
14911491
* FROM table WHERE ... GROUP BY metric, time ORDER BY time ASC
14921492
*
1493-
* @param array<string, mixed> $parsed Parsed query data from parseQueries()
1493+
* @param array{filters: array<string>, params: array<string, mixed>, orderBy?: array<string>, limit?: int, offset?: int, groupByInterval?: string} $parsed Parsed query data from parseQueries()
14941494
* @param string $fromTable Fully qualified table reference
14951495
* @param string $type 'event' or 'gauge'
14961496
* @return array<Metric>
@@ -1499,7 +1499,7 @@ private function findFromTable(array $queries, string $type): array
14991499
private function findAggregatedFromTable(array $parsed, string $fromTable, string $type): array
15001500
{
15011501
/** @var string $interval */
1502-
$interval = $parsed['groupByInterval'];
1502+
$interval = $parsed['groupByInterval'] ?? '1h';
15031503
$intervalSql = UsageQuery::VALID_INTERVALS[$interval];
15041504

15051505
// Choose aggregation function based on metric type
@@ -2542,7 +2542,13 @@ private function parseQueries(array $queries, string $type = 'event'): array
25422542
case UsageQuery::TYPE_GROUP_BY_INTERVAL:
25432543
$this->validateAttributeName($attribute, $type);
25442544
$interval = $values[0] ?? '1h';
2545-
if (!is_string($interval) || !isset(UsageQuery::VALID_INTERVALS[$interval])) {
2545+
if (!is_string($interval)) {
2546+
throw new \Exception(
2547+
'Invalid groupByInterval interval: expected string, got ' . get_debug_type($interval) . '. Allowed: '
2548+
. implode(', ', array_keys(UsageQuery::VALID_INTERVALS))
2549+
);
2550+
}
2551+
if (!isset(UsageQuery::VALID_INTERVALS[$interval])) {
25462552
throw new \Exception(
25472553
"Invalid groupByInterval interval '{$interval}'. Allowed: "
25482554
. implode(', ', array_keys(UsageQuery::VALID_INTERVALS))

tests/Usage/UsageBase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,3 @@ public function testGroupByIntervalWithLimitOffset(): void
640640
$this->assertGreaterThanOrEqual(1, count($results));
641641
}
642642
}
643-

0 commit comments

Comments
 (0)