setsById) + 1; $set = new DomainSet( id: $id, name: $dto->name, description: $dto->description, iconImageUrl: $dto->iconImageUrl, ); $this->setsById[$id] = $set; return $set; } public function find(int $id): ?DomainSet { if (! isset($this->setsById[$id])) { return null; } return $this->cloneSet($this->setsById[$id]); } /** * @return DomainSet[] */ public function getAll(): array { $sets = []; foreach ($this->setsById as $set) { $sets[] = $this->cloneSet($set); } return $sets; } private function cloneSet(DomainSet $set): DomainSet { return new DomainSet( id: $set->getId(), name: $set->getName(), description: $set->getDescription(), iconImageUrl: $set->getIconImageUrl(), ); } }