Formatting options for a long IF statement?
I've used the second snippet since I've found that much easier/faster to understand:


Here you could omit the else keyword:


if (empty($row)) { // if the row doesn't exist
    return $this-&gt;updateRow($id);
}
else { // the row does exist
...
}



The following is the same:

if (empty($row)) { // if the row doesn't exist
    return $this-&gt;updateRow($id);
}
// the row does exist
...

Then, you could create an explanatory variable to make the comments unnecessary:

$rowExists = !empty($row)
if (!rowExists) {
    return $this-&gt;updateRow($id);
}
...

Another explanatory variable with an inverted condition:

$rowExists = !empty($row)
if (!rowExists) {
    return $this-&gt;updateRow($id);
}

$updatedToday = (date('j', time()) == date('j', strtotime($row['date_added'])));
if ($updatedToday) {
    return 0;
}


Explanatory variables give names to the expression and reveal the developer's intent, so maintainers will know what's the purpose of (date('j', time()) == date('j', strtotime($row['date_added']))) faster (it should mean that we have an update today) (he or she doesn't have to figure it out or reverse engineer). 

It also makes bug fixing faster since a maintainer easily can validate whether the purpose is wrong (we need to check whether we have an update this week instead of this day!) or the implementation (to check that we have an update today or not we should use created field instead of date_added, for example).
Yet another explanatory variables and flattened conditonals:

$neverIgnored = empty($row['ignore']);
if ($neverIgnored) {
    return $this-&gt;updateRow($id);
}

$ignoredLastWeek = (time() - strtotime($row['ignore']) &lt; 3600 * 24 * 7);
if ($ignoredLastWeek) {
    return 0;
}

return $this-&gt;updateRow($id);



Final code:

$rowExists = !empty($row)
if (!rowExists) {
    return $this-&gt;updateRow($id);
}

$updatedToday = (date('j', time()) == date('j', strtotime($row['date_added'])));
if ($updatedToday) {
    return 0;
}

$neverIgnored = empty($row['ignore']);
if ($neverIgnored) {
    return $this-&gt;updateRow($id);
}

$ignoredLastWeek = (time() - strtotime($row['ignore']) &lt; 3600 * 24 * 7);
if ($ignoredLastWeek) {
    return 0;
}

return $this-&gt;updateRow($id);


You could also create a boolean isUpdateNeeded() function:

function isUpdateNeeded(...) {
    $rowExists = !empty($row)
    if (!rowExists) {
        return true;
    }

    $updatedToday = (date('j', time()) == date('j', strtotime($row['date_added'])));
    if ($updatedToday) {
        return false;
    }

    $neverIgnored = empty($row['ignore']);
    if ($neverIgnored) {
        return true;
    }

    $ignoredLastWeek = (time() - strtotime($row['ignore']) &lt; 3600 * 24 * 7);
    if ($ignoredLastWeek) {
        return false;
    }

    return true;
}

if (isUpdateNeeded(...)) {
    return $this-&gt;updateRow($id);
}
return 0;


References:


Clean Code by Robert C. Martin, G19: Use Explanatory Variables
Clean Code by Robert C. Martin, Bad Comments, p67: Don’t Use a Comment When You Can Use a Function or a Variable
Refactoring: Improving the Design of Existing Code by Martin Fowler, Introduce Explaining Variable
Flattening Arrow Code