nextId(); $text = new Text( id: $id, name: $dto->name, ); $this->existingTexts[$id] = $text; return $text; } public function find(int $id): ?Text { $text = array_find( $this->existingTexts, function (Text $text) use ($id){ return $text->getId() === $id; } ); if ($text === null) { return null; } return new Text( id: $id, name: $text->getName(), ); } private function nextId(): int { return count($this->existingTexts); } }