1.2.813. No Need For Else¶
<?php
function foo() {
// Else may be in the main sequence.
if ($a1) {
return $a1;
} else {
$a++;
}
// Same as above, but negate the condition : if (!$a2) { return $a2; }
if ($a2) {
$a++;
} else {
return $a2;
}
// This is OK
if ($a3) {
return;
}
// This has no break
if ($a4) {
$a++;
} else {
$b++;
}
// This has no else
if ($a5) {
$a++;
}
}
?>
See also Object Calisthenics, rule # 2.
1.2.813.1. Suggestions¶
Remove else block, but keep the code
1.2.813.2. Specs¶
Short name |
Structures/NoNeedForElse |
Rulesets |
|
Exakat since |
0.10.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
if-then |
Examples |
|
Available in |