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