Source: @Fleshgrinder
We could check the configured PHP version for the project and recommend the usage of a [public] const instead of a public static.
In some cases we can convert class static property to the class constant.
For example we have following code:
class User{
public static $statuses = [
'a'=>'Active',
'd'=>'Deleted',
];
}
Inspection can handle property $statuses and suggest to use constant:
class User{
const STATUSES = [
'a'=>'Active',
'd'=>'Deleted',
];
}
This inspection can be implemented in different ways:
I prefer 1 case ;)
On PHP 7.1, it could checks for privates and protecteds too.
I prefer case 2, there is nothing wrong about writing to static properties.
@Fleshgrinder static properties change global state. And global state is always a bad way.
2 case can be implemented only if we have private property. With public properties it will be hard to scan whole project and find writes.
Obviously I was thinking of a max. visibility of protected since having a public property (other than a DTO) is always a huge smell in my book; regardless of whether it is static or not. 馃槈
Bebo beep, the StaleBot is here. For one year nothing have happened here. It would be great if someone looked into details here within next 21 days when I'll close it.
Bebo beep, the StaleBot is here. For one year nothing have happened here. It would be great if someone looked into details here within next 21 days when I'll close it.
That'd be a complete semantics change, so I'll keep this closed. @funivan: feel free to take the issue over for your plugin.
Most helpful comment
On PHP 7.1, it could checks for privates and protecteds too.