Skip to content

Commit eb5a835

Browse files
Merge pull request #42 from keboola/webrouse-COM-350-fix-readline-speed
Validate line breaks only once - in constructor
2 parents a439656 + fcce3bf commit eb5a835

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/CsvReader.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public function __construct(
5353
$this->options = new CsvOptions($delimiter, $enclosure, $escapedBy);
5454
$this->setSkipLines($skipLines);
5555
$this->setFile($file);
56+
5657
$this->lineBreak = $this->detectLineBreak();
58+
$this->validateLineBreak();
59+
5760
rewind($this->filePointer);
5861
$this->header = $this->readLine();
5962
$this->rewind();
@@ -124,8 +127,6 @@ protected function detectLineBreak()
124127
*/
125128
protected function readLine()
126129
{
127-
$this->validateLineBreak();
128-
129130
// allow empty enclosure hack
130131
$enclosure = !$this->getEnclosure() ? chr(0) : $this->getEnclosure();
131132
$escapedBy = !$this->getEscapedBy() ? chr(0) : $this->getEscapedBy();
@@ -138,15 +139,7 @@ protected function readLine()
138139
*/
139140
protected function validateLineBreak()
140141
{
141-
try {
142-
$lineBreak = $this->getLineBreak();
143-
} catch (Exception $e) {
144-
throw new InvalidArgumentException(
145-
"Failed to detect line break: " . $e->getMessage(),
146-
Exception::INVALID_PARAM,
147-
$e
148-
);
149-
}
142+
$lineBreak = $this->getLineBreak();
150143
if (in_array($lineBreak, ["\r\n", "\n"])) {
151144
return $lineBreak;
152145
}

0 commit comments

Comments
 (0)