'How to tell psalm to save getter state if property wasn't modified before the further checks?

class A
{
    private ?string $x = null;

    public function getX(): ?null
    {
        return $this->x;
    }
}

class B
{
    public function __construct(string $y)
    {
        // Property initialization...
    }
}

$a = new A();
if ($a->getX() !== null) {
    $b = new B($a->getX());
}

For this code snippet psalm will return an error like PossiblyNullOperand or similar. I know that this is kind of an expected behavior, and can be fixed like this:

$a = new A();
if (($x = $a->getX()) !== null) {
    $b = new B($x);
}

But is there a configuration parameter in psalm, which will ignore these errors for methods like getters which always return the same result?

Psalm version: 4.18.x



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source