1.2.269. Could Be Spaceship¶
The spaceship operator compares values and returns 0 for equality, 1 for superior and -1 for inferior.
It is the same as below, and prevents lots of code.
<?php
if ($a) {
return 1;
} elseif ($b) {
return 0;
} else {
return -1;
}
?>
See also spaceship operator and Remembering what spaceship operator do on comparison in PHP.
1.2.269.1. Connex PHP features¶
1.2.269.1.1. Suggestions¶
Adopt the spaceship operator
1.2.269.1.2. Specs¶
Short name |
Structures/CouldBeSpaceship |
Rulesets |
|
Exakat since |
2.4.0 |
PHP Version |
With PHP 7.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |