PHPStan wants to take my sanity checking away!

Consider this:

public function doSomething(ImageInterface $image) {

  $imageId = $image?->id();

  if (!$imageId) {

    throw new \Exception('Bad image');

  }
}

If you run PHPStan on that at a high enough level, it will complain that the question mark isn't necessary because $image is guaranteed to not be NULL.

And, yes, it's right. However, I'd prefer to keep that check in place just in case someone does something like remove the type hint.

Because without "ImageInterface", someone could pass NULL to that method and cause an error. And, if they don't subsequently run PHPStan at the same high level as before, that could be missed.

Technology