diff --git a/if-Statement.md b/if-Statement.md new file mode 100644 index 0000000..4488622 --- /dev/null +++ b/if-Statement.md @@ -0,0 +1,71 @@ +Use `elseif` instead of `else if`. For sake of consistency `else if` is considered bad practice. + +
Example

+ +**Bad** + +```PHP +if($conditionA) { + +} else if($conditionB) { + +} +``` + +**Good** + +```PHP +if($conditionA) { + +} elseif($conditionB) { + +} +``` + +

+ +_Reference_: [`PSR2.ControlStructures.ElseIfDeclaration`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php) + +*** + +Empty statements are considered bad practice and must be avoided. + +
Example

+ +**Bad** + +```PHP +if($condition) { + // empty statement +} else { + // do something here +} +``` + +**Good** (invert condition) + +```PHP +if(!$condition) { + // do something +} +``` + +

+ +_Reference_: [`Generic.CodeAnalysis.EmptyStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php) + +*** + +Do not write unconditional if-statements. If-statements without conditions are considered bad practice and must be avoided. + +
Example

+ +```PHP +if(true) { + +} +``` + +

+ +_Reference_: [`Generic.CodeAnalysis.UnconditionalIfStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php) \ No newline at end of file