syntro-opensource/silverstripe-phpstan

Bug: DataList return types do not respect possible `null` return type

Opened this issue · 2 comments

consider the following:

$result = SomeObject::get()->byID(3);

if ($result) { ... }

In this situation, phpstan will fail with an always true boolean expression.

@JamesDPC Not sure about that, the mentioned function only tells phpstan that the method is supported, it does not change the type returned. When writing the issue, PHPStan assumed that the return type is always DataObject and not DataObject|null as it should be. I'm unsure wether this issue still persists, will have to recheck.