phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
592 stars 46 forks source link

`class-string` should not be settable using string literal #223

Open mvorisek opened 1 year ago

mvorisek commented 1 year ago

repro: https://phpstan.org/r/1b7e94a5-9263-4f0c-83f8-a2964c1b5d5c

This is a feature request to emit a phpstan error /w strict rules to enforce the user to set the string using Xxx::class syntax.

Xxx::class is guaranteed to be always checked by static analysis, is more readable and always in canonical form - no leading backslash.

kamil-zacek commented 5 months ago

In my opinion - rule should be little bit different. It should check whether string literal is assigned to the class-string this should check whether string contains existing class name. To avoid unnecessary autoload for files with classes only for get class name.

mvorisek commented 5 months ago

👍, like any other class (name) is checked.