1.2.545. If With Same Conditions¶
Successive If / then structures that have the same condition may be either merged or have one of the condition changed. Note that if the values used in the condition have been modified in the first if/then structure, the two distinct conditions may be needed.
<?php
if ($a == 1) {
doSomething();
}
if ($a == 1) {
doSomethingElse();
}
// May be replaced by
if ($a == 1) {
doSomething();
doSomethingElse();
}
?>
1.2.545.1. Suggestions¶
Merge the two conditions so the condition is used once.
Change one of the condition, so they are different
Make it obvious that the first condition is a try, preparing the normal conditions.
1.2.545.2. Specs¶
Short name |
Structures/IfWithSameConditions |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Examples |
|
Available in |