mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-02 22:57:26 +02:00
Created if-Statement (markdown)
71
if-Statement.md
Normal file
71
if-Statement.md
Normal file
@@ -0,0 +1,71 @@
|
||||
Use `elseif` instead of `else if`. For sake of consistency `else if` is considered bad practice.
|
||||
|
||||
<details><summary>Example</summary><div><br>
|
||||
|
||||
**Bad**
|
||||
|
||||
```PHP
|
||||
if($conditionA) {
|
||||
|
||||
} else if($conditionB) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
**Good**
|
||||
|
||||
```PHP
|
||||
if($conditionA) {
|
||||
|
||||
} elseif($conditionB) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
</div></details><br>
|
||||
|
||||
_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.
|
||||
|
||||
<details><summary>Example</summary><div><br>
|
||||
|
||||
**Bad**
|
||||
|
||||
```PHP
|
||||
if($condition) {
|
||||
// empty statement
|
||||
} else {
|
||||
// do something here
|
||||
}
|
||||
```
|
||||
|
||||
**Good** (invert condition)
|
||||
|
||||
```PHP
|
||||
if(!$condition) {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
</div></details><br>
|
||||
|
||||
_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.
|
||||
|
||||
<details><summary>Example</summary><div><br>
|
||||
|
||||
```PHP
|
||||
if(true) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
</div></details><br>
|
||||
|
||||
_Reference_: [`Generic.CodeAnalysis.UnconditionalIfStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php)
|
Reference in New Issue
Block a user