phppsr-12

PSR-12 if statement


Can I use if statement like:

if (!true) {
    return false
}

Or something like this:

if (! true) {
    return false
}

Solution

  • According to PSR example all conditions in if clauses have no space before or after the expressions. In your case then

    if (!true) {
        return false;
    }
    

    would be a case. Remember that with short expressions you can always use ternary operator and if you have complex condition to be checked, consider to put it into variable.