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

Final Classes without Interfaces #5890

Open
bytes-commerce opened this issue Aug 28, 2023 · 5 comments
Open

Final Classes without Interfaces #5890

bytes-commerce opened this issue Aug 28, 2023 · 5 comments

Comments

@bytes-commerce
Copy link
Contributor

If a class is marked as final, it should have an Interface.

Why? PHPUnit Tests. In Unit Tests I never want to use new $something(); unless its the class I want to test. EasyAdmin does not allow me to inject some classes by Interface reference.

@dwd-akira
Copy link
Contributor

dwd-akira commented Aug 28, 2023

See #5299 and https://github.com/EasyCorp/easyadmin-no-final-plugin

@bytes-commerce
Copy link
Contributor Author

I see, interesting, thats not however really what I am suggesting.

Instead, there should be Interfaces. Just imagine you inject a dependency that is final and you want to write a PHPUnit test for that class. You cannot - at least not with some ugly hacks that you should avoid.

Having interfaces at hand allow for simple injection of anything without having to remove final.

@oleg-andreyev
Copy link
Contributor

+1 here, I'm +1 to disallow inheritance, keep it final but composition is key of OOP, so need to provide an interface so that I could decorate it

@bytes-commerce
Copy link
Contributor Author

@oleg-andreyev I am working on PRs to introduce more and more interfaces. You can review this open PR to support me on the matter. 👍 #5996

@jbonnier
Copy link

@oleg-andreyev, I don't think I can decorate fields which is what I need to extend/modify.

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

No branches or pull requests

4 participants