nextId(); $user = new User( id: $id, email: $dto->email, passwordHash: $dto->passwordHash, ); $this->users[$id] = $user; return $user; } public function findByEmail(EmailAddress $email): ?User { foreach ($this->users as $user) { if ($user->getEmail()->value() === $email->value()) { return new User( id: $user->getId(), email: $user->getEmail(), passwordHash: $user->getPasswordHash(), ); } } return null; } public function find(int $id): ?User { $user = $this->users[$id] ?? null; if ($user === null) { return null; } return new User( id: $user->getId(), email: $user->getEmail(), passwordHash: $user->getPasswordHash(), ); } private function nextId(): int { return count($this->users); } }