CollatorComparisonTruthinessReversed
warning native off by default PHP ≥ 5.3Group: Probable bugs
Compare collation results explicitly.
Example
php
<?php
$c=new Collator("en_US"); if ($c->compare("cobalt","cobalt") === true) { echo "equal"; }Reported:
- line 2: Compare collation results explicitly.
Detection
This is an opt-in policy. Truthiness, previous-state checks, raw wait-status comparisons and dispatch acknowledgements can be intentional; enabling this rule requests explicit handling of the contract described below.
- Report direct truthiness, negation, assignment-in-condition, or equality against true of resolved Collator::compare. Loose and strict equality both count, with the true constant on either side of the operator. Highlight the complete comparison when the misuse is equality against true; otherwise highlight the call. Equality is zero; failure is false. Desired ordering is not inferred.
- Resolve builtin functions, extension classes, method receivers, constants and named arguments. Follow unchanged locals and aliases only within the same bounded lexical scope. Require a reachable path; merge branch facts only when all incoming paths establish them.
- Emit one finding at the violating operation, not one per evidence statement. Rebinding, writes, by-reference escape and unresolved calls that can mutate relevant state remove proof. When the proof is inconclusive, nothing is reported.
Exceptions (no report)
- Exclude shadowed builtins, unresolved receivers, incomplete syntax and unknown prerequisite facts. An extension function name alone does not prove an application function is that builtin.
- A dominating valid guard or repair described in Detection prevents the finding. Both legacy noinspection and custos-ignore forms suppress this ID.
Fix
No automatic fix. Neither truthiness nor comparison against true establishes whether equality, ascending order or descending order was intended.
PHP versions
Requires PHP 5.3 or later and the referenced extension API. Respect method-specific introduction versions within PHP 5.3–8.5; unsupported optional APIs cannot establish facts. Named arguments require PHP 8.0 or later.
Configure
In custos.json:
json
{
"rules": {
"CollatorComparisonTruthinessReversed": {
"enabled": true
}
}
}Suppress
Before the statement or declaration (or the first statement of the file):
php
// @custos-ignore CollatorComparisonTruthinessReversed