Bug: DataList return types do not respect possible `null` return type
Opened this issue · 2 comments
mleutenegger commented
consider the following:
$result = SomeObject::get()->byID(3);
if ($result) { ... }
In this situation, phpstan will fail with an always true boolean expression.
JamesDPC commented
Hello ... is the fix (for byID) to simply remove it at https://github.com/syntro-opensource/silverstripe-phpstan/blob/master/src/Type/DataListReturnTypeExtension.php#L52 ?
mleutenegger commented
@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.