The following code will produce an error:
try {
$entityManager->flush();
} catch( UniqueConstraintViolationException $ex ) {
// do something with $ex here
}
The error message is Doctrine\DBAL\Exception\UniqueConstraintViolationException is never thrown in the try block. This is kind-of-true, since that exception is not declared on EntityManager::flush, but bubbles up from the DBAL implementation. It's been raised as an issue on the repo ( doctrine/orm#7780 ), but so far it looks like this is "by design" and won't be fixed.
Could you create an "exception" (no pun intended) for this exception in PHPStan to ignore catch segments that look for UniqueConstraintViolationException?