svnldwg / phpstan-rules

Collection of useful additional phpstan rules. Currently only one rule, which checks immutability of objects (e.g. value objects) or properties.
MIT License
7 stars 0 forks source link

Immutability with inheritance #2

Closed svnldwg closed 3 years ago

svnldwg commented 4 years ago

Ensure that protected or public properties annotated as immutable are not mutated in a child class.

The following example should lead to an error:

/**
 * @immutable
 */
class ImmutableClass {
    protected $value;
}

class ChildClassThatMutatesParent extends ImmutableClass {
    public function setValue($value) {
        $this->value = $value;
    }
}