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

mark classes as final and methods and properties as private #123

Merged
merged 1 commit into from Dec 25, 2018
Merged

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Dec 2, 2018

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Related tickets partially #20
Documentation php-http/documentation#244
License MIT

What's in this PR?

Mark the remaining things final.

Why?

See #20

Checklist

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

@dbu
Copy link
Contributor Author

dbu commented Dec 2, 2018

ignore styleci here. we switched to pretty-ci, i disabled styleci for this repository now.

src/BatchClient.php Outdated Show resolved Hide resolved
src/HttpClientPoolItem.php Outdated Show resolved Hide resolved
@gmponos
Copy link
Contributor

gmponos commented Dec 2, 2018

I know that you want to enforce composition instead of inheritance but in real life scenarios there are cases that you will need to depend on implementation instead of abstraction.

This way it will make mocking impossible. Especially when clients like BatchClient do not have an abstraction layer for all of their methods.

Don't get me wrong I am all in for final but not for packages like this. If it was like guzzle having only one implementation I think it would make sense. But for packages like this one that contain multiple implementations of the same abstraction I think it's not the best thing to do...

For instance take a look at this.. it has no finals. Although I can't be sure if this was made on purpose. The point is that there will be real life scenarios that I will need to depend specifically in ArrayCache.. Same goes for clients inside this package.

That's my opinion for what is worth it.

@dbu
Copy link
Contributor Author

dbu commented Dec 2, 2018

hm, i see what you mean, and with the utility clients like batch or method client, you are certainly right. but i think we still want to prevent people from extending the specific clients. our options are:

  • mark them as @internal and if people rely on being able to extend the class, tell them "told you"
  • provide interfaces for those clients

i think i prefer the second option, as that is cleaner.

@php-http/owners wdyt?

@sagikazarmark and if you agree to make the clients final, can you check if its sane what i did with php spec?

@Nyholm
Copy link
Member

Nyholm commented Dec 4, 2018

I agree with @gmponos. If we should be really correct, we should use an interface for all classes we mark as final.

Interfaces could be added after 2.0.0 though. But (of course) we cannot add final.

@sagikazarmark
Copy link
Member

TBH I don't really like the Impl suffix. Unfortunately, I don't really have an alternative. :\

@joelwurtz
Copy link
Member

We could use the @final annotation ATM and then use an interface latter ?

src/HttpMethodsClient.php Outdated Show resolved Hide resolved
@dbu
Copy link
Contributor Author

dbu commented Dec 8, 2018

i added the interfaces. i opted to change the classes to Impl and keep the name for the interface. this way, everywhere the class was typehinted, this will now point to the interface. the only change needed is in the bootstrap where classes are implemented.

i think the interfaces are a clean thing here and we want them. if somebody has a better idea for the naming, i am happy to change it, but i don't know one. we could have a subnamespace for the implementations, but that does not seem better :-)

if the other @php-http/owners agree, i will do a pull request on the documentation as well.

@gmponos
Copy link
Contributor

gmponos commented Dec 19, 2018

TBH I don't really like the Impl suffix. Unfortunately, I don't really have an alternative. :\

It's the exact opposite of having Interface suffix to interfaces.

My point of view is that I would prefer to be inconsistent with interfaces and some to have the interface suffix and some will not.. rather with the classes... some to have the impl and some not.

src/BatchClientImpl.php Outdated Show resolved Hide resolved
@dbu
Copy link
Contributor Author

dbu commented Dec 19, 2018

for php-http we decided to avoid the interface suffix.

we could add it for those cases - it would also make the upgrade path a bit different, because there would be no BC break at all. instead, the user should change all of their code to typehint interface instead, but things work fine without, unless they want to test with mocks.

unless i hear any other arguments, i will go with the Interface suffix for these and chose ease of upgrade over consistency.

@sagikazarmark
Copy link
Member

I would also probably go with the interface suffix with a big fat warning, that otherwise that's a ten kittens offense

We add interfaces for final classes so that they can be mocked in testing.
We chose to use the Interface suffix here to avoid name clashes, rather than renaming the existing PHP classes.
The interfaces are only relevant for unit testing, we do not expect people to provide their own implementations.

HttpClientPoolItem is purely internal and we therefore don't want an interface for it.
It is marked with @Final and explained to not be meant to extend.
@dbu
Copy link
Contributor Author

dbu commented Dec 20, 2018

okay, i changed to the interface suffix and like the changes and its impact a lot more! want to merge @sagikazarmark ?

@dbu
Copy link
Contributor Author

dbu commented Dec 20, 2018

php-http/HttplugBundle#291 and php-http/documentation#244 also become much simpler this way \o/

@dbu dbu merged commit 4d59cc4 into 2.x Dec 25, 2018
@dbu dbu deleted the mark-as-final branch December 25, 2018 14:12
@sagikazarmark
Copy link
Member

Sorry, looks good to me. 👍

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