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

Remove encoding writing stuff #59

Merged
merged 1 commit into from
Oct 24, 2016

Conversation

ajgarlag
Copy link
Contributor

@ajgarlag ajgarlag commented Oct 19, 2016

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
License MIT

What's in this PR?

This PR removes all stuff related with write filters in the Http\Message\Encoding namespace.

Why?

The abstract class Http\Message\Encoding\FilteredStream defines an abstract method named getWriteFilter that is not called anywhere and produces dead code not being tested. IMO this code must be removed or at least deprecated.

Example Usage

You can run the tests to see that this code is not being used nor tested.

$composer test

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix

To Do

  • Squash the commits before merge

@sagikazarmark
Copy link
Member

As far as I can see it's being called here: https://github.com/php-http/message/blob/master/src/Encoding/FilteredStream.php#L55

@ajgarlag
Copy link
Contributor Author

Yes, but the writeFilterCallback is not being called anywhere

@sagikazarmark
Copy link
Member

That's true, but technically the methods you removed are still called.

@sagikazarmark
Copy link
Member

Ping @joelwurtz

@joelwurtz
Copy link
Member

joelwurtz commented Oct 19, 2016

My intent was to propose a method to write into a filtered stream which is the reverse filter of the reading action.

This can be useful on server side or library manipulating stream (like transfering data from a FilteredStream to another FilteredStream should result in the same data, which is not the case actually as it would only decode multiple times but never reencode)

However i nerver implemented the method as ATM there was no need for that, removing this is not a problem as like you said it's never used (and it's not a BC break).

But there should be more to that, the filtered stream should only be readable and not writable (so isWritable should return false, and write method should throw an exception) and also it should not be seekable (but not the purpose of this PR, can be reported as a separate Issue or write as a separate PR)

@sagikazarmark
Copy link
Member

Well, the fact that we don't use it is enough for removal?

Also, IMO it's a BC break, no matter if it's used by US or not, it's a public API change.

@dbu
Copy link
Contributor

dbu commented Oct 19, 2016

this is a massive BC break in our public API. if we decide we don't need this we should deprecate the methods and remove them in version 2 only. if they are useful as is, we should instead write some tests that make sure they work as intended.

@joelwurtz
Copy link
Member

joelwurtz commented Oct 19, 2016

Ah yes didn't see the public visibility, i think it's a mistake in the original code as a user never need to get the encoding or decoding filter it's only an implementation detail, they should be deprecated then and removed in 2.0.

@ajgarlag ajgarlag force-pushed the remove-encoding-writing-stuff branch 2 times, most recently from 9d72e58 to ee44e05 Compare October 19, 2016 15:55
@dbu
Copy link
Contributor

dbu commented Oct 19, 2016 via email

@ajgarlag
Copy link
Contributor Author

@dbu I've already modified the PR to deprecate the methods.

### Deprecated

- FilteredStream::getReadFilter will be removed in 2.0
- FilteredStream::getWriteFilter will be removed in 2.0
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd like to add an explanation to the changelog why we deprecate them. "The read filter is internal and should never be used by consuming code.", "We did not implement writing to the streams at all. And if we do, the filter is an internal information and should not be used by consuming code."

@ajgarlag ajgarlag force-pushed the remove-encoding-writing-stuff branch 2 times, most recently from 738954a to b4b29e7 Compare October 20, 2016 07:03
$this->readFilterCallback = Filter\fun($this->getReadFilter(), $readFilterOptions);
$this->writeFilterCallback = Filter\fun($this->getWriteFilter(), $writeFilterOptions);
$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
if (null !== $writeFilterOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add some spacing before and after?

$this->writeFilterCallback = Filter\fun($this->getWriteFilter(), $writeFilterOptions);
$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
if (null !== $writeFilterOptions) {
@trigger_error('The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0. Use Http\Message\RequestMatcher\RequestMatcher instead.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

You mean Http\Message\RequestMatcher? (interface).

$this->writeFilterCallback = Filter\fun($this->getWriteFilter(), $writeFilterOptions);
$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
if (null !== $writeFilterOptions) {
@trigger_error('The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0. Use Http\Message\RequestMatcher\RequestMatcher instead.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

Also, maybe use sprintf and ::class constant for code brevity?

/**
* @var callable
*/
protected $writeFilterCallback;
Copy link
Member

Choose a reason for hiding this comment

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

Since this is an abstract class: isn't this a BC break too?

Copy link
Member

Choose a reason for hiding this comment

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

Removing a non-private function in a non-final class is always a BC break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, the $readFilter and $writeFilter properties should remain and should be marked as deprecated too.

@ajgarlag ajgarlag force-pushed the remove-encoding-writing-stuff branch from d5949f6 to 2477b70 Compare October 20, 2016 09:00
@ajgarlag
Copy link
Contributor Author

@sagikazarmark ready for review

@sagikazarmark
Copy link
Member

LGTM

@ajgarlag ajgarlag force-pushed the remove-encoding-writing-stuff branch from 2477b70 to b9b8f14 Compare October 20, 2016 09:52
*/
protected $writeFilterCallback;

/**
* @var resource
*
* @deprecated since version 1.5, will be removed in 2.0
*/
protected $writeFilter;
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be safely removed as it was always null and never used, even if it's BC i assume nobody use this (otherwise i really don't understand why xD)

@dbu @sagikazarmark ok to remove this even if it's somehow BC (never used, always null value in a protected scope so ...) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

i tend to agree, but lets maybe leave as is, there is stuff to remove when we go 2.0 anyways so we can play it safe. does not add cost to leave those in

@@ -24,16 +24,22 @@

/**
* @var resource
*
* @deprecated since version 1.5, will be removed in 2.0
*/
protected $readFilter;
Copy link
Member

Choose a reason for hiding this comment

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

Can be removed as well as the writeFilter

@joelwurtz joelwurtz merged commit 1761cb6 into php-http:master Oct 24, 2016
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.

None yet

5 participants