feat(store): finish ContributionStore and add typed entities
- Fix add()'s upsert SQL (was invalid SQL from typos) and use it for the new merge() as well. - Fix remove()'s missing FROM keyword and drop the unindexed LIKE scan in favor of an exact match. - Add latestDate(), all() with optional sinceDays filtering, and prune() with a retention-day cutoff. - Add Contribution (immutable value object) and ContributionCollection (IteratorAggregate + Countable) so all() returns something typed instead of a raw date => count array. - Cover all of the above with unit tests against an in-memory SQLite database.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
/**
|
||||
* @implements \IteratorAggregate<int, Contribution>
|
||||
*/
|
||||
final class ContributionCollection implements \IteratorAggregate, \Countable
|
||||
{
|
||||
/** @var array<int, Contribution> */
|
||||
private readonly array $contributions;
|
||||
|
||||
public function __construct(Contribution ...$contributions)
|
||||
{
|
||||
$this->contributions = $contributions;
|
||||
}
|
||||
|
||||
public function getIterator(): \ArrayIterator
|
||||
{
|
||||
return new \ArrayIterator($this->contributions);
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->contributions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user