chore(doc): documentet all public methods
This commit is contained in:
@@ -13,6 +13,9 @@ class ContributionStore
|
|||||||
private PDO $pdo;
|
private PDO $pdo;
|
||||||
private const int DAY_IN_SECONDS = 86400;
|
private const int DAY_IN_SECONDS = 86400;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens (creating if needed) the SQLite store at $dbPath and ensures the schema exists.
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly string $dbPath = "%kernel.project_dir%/var/data/contributions.db",
|
private readonly string $dbPath = "%kernel.project_dir%/var/data/contributions.db",
|
||||||
private readonly ?int $retentionDays = null,
|
private readonly ?int $retentionDays = null,
|
||||||
@@ -38,6 +41,9 @@ class ContributionStore
|
|||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a contribution count, overwriting any existing count for the same provider/date.
|
||||||
|
*/
|
||||||
public function add(string $provider, int $unixtime, int $count): void
|
public function add(string $provider, int $unixtime, int $count): void
|
||||||
{
|
{
|
||||||
$stmt = $this->pdo->prepare('
|
$stmt = $this->pdo->prepare('
|
||||||
@@ -48,6 +54,9 @@ class ContributionStore
|
|||||||
$stmt->execute([$provider, $unixtime, $count]);
|
$stmt->execute([$provider, $unixtime, $count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the contribution row for the given provider/date, if any.
|
||||||
|
*/
|
||||||
public function remove(string $provider, int $unixtime): void
|
public function remove(string $provider, int $unixtime): void
|
||||||
{
|
{
|
||||||
$stmt = $this->pdo->prepare('
|
$stmt = $this->pdo->prepare('
|
||||||
@@ -58,6 +67,8 @@ class ContributionStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Upserts a batch of date => count pairs for a provider via repeated add() calls.
|
||||||
|
*
|
||||||
* @param array<int, int> $dateCounts unix timestamp => count
|
* @param array<int, int> $dateCounts unix timestamp => count
|
||||||
*/
|
*/
|
||||||
public function merge(string $provider, array $dateCounts): void
|
public function merge(string $provider, array $dateCounts): void
|
||||||
@@ -67,6 +78,9 @@ class ContributionStore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the most recent stored unix timestamp for a provider, or null if it has no rows.
|
||||||
|
*/
|
||||||
public function latestDate(string $provider): ?int
|
public function latestDate(string $provider): ?int
|
||||||
{
|
{
|
||||||
$stmt = $this->pdo->prepare('SELECT MAX(date) FROM contributions WHERE provider = ?');
|
$stmt = $this->pdo->prepare('SELECT MAX(date) FROM contributions WHERE provider = ?');
|
||||||
@@ -76,6 +90,9 @@ class ContributionStore
|
|||||||
return $result !== null ? (int) $result : null;
|
return $result !== null ? (int) $result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all stored contributions for a provider, optionally limited to the last $sinceDays days.
|
||||||
|
*/
|
||||||
public function all(string $provider, ?int $sinceDays = null): ContributionCollection
|
public function all(string $provider, ?int $sinceDays = null): ContributionCollection
|
||||||
{
|
{
|
||||||
$sql = 'SELECT provider, date, count FROM contributions WHERE provider = ?';
|
$sql = 'SELECT provider, date, count FROM contributions WHERE provider = ?';
|
||||||
@@ -97,6 +114,9 @@ class ContributionStore
|
|||||||
return new ContributionCollection(...$contributions);
|
return new ContributionCollection(...$contributions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes rows older than the configured retention window; a no-op if retention is unset or 0.
|
||||||
|
*/
|
||||||
public function prune(): void
|
public function prune(): void
|
||||||
{
|
{
|
||||||
if ($this->retentionDays === null || $this->retentionDays === 0) {
|
if ($this->retentionDays === null || $this->retentionDays === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user