-
Notifications
You must be signed in to change notification settings - Fork 28
[Proposal] Make some classes final out of the box #1594
Comments
Final is a pain in the ass then it comes to tests and mocking stuff |
@ludo237 I didn't experience that. Can you provide some example please? Tnx |
@MladenJanjetovic @ludo237 is right, mocking final classes is not possible with contemporary versions od PHPUnit. See sebastianbergmann/phpunit-mock-objects#388 (comment), albeit I can not think of a use case when you would need to mock a final class as I usually mock interfaces in general PHP projects. No experience of how this would influence Laravel testing workflow though. |
@srdjanmarjanovic Agree. But when will you mock any of the classes I listed above in proposal? |
If you want to make your own classes final, Laravel gives you the freedom to do that. I think |
It would be nice to follow good practice and make most of the classes final.
There are several facts that this can improve code quality and make development easier and safer.
Here are some nice reads:
https://ocramius.github.io/blog/when-to-declare-classes-final/
https://matthiasnoback.nl/2018/09/final-classes-by-default-why/
I guess that these classes can be made Final out of the box, and when making them with CLI:
Just for example, imagine when you want to extend your custom class in IDE and you don't get all of these above listed as autocomplete :)
These are just off the top of my head. I can create PRs for this.
@taylorotwell Let me know
Best,
The text was updated successfully, but these errors were encountered: