Skip to content

PriorityQueueMinOrderAssumption ​

warning native off by default PHP ≥ 5.3

Group: Probable bugs

Reverse priorities for smallest-first extraction. This opt-in inspection applies the policy stated in Detection.

Example ​

Finding with the rule explicitly enabled:

php
<?php
$q = new SplPriorityQueue(); $q->insert("first", 2); $q->insert("second", 8); $q->extract();

Reported:

  • line 2: Reverse priorities for smallest-first extraction.

Detection ​

  • Enabled policy requires smallest numeric priority first. Report first extraction from an exact builtin SplPriorityQueue with at least two distinct proven literal numeric priorities since construction, using unmodified inherited comparator. Highlight extract/top/current call. The queue inherently returns the largest priority first.
  • Emit one finding per violating operation. Flow facts require a reachable path with no intervening mutation, escaped alias, unknown call involving the tracked value or analysis-budget exhaustion. Uncertain facts cannot prove a violation.

Exceptions (no report) ​

  • Exclude a single priority, tied priorities, unknown priorities, subclasses with custom compare, proven negated priorities and invalidated queue state. Enabling states the numeric ordering policy; labels and comments are not evidence.
  • Exclude shadowed builtin symbols, unresolved required types, incomplete syntax and unsupported PHP versions.

Fix ​

No automatic fix. Choosing a repair requires runtime information, error-handling policy or a semantic decision.

All edits use exact byte ranges, preserve comments and evaluation order, and require syntax supported by the target PHP version. A fix must never add an evaluation or silently change unrelated arguments.

PHP versions ​

Minimum PHP 5.3.

Options ​

None. Enabling the rule declares the policy stated in Detection; the rule is disabled by default.

Configure ​

In custos.json:

json
{
  "rules": {
    "PriorityQueueMinOrderAssumption": {
      "enabled": true
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore PriorityQueueMinOrderAssumption

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.