from time to time I stuble over code which should have used a native constant property, but uses a static property instead.
I think some people mix up static with constant.
could rector detect private properties which are only used in a readonly fashion and turn them into constants?
Example
class A {
- private static array $availableSizes = [
+ private const AVAILABLE_SIZES = [
'sm' => 'small',
'me' => 'medium',
'la' => 'large',
];
public function getFoo() {
- return self::$availableSizes;
+ return self::AVAILABLE_SIZES
}
}
We actually had such a rule but it was impossible to detect if property is changed or not. Due to references, magic and more magic :) we removed it to avoid WTFs and false positives.
Feature Request
from time to time I stuble over code which should have used a native constant property, but uses a static property instead. I think some people mix up
static
withconstant
.could rector detect private properties which are only used in a readonly fashion and turn them into constants?
Example