Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemoryStatsRecord Interface #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Adapters/InMemory/InMemoryClientAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cosmastech\StatsDClientAdapter\Adapters\Concerns\TagNormalizerAwareTrait;
use Cosmastech\StatsDClientAdapter\Adapters\Concerns\TimeClosureTrait;
use Cosmastech\StatsDClientAdapter\Adapters\Contracts\TagNormalizerAware;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Contracts\InMemoryStatsRecordInterface;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryCountRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryDistributionRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryGaugeRecord;
Expand All @@ -31,18 +32,18 @@

/**
* @param array<mixed, mixed> $defaultTags
* @param InMemoryStatsRecord $inMemoryStatsRecord
* @param InMemoryStatsRecordInterface $inMemoryStatsRecord
* @param TagNormalizer $tagNormalizer
* @param ClockInterface $clock
*/
public function __construct(
array $defaultTags = [],
InMemoryStatsRecord $inMemoryStatsRecord = new InMemoryStatsRecord(),
InMemoryStatsRecordInterface $inMemoryStatsRecord = new InMemoryStatsRecord(),
TagNormalizer $tagNormalizer = new NoopTagNormalizer(),
ClockInterface $clock = new Clock()
) {
$this->setDefaultTags($defaultTags);
$this->stats = $inMemoryStatsRecord;

Check failure on line 46 in src/Adapters/InMemory/InMemoryClientAdapter.php

View workflow job for this annotation

GitHub Actions / build

Property Cosmastech\StatsDClientAdapter\Adapters\InMemory\InMemoryClientAdapter::$stats (Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryStatsRecord) does not accept Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Contracts\InMemoryStatsRecordInterface.
$this->setTagNormalizer($tagNormalizer);
$this->clock = $clock;
}
Expand Down Expand Up @@ -179,7 +180,7 @@
/**
* Get all recorded stats.
*/
public function getStats(): InMemoryStatsRecord
public function getStats(): InMemoryStatsRecordInterface
{
return $this->stats;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Contracts;

use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryCountRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryDistributionRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryGaugeRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryHistogramRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemorySetRecord;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\InMemoryTimingRecord;

interface InMemoryStatsRecordInterface
{
public function recordTiming(InMemoryTimingRecord $inMemoryTimingRecord): void;

/**
* @return array<int, InMemoryTimingRecord>|iterable<InMemoryTimingRecord>
*/
public function getTimings();

public function recordCount(InMemoryCountRecord $inMemoryCountRecord): void;

/**
* @return array<int, InMemoryCountRecord>|iterable<InMemoryCountRecord>
*/
public function getCounts();

public function recordGauge(InMemoryGaugeRecord $inMemoryGaugeRecord): void;

/**
* @return array<int, InMemoryGaugeRecord>|iterable<InMemoryGaugeRecord>
*/
public function getGauges();


public function recordSet(InMemorySetRecord $inMemorySetRecord): void;

/**
* @return array<int, InMemorySetRecord>|iterable<InMemorySetRecord>
*/
public function getSets();

public function recordHistogram(InMemoryHistogramRecord $inMemoryHistogramRecord): void;

/**
* @return array<int, InMemoryHistogramRecord>|iterable<InMemoryHistogramRecord>
*/
public function getHistograms();

public function recordDistribution(InMemoryDistributionRecord $inMemoryDistributionRecord): void;

/**
* @return array<int, InMemoryDistributionRecord>|iterable<InMemoryDistributionRecord>
*/
public function getDistributions();

public function flush(): void;
}
3 changes: 2 additions & 1 deletion src/Adapters/InMemory/Models/InMemoryStatsRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models;

use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Concerns\GetAndSetRecordsTrait;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Contracts\InMemoryStatsRecordInterface;
use Cosmastech\StatsDClientAdapter\Adapters\InMemory\Models\Contracts\RecordInterface;

/**
* Container class for storing all stats.
*/
class InMemoryStatsRecord implements RecordInterface
class InMemoryStatsRecord implements RecordInterface, InMemoryStatsRecordInterface
{
use GetAndSetRecordsTrait;

Expand Down
1 change: 1 addition & 0 deletions tests/Adapters/InMemory/InMemoryTimingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function storesTimingRecord(): void
$inMemoryClient->timing("timing-stat", 199, 0.2, ["timing" => "some-value"]);

// Then
/** @var InMemoryStatsRecord $statsRecord */
$statsRecord = $inMemoryClient->getStats();
self::assertCount(1, $statsRecord->getTimings());

Expand Down
Loading