PHPStan extension for final classes (in theory) that cannot be final (because of mocking, Doctrine proxies, etc) #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 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! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, I shy away from introducing custom attributes like that because they'd create problems at runtime - since PHPStan is a dev dependency, instantiating those attributes would fail. There's already some support for reading |
Beta Was this translation helpful? Give feedback.
Hi, I shy away from introducing custom attributes like that because they'd create problems at runtime - since PHPStan is a dev dependency, instantiating those attributes would fail.
There's already some support for reading
@final
, the annotation just haven't been read by the corresponding rule. I just added the check. You'll see it if you enable bleeding edge: phpstan/phpstan-src@dffd2c2