38 lines
946 B
PHP
38 lines
946 B
PHP
<?php
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
use App\Modules\TimeTracking\Domain\Contracts\PinnedTaskRepository;
|
|
use DateTimeImmutable;
|
|
|
|
class InMemoryPinnedTaskRepository implements PinnedTaskRepository
|
|
{
|
|
/** @var array<int, list<int>> task ids by user id */
|
|
public array $pins = [];
|
|
|
|
public function pin(int $userId, int $taskId, DateTimeImmutable $at): void
|
|
{
|
|
if (! in_array($taskId, $this->pins[$userId] ?? [], true)) {
|
|
$this->pins[$userId][] = $taskId;
|
|
}
|
|
}
|
|
|
|
public function unpin(int $userId, int $taskId): void
|
|
{
|
|
$this->pins[$userId] = array_values(array_diff($this->pins[$userId] ?? [], [$taskId]));
|
|
}
|
|
|
|
public function unpinAll(int $userId): int
|
|
{
|
|
$count = count($this->pins[$userId] ?? []);
|
|
$this->pins[$userId] = [];
|
|
|
|
return $count;
|
|
}
|
|
|
|
public function pinnedTaskIds(int $userId): array
|
|
{
|
|
return $this->pins[$userId] ?? [];
|
|
}
|
|
}
|