Multi-line if statements

Sometimes, the checks in code are so complex, that we have to write very sophisticated conditionals that have lots of conditional expressions. One might say that this is a bad practice. Maybe - but in some cases this is an inevitable evil. The main question is to format it.

In different communities, the heated discussions about multi-line if statements arise from time to time, as well as the discussions about nested ternary operators. I’d like to put my two cents on this topic. So, what is the main point of the discussion?

Let’s take a piece of code from the Slim tutorial. The code can be formatted in very different ways.

if (!($exception instanceof HttpException) && ($exception instanceof Exception || $exception instanceof Throwable) && $this->displayErrorDetails) {
    $error->setDescription($exception->getMessage());
}
if (
    !($exception instanceof HttpException) &&
    ($exception instanceof Exception || $exception instanceof Throwable) &&
    $this->displayErrorDetails
) {
    $error->setDescription($exception->getMessage());
}
if (
    !($exception instanceof HttpException)
    && ($exception instanceof Exception || $exception instanceof Throwable)
    && $this->displayErrorDetails
) {
    $error->setDescription($exception->getMessage());
}

Which one would you prefer? I definitely prefer the last one. The reason behind my decision is that it is more readable than the first one (and even seems less complex). But even more important is that this style of formatting gives us the possibility to easily comment out any of the conditions. Which consequently opens the road to simpler testing and faster debugging.