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); } /** * @return Text[] */ public function getAll(): array { return array_map( function (Text $text) { return new Text( id: $text->getId(), name: $text->getName(), ); }, $this->existingTexts ); } }