Skip to content
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

Override the createFromPath static method for a simple open mode on Reader #266

Merged
merged 2 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Reader extends AbstractCsv implements Countable, IteratorAggregate, JsonSe
*/
protected $stream_filter_mode = STREAM_FILTER_READ;

/**
* @inheritdoc
*/
public static function createFromPath(string $path, string $open_mode = 'r', $context = null): AbstractCsv
Copy link
Member

@nyamsprod nyamsprod Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a tiny BC break you can't just correct it like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you'd mentioned this would potentially go in a 10.0 release (which is likely to be atleast a year away), I approached it with that in mind. Is there another way I should approach this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type-hint here is wrong. You're returning new static so the return type should be Reader. While upgrading from 9.0.1 to 9.1.2 I started getting errors like these from Phan:

app/Legacy/Console/Commands/AbstractCsvImportCommand.php:77 PhanUndeclaredMethod Call to undeclared method \League\Csv\AbstractCsv::setHeaderOffset

{
return new static(Stream::createFromPath($path, $open_mode, $context));
}

/**
* Returns the header offset
*
Expand Down
9 changes: 9 additions & 0 deletions tests/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,13 @@ public function testJsonSerialize()
json_encode($reader)
);
}

/**
* @covers ::createFromPath
*/
public function testCreateFromPath()
{
$csv = Reader::createFromPath(__DIR__.'/data/foo_readonly.csv');
$this->assertCount(1, $csv);
}
}
1 change: 1 addition & 0 deletions tests/data/foo_readonly.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
john,doe,[email protected]