EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Final Classes without Interfaces

Open bytes-commerce opened this issue 2 years ago • 5 comments

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.

bytes-commerce avatar Aug 28 '23 12:08 bytes-commerce

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

dwd-akira avatar Aug 28 '23 21:08 dwd-akira

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.

bytes-commerce avatar Aug 30 '23 07:08 bytes-commerce

+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

oleg-andreyev avatar Nov 06 '23 16:11 oleg-andreyev

@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. :+1: https://github.com/EasyCorp/EasyAdminBundle/pull/5996

bytes-commerce avatar Nov 06 '23 16:11 bytes-commerce

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

jbonnier avatar Apr 27 '24 15:04 jbonnier