4 if Statement
LogMANOriginal edited this page 2018-11-05 13:46:28 +01:00

Use elseif instead of else if

For sake of consistency else if is considered bad practice.

Example

Bad

if($conditionA) {

} else if($conditionB) {

}

Good

if($conditionA) {

} elseif($conditionB) {

}

Reference: PSR2.ControlStructures.ElseIfDeclaration

Do not write empty statements

Empty statements are considered bad practice and must be avoided.

Example

Bad

if($condition) {
    // empty statement
} else {
    // do something here
}

Good (invert condition)

if(!$condition) {
    // do something
}

Reference: Generic.CodeAnalysis.EmptyStatement

Do not write unconditional if-statements

If-statements without conditions are considered bad practice and must be avoided.

Example

if(true) {

}

Reference: Generic.CodeAnalysis.UnconditionalIfStatement