phpstan-strict-rules
phpstan-strict-rules copied to clipboard
Idea: disallow protected members in final classes
Originally reported as https://github.com/slevomat/coding-standard/issues/563 but impossible to implement there.
The idea is to ensure that final classes don't contain any new protected members. Such members can be made private because there are no descendants that can use them. Special care has to be taken to avoid changing protected methods from parent classes to private, such as in this example:
abstract class MyAbstractClass
{
protected function protectedFunction()
{
echo 'foo';
}
}
final class MyClass extends MyAbstractClass
{
protected function protectedFunction()
{
echo 'bar';
}
}
In this case, protectedFunction may not cause an error because its visibility can't be changed to private.