readEntireFile($csvReader); $this->reset(); } private function readEntireFile(CsvReader $reader): void { while ($line = $reader->readNextLine()) { $this->lines[] = $line; } } public function getRandomLine(): array | null { if (empty($this->currentLines)) { return null; // No more lines to read } $randomNumber = array_rand($this->currentLines); $randomLine = $this->currentLines[$randomNumber]; // Remove the line from the current lines to avoid repetition unset($this->currentLines[$randomNumber]); $this->lastReadLineIndex = array_search($randomLine, $this->lines, true); return $randomLine; } public function reset(): void { $this->currentLines = $this->lines; } public function getLastReadLineIndex(): int { return $this->lastReadLineIndex; } }