1.2.256. Could Be Else¶
Merge opposite conditions into one if/then structure.
When two if/then structures follow each other, using a condition and its opposite, they may be merged into one.
<?php
// Short version
if ($a == 1) {
$b = 2;
} else {
$b = 1;
}
// Long version
if ($a == 1) {
$b = 2;
}
if ($a != 1) {
$b = 3;
}
?>
1.2.256.1. Connex PHP features¶
1.2.256.1.1. Suggestions¶
Merge the two conditions into one structure
Check if the second condition is still applicable
1.2.256.1.2. Specs¶
Short name |
Structures/CouldBeElse |
Rulesets |
|
Exakat since |
1.0.1 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Examples |
|
Available in |