You could use `instanceof $targetEntityClass`