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

Immutable object properties must be immutable objects #5

Open svnldwg opened 3 years ago

svnldwg commented 3 years ago

If a class has a property of type object which is declared immutable and accessible from outside (public or via getter), the object itself must be immutable as well.

Example:


/** @var immutable */
class Immutable
{
    public Cat $cat;
}

class Cat {
    public int $lala; // not allowed here, Cat must be immutable
}