1.2.1102. Short Or Complete Comparison¶
Which type of condition is used for boolean comparisons : either short or formal.
Formal is an explicit comparison to another boolean, while short is when the variable is used without comparison.
The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make them all the same.
<?php
// returns a boolean
$checked = checkSomething();
// short comparison
if ($checked) {
// doSomething()
}
// also short comparison
if (!$checked) {
// doSomething()
}
// formal comparison
if ($checked === true) {
// doSomething()
}
?>
1.2.1102.1. Specs¶
Short name |
Structures/ShortOrCompleteComparison |
Rulesets |
|
Exakat since |
2.5.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |