-
-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal error with ltrim() when using the EmptyEscapeParser #358
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,35 @@ public function testPreserveEmptyLines() | |
} | ||
} | ||
|
||
/** | ||
* @covers ::parse | ||
* @covers ::extractRecord | ||
* @covers ::extractFieldContent | ||
* @covers ::extractEnclosedFieldContent | ||
*/ | ||
public function testReadingOnlyStream() | ||
{ | ||
$source = <<<EOF | ||
"1","2" | ||
|
||
EOF; | ||
|
||
$expected = [ | ||
['1', '2'], | ||
[null], | ||
]; | ||
|
||
$path = sys_get_temp_dir().'/test.csv'; | ||
file_put_contents($path, $source); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely overlooked the |
||
|
||
$stream = Stream::createFromPath($path); | ||
foreach (EmptyEscapeParser::parse($stream) as $offset => $record) { | ||
self::assertSame($expected[$offset], $record); | ||
} | ||
|
||
unlink($path); | ||
} | ||
|
||
/** | ||
* @covers ::parse | ||
* @covers ::extractRecord | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make the conditions more explicit ...
and that should be enough no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree but that seems to confuse PHPStan:
See also: https://travis-ci.org/thephpleague/csv/jobs/594868542
It seems a bad idea to ignore the error completely but to ignore the error in just that file would require updating PHPStan which seems to open a can of worms (at least in my development environment).
This won't work with the current version of PHPStan. We need v0.11+:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can not update because of the PHP7.0+ requirement but I have no issue ignoring this PHPstan notice, this is kind of a trade off. The day we drop PHP7.2- we will be able to upgrade/improve the ignore message IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your patch is applied at the wrong lines 🤔 if you put the patch inside the while loop then PHPStan will not complained 👍 . You just need to patch the
$buffer
not so much the rawself::$line
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great - trade-off avoided!