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

Conversation

btmash
Copy link
Contributor

@btmash btmash commented Oct 12, 2017

Introduction

I actually got bit by the readonly issue that is described in #258 And figured I'd give a shot at how to fix the issue.

Proposal

I introduce a new static method in reader where the default open mode is 'r'. I also added a test to ensure this works by adding a readonly csv file.

Describe the new/upated/fixed feature

I override the static function createFromPath provided by AbstractCsv to set the default open mode.

Backward Incompatible Changes

There shouldn't be a BC issue.

Targeted release version

Could be 9.0, 10.0, up to you. This is my first time writing a PR for a PHP library like this so its very much a learning experience for me 😄

PR Impact

I don't think there should be a PR impact.

Open issues

#258

@@ -62,6 +62,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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants