Here we could do:
if ($transport) {
    $mail->send($transport);
} else {
    $mail->send();
}