*/ public array $jobs = []; /** @var list job id, user id, change */ public array $changes = []; /** @var array */ private array $lastNumbers = []; private int $nextId = 1; public function findById(int $id): ?CustomerJob { return isset($this->jobs[$id]) ? clone $this->jobs[$id] : null; } public function save(CustomerJob $job): CustomerJob { $id = $job->id() ?? $this->nextId++; $this->jobs[$id] = CustomerJob::reconstitute($id, $job->number(), $job->details(), $job->createdBy(), $job->completedAt()); return clone $this->jobs[$id]; } public function recordChanges(int $jobId, int $userId, array $changes): void { foreach ($changes as $change) { $this->changes[] = [$jobId, $userId, $change]; } } public function next(int $year): JobNumber { $this->lastNumbers[$year] = ($this->lastNumbers[$year] ?? 0) + 1; return new JobNumber($year, $this->lastNumbers[$year]); } /** * @return list */ public function changedFields(int $jobId): array { return array_values(array_map(fn (array $row): string => $row[2]->field, array_filter($this->changes, fn (array $row): bool => $row[0] === $jobId))); } }