protected function writeLine($line, $number = null)
    {
        $this->ensureFileIsWritable();

        // Append
        if (is_null($number)) {
            return file_put_contents($this->filePath, $line . PHP_EOL, FILE_APPEND);
        }

        // Replace
        $lines = $this->readLinesFromFile($this->filePath);
        $lines[$number] = $line;
        return file_put_contents($this->filePath, implode(PHP_EOL, $lines));
    }