Skip to content

Commit

Permalink
Make it impossible to return null in getOrCreateBucket() (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Oct 15, 2021
1 parent cc9cf67 commit fadba29
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Metrics/DefaultMetricsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function handleMetrics(Feature $feature, bool $successful, Variant $varia
return;
}

$bucket = $this->getOrCreateBucket($feature);
$bucket = $this->getOrCreateBucket();
$bucket->addToggle(new MetricsBucketToggle($feature, $successful, $variant));
if ($this->shouldSend($bucket)) {
$this->send($bucket);
Expand All @@ -31,14 +31,18 @@ public function handleMetrics(Feature $feature, bool $successful, Variant $varia
}
}

private function getOrCreateBucket(Feature $feature): MetricsBucket
private function getOrCreateBucket(): MetricsBucket
{
$cache = $this->configuration->getCache();

$bucket = null;
if ($cache->has(CacheKey::METRICS_BUCKET)) {
return $cache->get(CacheKey::METRICS_BUCKET);
$bucket = $cache->get(CacheKey::METRICS_BUCKET);
}

return new MetricsBucket(new DateTimeImmutable());
$bucket ??= new MetricsBucket(new DateTimeImmutable());

return $bucket;
}

private function shouldSend(MetricsBucket $bucket): bool
Expand Down

0 comments on commit fadba29

Please sign in to comment.