PHPStan extension for final classes (in theory) that cannot be final (because of mocking, Doctrine proxies, etc) · phpstan/phpstan · Discussion #5343
Hello there,
I was thinking about final classes, and how much I like them. And then I was thinking about the few classes in my projects that are not final and might, without further notice, be inherited from - even though they should not. The reason they are not final is always "technical" : they are Doctrine entities (which uses proxies), mocked by tests frameworks (PHPUnit & Prophecy), etc.
And then I was wondering if we could add a PHP8 attribute #[Final], that a PHPStan extension could use to look for classes extending the class having such an attribute, and triggering an error if it finds one (a PHPDoc block /** @phpstan-final */ would work too I guess).
What do you think ? Could this be an official PHPStan extension (or even part of core) ? I don't know much about the current ecosystem's approach to Attributes and how they are intended to be used. I'm eager to hear your opinions.
Thanks!
gnutix