Skip to main content

mir_issues/
lib.rs

1use std::collections::HashSet;
2use std::fmt;
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7mod psalm_levels;
8pub use psalm_levels::psalm_error_level;
9
10// ---------------------------------------------------------------------------
11// Severity
12// ---------------------------------------------------------------------------
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
15pub enum Severity {
16    /// Only shown with `--show-info`
17    Info,
18    /// Warnings — shown at default level
19    Warning,
20    /// Errors — always shown; non-zero exit code
21    Error,
22}
23
24impl fmt::Display for Severity {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Severity::Info => write!(f, "info"),
28            Severity::Warning => write!(f, "warning"),
29            Severity::Error => write!(f, "error"),
30        }
31    }
32}
33
34// ---------------------------------------------------------------------------
35// Location
36// ---------------------------------------------------------------------------
37
38pub use mir_types::Location;
39
40// ---------------------------------------------------------------------------
41// IssueKind
42// ---------------------------------------------------------------------------
43
44/// Why `clone` fails for [`IssueKind::InvalidClone`].
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub enum CloneFailure {
47    NonObject,
48    Enum,
49    /// `scope` is the calling class, `None` outside any class.
50    PrivateMethod {
51        owner: String,
52        scope: Option<String>,
53    },
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57#[non_exhaustive]
58pub enum IssueKind {
59    // --- Undefined ----------------------------------------------------------
60    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
61    /// Fixtures: `tests/fixtures/by-kind/invalid_scope/`.
62    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
63    /// Fixtures: `tests/fixtures/by-kind/invalid_scope/self_non_static_invocation.phpt`.
64    NonStaticSelfCall { class: String, method: String },
65    InvalidScope {
66        /// `true` when inside a class but in a static method; `false` when outside a class.
67        in_class: bool,
68    },
69    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
70    /// Fixtures: `tests/fixtures/by-kind/undefined_variable/`.
71    UndefinedVariable { name: String },
72    /// Emitted by `mir-analyzer/src/call/function.rs`.
73    /// Fixtures: `tests/fixtures/by-kind/undefined_function/`.
74    UndefinedFunction { name: String },
75    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
76    /// Fixtures: `tests/fixtures/by-kind/undefined_method/`.
77    UndefinedMethod { class: String, method: String },
78    /// Emitted by `mir-analyzer/src/call/method.rs`.
79    /// Fixtures: `tests/fixtures/by-kind/undefined_method/`.
80    PossiblyUndefinedMethod { class: String, method: String },
81    /// Emitted by `mir-analyzer/src/batch/mod.rs`.
82    /// Fixtures: `tests/fixtures/by-kind/undefined_class/`.
83    UndefinedClass { name: String },
84    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
85    /// Fixtures: `tests/fixtures/by-kind/undefined_property/`.
86    UndefinedProperty { class: String, property: String },
87    /// A private or protected property is read from outside the scope PHP
88    /// visibility rules allow — a fatal error at runtime.
89    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
90    /// Fixtures: `tests/fixtures/by-kind/inaccessible_property/`.
91    InaccessibleProperty { class: String, property: String },
92    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
93    /// Fixtures: `tests/fixtures/by-kind/undefined_constant/`.
94    UndefinedConstant { name: String },
95    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
96    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/invalid_*_class_const_fetch*.phpt`.
97    InaccessibleClassConstant { class: String, constant: String },
98    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
99    /// Fixtures: `tests/fixtures/by-kind/possibly_undefined_variable/`.
100    PossiblyUndefinedVariable { name: String },
101    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
102    /// Fixtures: `tests/fixtures/by-kind/undefined_trait/`.
103    UndefinedTrait { name: String },
104    /// A trait's constant is fetched directly (`SomeTrait::CONST`) rather
105    /// than through a class that `use`s it — a PHP fatal error regardless of
106    /// whether the constant exists, since a trait is never itself a valid
107    /// constant-access target.
108    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
109    /// Fixtures: `tests/fixtures/by-kind/undefined_class/trait_constant_accessed_directly*.phpt`.
110    TraitConstantAccessedDirectly {
111        trait_name: String,
112        constant: String,
113    },
114    /// A trait `use` adaptation (`use T { T::missing as alias; }`, or an
115    /// unqualified `as` naming no method any used trait declares) aliases a
116    /// method that doesn't exist — a PHP fatal error at class-declaration
117    /// time, checked the same way a bad `insteadof`/undefined trait already
118    /// is by `check_trait_constraints`.
119    /// Emitted by `mir-analyzer/src/body_analysis/classes.rs`.
120    /// Fixtures: `tests/fixtures/by-kind/undefined_method/trait_alias*.phpt`.
121    UndefinedTraitAliasMethod {
122        trait_name: Option<String>,
123        method: String,
124    },
125    /// Emitted when `parent` is used in a class that has no parent (the parser's `ParentWithoutParentClass`).
126    /// Fixtures: `tests/fixtures/by-kind/parent_not_found/`.
127    ParentNotFound,
128    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
129    /// Fixtures: `tests/fixtures/by-kind/invalid_string_class/`.
130    InvalidStringClass { actual: String },
131    /// Emitted by `mir-analyzer/src/call/args/types.rs` when an `interface-string`-typed
132    /// argument names a class or trait that exists but is not an interface.
133    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/interface_string_*.phpt`.
134    NotAnInterface { name: String },
135
136    // --- Nullability --------------------------------------------------------
137    /// Emitted by `mir-analyzer/src/call/args.rs`.
138    /// Fixtures: `tests/fixtures/by-kind/null_argument/`.
139    NullArgument { param: String, fn_name: String },
140    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
141    /// Fixtures: `tests/fixtures/by-kind/null_property_fetch/`.
142    NullPropertyFetch { property: String },
143    /// Emitted by `mir-analyzer/src/call/method.rs`.
144    /// Fixtures: `tests/fixtures/by-kind/null_method_call/`.
145    NullMethodCall { method: String },
146    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
147    /// Fixtures: `tests/fixtures/by-kind/null_array_access/`.
148    NullArrayAccess,
149    /// Emitted by `mir-analyzer/src/call/args.rs`.
150    /// Fixtures: `tests/fixtures/by-kind/possibly_null_argument/`.
151    PossiblyNullArgument { param: String, fn_name: String },
152    /// Emitted by `mir-analyzer/src/call/args.rs`.
153    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_argument/`.
154    PossiblyInvalidArgument {
155        param: String,
156        fn_name: String,
157        expected: String,
158        actual: String,
159    },
160    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
161    /// Fixtures: `tests/fixtures/by-kind/possibly_null_property_fetch/`.
162    PossiblyNullPropertyFetch { property: String },
163    /// Emitted by `mir-analyzer/src/call/method.rs`.
164    /// Fixtures: `tests/fixtures/by-kind/possibly_null_method_call/`.
165    PossiblyNullMethodCall { method: String },
166    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
167    /// Fixtures: `tests/fixtures/by-kind/possibly_null_array_access/`.
168    PossiblyNullArrayAccess,
169    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
170    /// Fixtures: `tests/fixtures/by-kind/nullable_return_statement/`.
171    NullableReturnStatement { expected: String, actual: String },
172
173    // --- Type mismatches ----------------------------------------------------
174    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
175    /// Fixtures: `tests/fixtures/by-kind/invalid_return_type/`.
176    InvalidReturnType { expected: String, actual: String },
177    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
178    /// Fixtures: `tests/fixtures/by-kind/less_specific_return_statement/`.
179    LessSpecificReturnStatement { expected: String, actual: String },
180    /// Emitted by `mir-analyzer/src/call/args.rs`.
181    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/`.
182    InvalidArgument {
183        param: String,
184        fn_name: String,
185        expected: String,
186        actual: String,
187    },
188    /// Emitted by `mir-analyzer/src/call/args/types.rs`.
189    /// Fixtures: `tests/fixtures/by-kind/invalid_scalar_argument/`.
190    InvalidScalarArgument {
191        param: String,
192        fn_name: String,
193        expected: String,
194        actual: String,
195    },
196    /// Emitted by `mir-analyzer/src/call/callable.rs`.
197    /// Fixtures: `tests/fixtures/by-kind/too_few_arguments/`.
198    TooFewArguments {
199        fn_name: String,
200        expected: usize,
201        actual: usize,
202    },
203    /// Emitted by `mir-analyzer/src/call/function.rs`.
204    /// Fixtures: `tests/fixtures/by-kind/too_many_arguments/`.
205    TooManyArguments {
206        fn_name: String,
207        expected: usize,
208        actual: usize,
209    },
210    /// Emitted by `mir-analyzer/src/call/args.rs`.
211    /// Fixtures: `tests/fixtures/by-kind/invalid_named_argument/`.
212    InvalidNamedArgument {
213        fn_name: String,
214        name: String,
215        overwrites: bool,
216    },
217    /// Emitted when a function/method tagged `@no-named-arguments` is called with named args.
218    /// Fixtures: `tests/fixtures/by-kind/invalid_named_argument/`.
219    InvalidNamedArguments { fn_name: String },
220    /// Emitted by `mir-analyzer/src/call/args.rs`.
221    /// Fixtures: `tests/fixtures/by-kind/invalid_pass_by_reference/`.
222    InvalidPassByReference { fn_name: String, param: String },
223    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
224    /// Fixtures: `tests/fixtures/by-kind/invalid_property_fetch/bad_fetch.phpt`.
225    InvalidPropertyFetch { ty: String },
226    /// Emitted by `mir-analyzer/src/call/method.rs`.
227    /// Fixtures: `tests/fixtures/by-kind/invalid_method_call/`.
228    InvalidMethodCall { method: String, ty: String },
229    /// Emitted by `mir-analyzer/src/expr/mod.rs` for an object used as `$obj->{$name}`.
230    /// Fixtures: `tests/fixtures/by-kind/invalid_member_name/`.
231    InvalidMemberName { member: String, ty: String },
232    /// Emitted by `mir-analyzer/src/diagnostics.rs` for `resource` used as a native type.
233    /// Fixtures: `tests/fixtures/by-kind/native_resource_type/`.
234    NativeResourceType { class: String },
235    /// Emitted by `mir-analyzer/src/call/args.rs` for `f(...$x)` with a scalar or `null`.
236    /// Fixtures: `tests/fixtures/by-kind/invalid_unpack/`.
237    InvalidUnpack {
238        /// Empty before PHP 8.4, which does not name the type.
239        ty: String,
240    },
241    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
242    /// Fixtures: `tests/fixtures/by-kind/invalid_array_access/`.
243    InvalidArrayAccess { ty: String },
244    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
245    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_array_access/`.
246    PossiblyInvalidArrayAccess { ty: String },
247    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
248    /// Fixtures: `tests/fixtures/by-kind/invalid_array_assignment/`.
249    InvalidArrayAssignment { ty: String },
250    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
251    /// Fixtures: `tests/fixtures/by-kind/invalid_property_assignment/`.
252    InvalidPropertyAssignment {
253        property: String,
254        expected: String,
255        actual: String,
256    },
257    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
258    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_property_assignment/`.
259    PossiblyNullPropertyAssignmentValue {
260        property: String,
261        expected: String,
262        actual: String,
263    },
264    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
265    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_property_assignment/`.
266    PossiblyFalsePropertyAssignmentValue {
267        property: String,
268        expected: String,
269        actual: String,
270    },
271    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
272    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_property_assignment/`.
273    PossiblyInvalidPropertyAssignmentValue {
274        property: String,
275        expected: String,
276        actual: String,
277    },
278    /// Emitted by `mir-analyzer/src/expr/casts.rs`.
279    /// Fixtures: `tests/fixtures/by-kind/invalid_cast/`.
280    InvalidCast { from: String, to: String },
281    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
282    /// Fixtures: `tests/fixtures/by-kind/undefined_method/static_invocation*.phpt`.
283    InvalidStaticInvocation { class: String, method: String },
284    /// Emitted by `mir-analyzer/src/expr/binary.rs` and `unary.rs` for operations on
285    /// non-numeric or non-bitwise-compatible operands.
286    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
287    InvalidOperand {
288        op: String,
289        left: String,
290        right: String,
291    },
292    /// Emitted when a union-typed operand has some non-numeric/non-stringifiable members.
293    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
294    PossiblyInvalidOperand {
295        op: String,
296        left: String,
297        right: String,
298    },
299    /// Emitted when a divisor operand could be null (potential division by zero).
300    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
301    PossiblyNullOperand { op: String, ty: String },
302    /// Emitted when a divisor operand is DEFINITELY the literal `0` — an
303    /// unconditional runtime `DivisionByZeroError`.
304    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
305    DivisionByZero { op: String },
306    /// Emitted when `yield from` is used with a non-iterable object (no Traversable).
307    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
308    RawObjectIteration { ty: String },
309    /// Emitted when `yield from` might be used with a non-iterable object.
310    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
311    PossiblyRawObjectIteration { ty: String },
312    /// `foreach` over a generator whose send type does not accept the `null` each step sends.
313    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs`.
314    /// Fixtures: `tests/fixtures/by-kind/invalid_generator_iteration/`.
315    InvalidGeneratorIteration { ty: String, send: String },
316    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
317    /// Fixtures: `tests/fixtures/by-kind/mismatching_docblock_return_type/`.
318    MismatchingDocblockReturnType { declared: String, inferred: String },
319    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
320    /// Fixtures: `tests/fixtures/by-kind/mismatching_docblock_param_type/`.
321    MismatchingDocblockParamType {
322        param: String,
323        declared: String,
324        inferred: String,
325    },
326    /// Emitted by `@mir-check EXPR is TYPE` docblock directives (test-only —
327    /// never raised by real analysis of user code). `var` is the checked
328    /// expression's source text verbatim (e.g. `$x`, `$h->status`,
329    /// `self::$prop`), already including any `$` it needs.
330    /// Fixtures: `tests/fixtures/by-kind/type_check_mismatch/`.
331    TypeCheckMismatch {
332        var: String,
333        expected: String,
334        actual: String,
335    },
336
337    /// Emitted by `@trace $var` docblock annotation. Shows inferred type.
338    /// Fixtures: `tests/fixtures/by-kind/trace/`.
339    Trace { variable: String, type_info: String },
340
341    // --- Array issues -------------------------------------------------------
342    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
343    /// Fixtures: `tests/fixtures/by-kind/invalid_array_offset/`.
344    InvalidArrayOffset { expected: String, actual: String },
345    /// Emitted by `mir-analyzer/src/expr/arrays.rs` when a TKeyedArray is accessed with
346    /// a literal key that does not exist in the shape.
347    /// Fixtures: `tests/fixtures/by-kind/invalid_array_offset/`.
348    NonExistentArrayOffset { key: String },
349    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
350    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_array_offset/`.
351    PossiblyInvalidArrayOffset { expected: String, actual: String },
352    /// Emitted by `mir-analyzer/src/expr/arrays.rs` when an array literal repeats
353    /// the same key — the earlier entry is silently overwritten at runtime,
354    /// almost always a copy-paste mistake.
355    /// Fixtures: `tests/fixtures/by-kind/duplicate_array_key/`.
356    DuplicateArrayKey { key: String },
357
358    // --- Redundancy ---------------------------------------------------------
359    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
360    /// Fixtures: `tests/fixtures/by-kind/redundant_condition/`.
361    RedundantCondition {
362        always_true: bool,
363        /// The branch that can never run (`then branch`, `else branch`, `loop body`); `None` when there is no such branch to name.
364        unreachable: Option<String>,
365    },
366    /// Emitted by `mir-analyzer/src/expr/casts.rs`.
367    /// Fixtures: `tests/fixtures/by-kind/redundant_cast/`.
368    RedundantCast { from: String, to: String },
369    /// Emitted by `mir-analyzer/src/stmt/mod.rs`.
370    /// Fixtures: `tests/fixtures/by-kind/unnecessary_var_annotation/`.
371    UnnecessaryVarAnnotation { var: String },
372    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
373    /// Fixtures: `tests/fixtures/by-kind/type_does_not_contain_type/`.
374    TypeDoesNotContainType { left: String, right: String },
375    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
376    /// Fixtures: `tests/fixtures/by-kind/paradoxical_condition/`.
377    ParadoxicalCondition { value: String },
378    /// A docblock-declared type makes a subsequent assertion or comparison
379    /// impossible (e.g. `assert($a < 4)` on a `@param int<5, max> $a`).
380    /// Emitted by `mir-analyzer/src/narrowing.rs`.
381    /// Fixtures: `tests/fixtures/by-kind/docblock_type_contradiction/`.
382    DocblockTypeContradiction { expr: String, declared: String },
383    /// A `===` or `!==` comparison between two types that can never be strictly
384    /// equal — e.g. `$int === $string` or `$obj !== null` where `$obj` is a
385    /// non-nullable typed value.
386    /// Emitted by `mir-analyzer/src/expr/binary.rs`.
387    /// Fixtures: `tests/fixtures/by-kind/impossible_identical_comparison/`.
388    ImpossibleIdenticalComparison {
389        op: String,
390        left: String,
391        right: String,
392    },
393    /// A `==` or `!=` comparison between two types that can never be loosely
394    /// equal in PHP — e.g. `$obj == null`, `$arr == "foo"`, or a non-empty
395    /// array `== false`.  PHP's type-juggling rules make these always false (or
396    /// always true for `!=`), which almost certainly indicates a logic bug.
397    /// Emitted by `mir-analyzer/src/expr/binary.rs`.
398    /// Fixtures: `tests/fixtures/by-kind/impossible_loose_comparison/`.
399    ImpossibleLooseComparison {
400        op: String,
401        left: String,
402        right: String,
403    },
404    /// A `switch`/`match` arm that can never be reached given the subject's
405    /// inferred type — most often a `gettype()` arm tested against a string
406    /// that `gettype()` never returns (e.g. `case "int"` — it returns
407    /// `"integer"`).
408    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
409    /// Fixtures: `tests/fixtures/by-kind/unevaluated_code/`.
410    UnevaluatedCode { reason: String },
411
412    // --- Dead code ----------------------------------------------------------
413    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
414    /// Fixtures: `tests/fixtures/by-kind/unused_variable/`.
415    UnusedVariable { name: String },
416    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
417    /// Fixtures: `tests/fixtures/by-kind/unused_param/`.
418    UnusedParam { name: String },
419    /// Emitted by `mir-analyzer/src/stmt/mod.rs`.
420    /// Fixtures: `tests/fixtures/by-kind/unreachable_code/`.
421    UnreachableCode,
422    /// Emitted by `mir-analyzer/src/expr/conditional.rs`.
423    /// Fixtures: `tests/fixtures/by-kind/unreachable_code/`.
424    UnhandledMatchCondition { detail: String },
425    /// Emitted by `mir-analyzer/src/dead_code.rs`.
426    /// Fixtures: `tests/fixtures/by-kind/unused_method/`.
427    UnusedMethod { class: String, method: String },
428    /// Emitted by `mir-analyzer/src/dead_code.rs`.
429    /// Fixtures: `tests/fixtures/by-kind/unused_property/`.
430    UnusedProperty { class: String, property: String },
431    /// Emitted by `mir-analyzer/src/dead_code.rs`.
432    /// Fixtures: `tests/fixtures/by-kind/unused_function/`.
433    UnusedFunction { name: String },
434    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
435    /// Fixtures: `tests/fixtures/by-kind/unused_foreach_value/`.
436    UnusedForeachValue { name: String },
437    /// Emitted by `mir-analyzer/src/dead_code.rs`.
438    /// Fixtures: `tests/fixtures/by-kind/unused_class/`.
439    UnusedClass { class: String },
440    /// Emitted by `mir-analyzer/src/dead_code.rs`.
441    /// Fixtures: `tests/fixtures/by-kind/unused_constant/`.
442    UnusedConstant { class: String, constant: String },
443    /// Emitted by `mir-analyzer/src/batch/mod.rs` when a `@psalm-suppress` /
444    /// `@mir-suppress` / `@suppress` annotation does not match any actual issue.
445    /// Fixtures: `tests/fixtures/by-kind/unused_suppress/`.
446    UnusedSuppress { kind: String },
447
448    /// Emitted by `mir-analyzer/src/call/args/types.rs`.
449    /// Fixtures: `tests/fixtures/by-kind/argument_type_coercion/`.
450    ArgumentTypeCoercion {
451        param: String,
452        fn_name: String,
453        expected: String,
454        actual: String,
455    },
456
457    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
458    /// Fixtures: `tests/fixtures/by-kind/property_type_coercion/`.
459    PropertyTypeCoercion {
460        property: String,
461        expected: String,
462        actual: String,
463    },
464
465    // --- Purity -------------------------------------------------------------
466    /// Emitted when a @pure function assigns to a parameter's property.
467    ImpurePropertyAssignment { property: String },
468    /// Emitted when a @pure function calls an impure method on a parameter.
469    ImpureMethodCall { method: String },
470    /// Emitted when a @pure function uses a global variable.
471    ImpureGlobalVariable { variable: String },
472    /// Emitted when a @pure function uses a static variable.
473    ImpureStaticVariable { variable: String },
474    /// Emitted when a @pure function assigns to a class static property
475    /// (`self::$x = ...`, `Foo::$x = ...`) — static properties are shared
476    /// external state, same as a global variable.
477    ImpureStaticPropertyAssignment { class: String, property: String },
478    /// Emitted when a @pure function reads a class static property
479    /// (`self::$x`, `Foo::$x`) — reading shared external state is just as
480    /// non-deterministic across calls as writing it, mirroring
481    /// `ImpureGlobalVariable`'s treatment of a superglobal read.
482    ImpureStaticPropertyAccess { class: String, property: String },
483    /// Emitted when a @pure function assigns to one of its own by-reference
484    /// parameters (`function f(int &$x) { $x = 1; }`) — this mutates
485    /// caller-visible state through the reference, a side effect @pure
486    /// forbids just as much as a global/static-variable write.
487    ImpureByRefAssignment { variable: String },
488    /// Emitted by `mir-analyzer/src/call/function.rs` when a `@pure` function calls a
489    /// non-pure named function.
490    /// Fixtures: `tests/fixtures/by-kind/impure_function_call/`.
491    ImpureFunctionCall { fn_name: String },
492    /// Emitted when a non-constructor method of a `@psalm-immutable` class assigns to a
493    /// `$this` property, or when ANY code writes to a property of an object whose class is
494    /// `@psalm-immutable` (`receiver` is the rendered receiver expression — `$this` for the
495    /// former, the actual receiver's source text, e.g. `$b`, for the latter).
496    /// Fixtures: `tests/fixtures/by-kind/immutable_property_modification/`.
497    ImmutablePropertyModification { receiver: String, property: String },
498
499    // --- Readonly -----------------------------------------------------------
500    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
501    /// Fixtures: `tests/fixtures/by-kind/readonly_property_assignment/`.
502    ReadonlyPropertyAssignment {
503        class: String,
504        property: String,
505        unset: bool,
506    },
507    /// A second write to a readonly property in a scope where writes are
508    /// otherwise allowed (the declaring constructor, or any method for a
509    /// native `readonly` property) — PHP throws `Error: Cannot modify
510    /// readonly property ... once initialized` on the second write.
511    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
512    /// Fixtures: `tests/fixtures/by-kind/readonly_property_already_initialized/`.
513    ReadonlyPropertyAlreadyInitialized { class: String, property: String },
514
515    // --- Inheritance --------------------------------------------------------
516    /// Emitted by `mir-analyzer/src/class/mod.rs`.
517    /// Fixtures: `tests/fixtures/by-kind/unimplemented_abstract_method/`.
518    UnimplementedAbstractMethod { class: String, method: String },
519    /// Emitted by `mir-analyzer/src/class/mod.rs`.
520    /// Fixtures: `tests/fixtures/by-kind/unimplemented_interface_method/`.
521    UnimplementedInterfaceMethod {
522        class: String,
523        interface: String,
524        method: String,
525    },
526    /// Emitted by `mir-analyzer/src/class/mod.rs`.
527    /// Fixtures: `tests/fixtures/by-kind/method_signature_mismatch/`.
528    MethodSignatureMismatch {
529        class: String,
530        method: String,
531        detail: String,
532    },
533    /// Emitted by `mir-analyzer/src/class/mod.rs`.
534    /// Fixtures: `tests/fixtures/by-kind/overridden_method_access/`.
535    OverriddenMethodAccess {
536        class: String,
537        method: String,
538        parent: String,
539        visibility: String,
540    },
541    /// Emitted by `mir-analyzer/src/class/mod.rs`.
542    /// Fixtures: `tests/fixtures/by-kind/overridden_property_access/`.
543    OverriddenPropertyAccess {
544        class: String,
545        property: String,
546        parent: String,
547        visibility: String,
548    },
549    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
550    /// Fixtures: `tests/fixtures/by-kind/property_type_redeclaration_mismatch/`.
551    PropertyTypeRedeclarationMismatch {
552        class: String,
553        property: String,
554        parent: String,
555        expected: String,
556        /// The parent is a get-only hook, so a subtype is enough.
557        covariant: bool,
558        /// PHP before 8.5 words an untyped parent as "must not be defined".
559        before_php85: bool,
560    },
561    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
562    /// Fixtures: `tests/fixtures/by-kind/non_invariant_docblock_property_type/`.
563    NonInvariantDocblockPropertyType {
564        class: String,
565        property: String,
566        parent: String,
567        expected: String,
568        actual: String,
569    },
570    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
571    /// Fixtures: `tests/fixtures/by-kind/readonly_property_redeclaration_mismatch/`.
572    ReadonlyPropertyRedeclarationMismatch {
573        parent_class: String,
574        class: String,
575        property: String,
576        /// True when the parent's property is readonly and the child drops it;
577        /// false when the parent's property is non-readonly and the child adds it.
578        parent_readonly: bool,
579    },
580    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
581    /// Fixtures: `tests/fixtures/by-kind/static_property_redeclaration_mismatch/`.
582    StaticPropertyRedeclarationMismatch {
583        parent_class: String,
584        class: String,
585        property: String,
586        /// True when the parent's property is static and the child redeclares it as
587        /// instance; false when the parent's is instance and the child redeclares it static.
588        parent_static: bool,
589    },
590    /// A `readonly class` extends a non-readonly parent, or vice versa — PHP
591    /// requires both sides of an extends relationship to agree on the
592    /// whole-class `readonly` modifier.
593    /// Emitted by `mir-analyzer/src/class/mod.rs`.
594    /// Fixtures: `tests/fixtures/by-kind/readonly_class_extends_mismatch/`.
595    ReadonlyClassExtendsMismatch {
596        parent: String,
597        child: String,
598        /// True when the parent is readonly and the child isn't; false when
599        /// the child is readonly and the parent isn't.
600        parent_readonly: bool,
601    },
602    /// A native `readonly` property declaration carries a default value — a
603    /// PHP fatal. (The sibling untyped-readonly-property fatal is already
604    /// caught by the parser itself as a `CompileError`.)
605    /// Emitted by `mir-analyzer/src/collector/class.rs`.
606    /// Fixtures: `tests/fixtures/by-kind/invalid_readonly_property_declaration/`.
607    InvalidReadonlyPropertyDeclaration { class: String, property: String },
608    /// Emitted by `mir-analyzer/src/collector/enum.rs`.
609    /// Fixtures: `tests/fixtures/by-kind/backed_enum_case_type_mismatch/`.
610    BackedEnumCaseTypeMismatch {
611        enum_name: String,
612        case_name: String,
613        expected: String,
614        actual: String,
615    },
616    /// Two cases of a backed enum have the same value — a PHP fatal.
617    /// Emitted by `mir-analyzer/src/collector/enum.rs`.
618    /// Fixtures: `tests/fixtures/by-kind/duplicate_enum_case_value/`.
619    DuplicateEnumCaseValue {
620        enum_name: String,
621        first_case: String,
622        case_name: String,
623    },
624    /// Emitted by `mir-analyzer/src/call/method.rs`.
625    /// Fixtures: `tests/fixtures/by-kind/undefined_method/direct_constructor_call*.phpt`.
626    DirectConstructorCall { class: String },
627    /// Emitted by `mir-analyzer/src/class/mod.rs`.
628    /// Fixtures: `tests/fixtures/by-kind/invalid_extend_class/`.
629    InvalidExtendClass {
630        parent: String,
631        child: String,
632        /// Set when the parent is not final but restricts its subtypes (`@phpstan-sealed`, `@phpstan-require-extends`).
633        #[serde(default)]
634        reason: Option<String>,
635    },
636    /// Emitted by `mir-analyzer/src/class/mod.rs`.
637    /// Fixtures: `tests/fixtures/by-kind/final_method_overridden/`.
638    FinalMethodOverridden {
639        class: String,
640        method: String,
641        parent: String,
642    },
643    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
644    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/`.
645    AbstractInstantiation { class: String },
646    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
647    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/prevent_abstract_method_call.phpt`.
648    AbstractMethodCall { class: String, method: String },
649    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
650    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/interface_instantiation.phpt`.
651    InterfaceInstantiation { class: String },
652    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
653    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/enum_instantiation.phpt`.
654    EnumInstantiation { class: String },
655    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
656    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/trait_instantiation.phpt`.
657    TraitInstantiation { class: String },
658    /// A write creates an undeclared property on an enum or readonly class, which throws.
659    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
660    /// Fixtures: `tests/fixtures/by-kind/dynamic_property_creation/`.
661    InvalidDynamicProperty { class: String, property: String },
662    /// Emitted by `mir-analyzer/src/class/overrides.rs` when `#[Override]` is declared
663    /// but no overridable parent method (or, from PHP 8.5, property) exists.
664    /// `member` is `name()` for a method, `$name` for a property.
665    /// Fixtures: `tests/fixtures/by-kind/invalid_override/`.
666    InvalidOverride { class: String, member: String },
667
668    // --- Security (taint) ---------------------------------------------------
669    /// Emitted for a `@taint-sink` kind with no dedicated issue.
670    /// Fixtures: `tests/fixtures/by-kind/tainted_input/`.
671    TaintedInput { sink: String },
672    /// Emitted by `mir-analyzer/src/call/function.rs`.
673    /// Fixtures: `tests/fixtures/by-kind/tainted_html/`.
674    TaintedHtml,
675    /// Emitted by `mir-analyzer/src/call/function.rs`.
676    /// Fixtures: `tests/fixtures/by-kind/tainted_sql/`.
677    TaintedSql,
678    /// Emitted by `mir-analyzer/src/call/function.rs`.
679    /// Fixtures: `tests/fixtures/by-kind/tainted_shell/`.
680    TaintedShell,
681    /// Emitted by `mir-analyzer/src/call/method.rs` when a tainted value reaches a
682    /// `@taint-sink llm_prompt` annotated parameter.
683    /// Fixtures: `tests/fixtures/by-kind/tainted_llm_prompt/`.
684    TaintedLlmPrompt,
685    /// Emitted by `mir-analyzer/src/call/function.rs`.
686    /// Fixtures: `tests/fixtures/by-kind/tainted_header/`.
687    TaintedHeader,
688    /// Emitted by `mir-analyzer/src/call/function.rs`.
689    /// Fixtures: `tests/fixtures/by-kind/tainted_cookie/`.
690    TaintedCookie,
691    /// Emitted by `mir-analyzer/src/call/function.rs`.
692    /// Fixtures: `tests/fixtures/by-kind/tainted_ssrf/`.
693    TaintedSsrf,
694    /// Emitted by `mir-analyzer/src/call/function.rs`.
695    /// Fixtures: `tests/fixtures/by-kind/tainted_ldap/`.
696    TaintedLdap,
697    /// Emitted by `mir-analyzer/src/call/method.rs`.
698    /// Fixtures: `tests/fixtures/by-kind/tainted_xpath/`.
699    TaintedXpath,
700    /// Emitted by `mir-analyzer/src/call/function.rs`.
701    /// Fixtures: `tests/fixtures/by-kind/tainted_callable/`.
702    TaintedCallable,
703    /// Emitted by `mir-analyzer/src/call/function.rs` for filesystem path arguments.
704    /// Fixtures: `tests/fixtures/by-kind/tainted_file/`.
705    TaintedFile,
706    /// Emitted by `mir-analyzer/src/expr/mod.rs` for `include`/`require` paths.
707    /// Fixtures: `tests/fixtures/by-kind/tainted_include/`.
708    TaintedInclude,
709    /// Emitted by `mir-analyzer/src/expr/mod.rs` for `eval()` code.
710    /// Fixtures: `tests/fixtures/by-kind/tainted_eval/`.
711    TaintedEval,
712    /// Emitted by `mir-analyzer/src/call/function.rs` for `unserialize()` payloads.
713    /// Fixtures: `tests/fixtures/by-kind/tainted_unserialize/`.
714    TaintedUnserialize,
715
716    /// `password_hash()` is called with options or input that weaken it.
717    /// Emitted by `mir-analyzer/src/security.rs`.
718    /// Fixtures: `tests/fixtures/by-kind/insecure_password_hash/`.
719    InsecurePasswordHash { reason: String },
720
721    /// `openssl_encrypt()` or `openssl_decrypt()` is called with a broken cipher, a hardcoded key or IV, or an AEAD cipher without its tag.
722    /// Emitted by `mir-analyzer/src/security.rs`.
723    /// Fixtures: `tests/fixtures/by-kind/weak_cryptography/`.
724    WeakCryptography { reason: String },
725
726    /// Code turns off a session protection that PHP's secure defaults rely on, or takes the session ID from the request.
727    /// Emitted by `mir-analyzer/src/security.rs`.
728    /// Fixtures: `tests/fixtures/by-kind/insecure_session_config/`.
729    InsecureSessionConfig { reason: String },
730
731    /// A session ID or a security token comes from a guessable random generator.
732    /// Emitted by `mir-analyzer/src/security.rs`.
733    /// Fixtures: `tests/fixtures/by-kind/insecure_randomness/`.
734    InsecureRandomness { context: String },
735
736    /// User-controlled XML is parsed with flags that load external entities or lift libxml's size limits.
737    /// Emitted by `mir-analyzer/src/call/function.rs`.
738    /// Fixtures: `tests/fixtures/by-kind/tainted_xml/`.
739    TaintedXml,
740
741    /// `unserialize()` of data that isn't a literal, without an `allowed_classes` restriction.
742    /// Emitted by `mir-analyzer/src/security.rs`.
743    /// Fixtures: `tests/fixtures/by-kind/unsafe_unserialize/`.
744    UnsafeUnserialize,
745
746    /// A magic method that runs on unserialized objects passes one of its properties to a dangerous call.
747    /// Emitted by `mir-analyzer/src/call/function.rs`.
748    /// Fixtures: `tests/fixtures/by-kind/unserialize_gadget/`.
749    UnserializeGadget { class: String, method: String },
750
751    /// A parameter named like a password, secret, token or API key lacks `#[\SensitiveParameter]`.
752    /// Emitted by `mir-analyzer/src/attributes.rs`.
753    /// Fixtures: `tests/fixtures/by-kind/missing_sensitive_parameter/`.
754    MissingSensitiveParameter { param: String },
755
756    /// User input chooses which property, variable, session key or named argument a write sets.
757    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
758    /// Fixtures: `tests/fixtures/by-kind/tainted_mass_assignment/`.
759    TaintedMassAssignment { target: String },
760
761    /// User input becomes an argument of a program run without a shell and can pass it an option.
762    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
763    /// Fixtures: `tests/fixtures/by-kind/tainted_command_argument/`.
764    TaintedCommandArgument,
765
766    /// An `escapeshellarg()` result is wrapped in another pair of quotes in a shell command.
767    /// Emitted by `mir-analyzer/src/security.rs`.
768    /// Fixtures: `tests/fixtures/by-kind/quoted_shell_escape/`.
769    QuotedShellEscape,
770
771    /// An uploaded file is saved under the name the client sent, with no check of its extension or content.
772    /// Emitted by `mir-analyzer/src/security.rs`.
773    /// Fixtures: `tests/fixtures/by-kind/unrestricted_file_upload/`.
774    UnrestrictedFileUpload,
775
776    /// An email body or outgoing request URL contains a value built from the `Host` header the client sent.
777    /// Emitted by `mir-analyzer/src/security.rs`.
778    /// Fixtures: `tests/fixtures/by-kind/host_header_injection/`.
779    HostHeaderInjection { target: String },
780
781    /// User input reaches a MongoDB `$where` clause, or may be an array in a MongoDB filter.
782    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
783    /// Fixtures: `tests/fixtures/by-kind/tainted_no_sql/`.
784    TaintedNoSql,
785
786    /// User input is compiled as a regular expression: catastrophic backtracking or a changed match.
787    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
788    /// Fixtures: `tests/fixtures/by-kind/tainted_regex/`.
789    TaintedRegex,
790
791    /// User input is written to the process environment, where it can switch the app's mode or inject `LD_PRELOAD`.
792    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
793    /// Fixtures: `tests/fixtures/by-kind/tainted_environment/`.
794    TaintedEnvironment,
795
796    /// Request data is bound into a `LIKE` pattern without escaping its `%` and `_` wildcards.
797    /// Emitted by `mir-analyzer/src/security.rs`.
798    /// Fixtures: `tests/fixtures/by-kind/unescaped_like_wildcard/`.
799    UnescapedLikeWildcard,
800
801    /// A quote-escaping function's result is placed in SQL text outside quotes, where it escapes nothing.
802    /// Emitted by `mir-analyzer/src/security.rs`.
803    /// Fixtures: `tests/fixtures/by-kind/unquoted_sql_escape/`.
804    UnquotedSqlEscape,
805
806    /// An HTML-escaping function's result is placed where it doesn't stop markup or script:
807    /// an attribute whose quotes it leaves raw, an unquoted attribute, or an event handler.
808    /// Emitted by `mir-analyzer/src/security.rs`.
809    /// Fixtures: `tests/fixtures/by-kind/insufficient_html_escape/`.
810    InsufficientHtmlEscape,
811
812    /// A WordPress AJAX, admin-post or REST handler changes site state without a capability
813    /// or nonce check, or a Laravel or Symfony action changes a record the URL selects without
814    /// an authorization check. Opt-in (`--audit access-control`).
815    /// Emitted by `mir-analyzer/src/frameworks/wordpress/access_control.rs` and
816    /// `mir-analyzer/src/frameworks/controller_access.rs`.
817    /// Fixtures: `tests/fixtures/by-kind/missing_authorization_check/`.
818    MissingAuthorizationCheck {
819        handler: String,
820        missing: String,
821        who: String,
822    },
823
824    /// Tainted data is passed to a call whose callee can't be resolved, so no sink or callee
825    /// summary is checked behind it. Opt-in (`--audit taint-coverage`).
826    /// Emitted by `mir-analyzer/src/taint/untraced.rs`.
827    /// Fixtures: `tests/fixtures/by-kind/untraced_taint/`.
828    UntracedTaint { call: String, reason: String },
829
830    /// User input is written as a CSV field that a spreadsheet may run as a formula.
831    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
832    /// Fixtures: `tests/fixtures/by-kind/tainted_csv/`.
833    TaintedCsv,
834
835    /// User input reaches a log message, where a line break forges log entries.
836    /// Emitted by `mir-analyzer/src/taint/sinks.rs`.
837    /// Fixtures: `tests/fixtures/by-kind/tainted_log/`.
838    TaintedLog,
839
840    /// A size, count or duration from the request reaches a builtin whose cost grows with it.
841    /// Emitted by `mir-analyzer/src/security.rs`.
842    /// Fixtures: `tests/fixtures/by-kind/resource_exhaustion/`.
843    ResourceExhaustion { function: String },
844
845    /// A condition decides on a client IP taken from `X-Forwarded-For`, `Client-IP` or `X-Real-IP`.
846    /// Emitted by `mir-analyzer/src/security.rs`.
847    /// Fixtures: `tests/fixtures/by-kind/spoofable_client_ip/`.
848    SpoofableClientIp,
849
850    /// A `header('Location: ...')` redirect is followed by output on a path with no `exit`.
851    /// Emitted by `mir-analyzer/src/call/function.rs`.
852    /// Fixtures: `tests/fixtures/by-kind/code_after_redirect/`.
853    CodeAfterRedirect,
854
855    /// A security check treats a function's error result as success.
856    /// Emitted by `mir-analyzer/src/security.rs`.
857    /// Fixtures: `tests/fixtures/by-kind/insecure_check_result/`.
858    InsecureCheckResult { reason: String },
859
860    /// `ldap_bind()` takes a password from the request that isn't checked to be non-empty.
861    /// Emitted by `mir-analyzer/src/security.rs`.
862    /// Fixtures: `tests/fixtures/by-kind/ldap_anonymous_bind/`.
863    LdapAnonymousBind,
864
865    /// `chmod()` or `umask()` with a literal value leaves files writable by every user.
866    /// Emitted by `mir-analyzer/src/security.rs`.
867    /// Fixtures: `tests/fixtures/by-kind/insecure_file_permissions/`.
868    InsecureFilePermissions { reason: String },
869
870    /// A password, key or token is written in the source code.
871    /// Emitted by `mir-analyzer/src/security.rs`.
872    /// Fixtures: `tests/fixtures/by-kind/hardcoded_credential/`.
873    HardcodedCredential { what: String },
874
875    /// `Access-Control-Allow-Origin` echoes the request's `Origin` header unchecked while credentials are allowed.
876    /// Emitted by `mir-analyzer/src/security.rs`.
877    /// Fixtures: `tests/fixtures/by-kind/insecure_cors/`.
878    InsecureCors,
879
880    /// `mt_srand()` or `srand()` gets a literal or clock-based seed.
881    /// Emitted by `mir-analyzer/src/security.rs`.
882    /// Fixtures: `tests/fixtures/by-kind/predictable_seed/`.
883    PredictableSeed { function: String },
884
885    /// Code passed to `eval()` or a function called by name comes out of a decoder such as `base64_decode()`.
886    /// Emitted by `mir-analyzer/src/security.rs`.
887    /// Fixtures: `tests/fixtures/by-kind/obfuscated_code/`.
888    ObfuscatedCode,
889
890    /// A curl or stream context option turns off checking the server's TLS certificate or host name.
891    /// Emitted by `mir-analyzer/src/security.rs`.
892    /// Fixtures: `tests/fixtures/by-kind/insecure_tls/`.
893    InsecureTls { reason: String },
894
895    /// A `hash_hmac()` digest or a stored secret is compared with `==` or `===` instead of `hash_equals()`.
896    /// Emitted by `mir-analyzer/src/security.rs`.
897    /// Fixtures: `tests/fixtures/by-kind/timing_unsafe_comparison/`.
898    TimingUnsafeComparison { what: String },
899
900    // --- Generics -----------------------------------------------------------
901    /// Emitted by `mir-analyzer/src/call/function.rs`.
902    /// Fixtures: `tests/fixtures/by-kind/invalid_template_param/`.
903    InvalidTemplateParam {
904        name: String,
905        expected_bound: String,
906        actual: String,
907    },
908    /// Emitted by `mir-analyzer/src/call/method.rs`.
909    /// Fixtures: `tests/fixtures/by-kind/shadowed_template_param/`.
910    ShadowedTemplateParam { name: String },
911    /// A method annotated `@if-this-is X<Y>` was called on a receiver whose
912    /// type does not satisfy that constraint.
913    /// Emitted by `mir-analyzer/src/call/method.rs`.
914    /// Fixtures: `tests/fixtures/by-kind/if_this_is_mismatch/`.
915    IfThisIsMismatch {
916        class: String,
917        method: String,
918        expected: String,
919        actual: String,
920    },
921
922    // --- Other --------------------------------------------------------------
923    /// Emitted by `mir-analyzer/src/call/function.rs`.
924    /// Fixtures: `tests/fixtures/by-kind/deprecated_call/`.
925    DeprecatedCall {
926        name: String,
927        message: Option<Arc<str>>,
928    },
929    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
930    /// Fixtures: `tests/fixtures/by-kind/undefined_property/deprecated_property_*.phpt`.
931    DeprecatedProperty {
932        class: String,
933        property: String,
934        message: Option<Arc<str>>,
935    },
936    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
937    /// Fixtures: `tests/fixtures/by-kind/deprecated_call/deprecated_class_const_fetch*.phpt`.
938    DeprecatedConstant {
939        class: String,
940        constant: String,
941        message: Option<Arc<str>>,
942    },
943    /// An optional parameter before a required one, which PHP deprecates from 8.0; the
944    /// message follows the target version.
945    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
946    /// Fixtures: `tests/fixtures/by-kind/optional_parameter_before_required/`.
947    OptionalParameterBeforeRequired { message: String },
948    /// A typed parameter made nullable only by its `null` default (`int $a = null`), which
949    /// PHP deprecates from 8.4.
950    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
951    /// Fixtures: `tests/fixtures/by-kind/implicitly_nullable_parameter/`.
952    ImplicitlyNullableParameter { message: String },
953    /// A declaration or statement form PHP deprecates at compile time, with PHP's message.
954    /// Emitted by `mir-analyzer/src/body_analysis/deprecated_syntax.rs`.
955    /// Fixtures: `tests/fixtures/by-kind/deprecated_syntax/`.
956    DeprecatedSyntax { message: String },
957    /// A write creates an undeclared property, which PHP deprecates from 8.2.
958    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
959    /// Fixtures: `tests/fixtures/by-kind/dynamic_property_creation/`.
960    DynamicPropertyCreation { class: String, property: String },
961    /// Emitted by `mir-analyzer/src/class/mod.rs`.
962    /// Fixtures: `tests/fixtures/by-kind/deprecated_interface/`.
963    DeprecatedInterface {
964        name: String,
965        message: Option<Arc<str>>,
966    },
967    /// Emitted by `mir-analyzer/src/class/mod.rs`.
968    /// Fixtures: `tests/fixtures/by-kind/deprecated_trait/`.
969    DeprecatedTrait {
970        name: String,
971        message: Option<Arc<str>>,
972    },
973    /// Emitted by `mir-analyzer/src/call/method.rs`.
974    /// Fixtures: `tests/fixtures/by-kind/deprecated_method_call/`.
975    DeprecatedMethodCall {
976        class: String,
977        method: String,
978        message: Option<Arc<str>>,
979    },
980    /// Emitted by `mir-analyzer/src/call/method.rs`.
981    /// Fixtures: `tests/fixtures/by-kind/deprecated_method/`.
982    DeprecatedMethod {
983        class: String,
984        method: String,
985        message: Option<Arc<str>>,
986    },
987    /// Emitted by `mir-analyzer/src/class/mod.rs`.
988    /// Fixtures: `tests/fixtures/by-kind/deprecated_class/`.
989    DeprecatedClass {
990        name: String,
991        message: Option<Arc<str>>,
992    },
993    /// Emitted by `mir-analyzer/src/call/method.rs`.
994    /// Fixtures: `tests/fixtures/by-kind/internal_method/`.
995    InternalMethod { class: String, method: String },
996    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
997    /// Fixtures: `tests/fixtures/by-kind/missing_return_type/`.
998    MissingReturnType { fn_name: String },
999    /// Emitted by `mir-analyzer/src/expr/closures.rs`.
1000    /// Fixtures: `tests/fixtures/by-kind/missing_closure_return_type/`.
1001    MissingClosureReturnType,
1002    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1003    /// Fixtures: `tests/fixtures/by-kind/missing_param_type/`.
1004    MissingParamType { fn_name: String, param: String },
1005    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1006    /// Fixtures: `tests/fixtures/by-kind/missing_param_type/` (property variants).
1007    MissingPropertyType { class: String, property: String },
1008    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
1009    /// Fixtures: `tests/fixtures/by-kind/invalid_throw/`.
1010    InvalidThrow { ty: String },
1011    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs`.
1012    /// Fixtures: `tests/fixtures/by-kind/invalid_catch/`.
1013    InvalidCatch { ty: String },
1014    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` when a `catch` type is a
1015    /// subtype of (or identical to) a type already caught by an earlier `catch`
1016    /// clause on the same `try` — the later block can never run.
1017    /// Fixtures: `tests/fixtures/by-kind/invalid_catch/`.
1018    UnreachableCatch { ty: String, shadowed_by: String },
1019    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
1020    /// Fixtures: `tests/fixtures/by-kind/missing_throws_docblock/`.
1021    MissingThrowsDocblock { class: String },
1022    /// `@throws` declares an exception class that does not exist in the
1023    /// workspace — the class the docblock promises to raise never was.
1024    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1025    /// Fixtures: `tests/fixtures/by-kind/undefined_throws_docblock/`.
1026    UndefinedThrowsDocblock { name: String },
1027    /// Emitted by `mir-analyzer/src/stmt/expressions.rs`.
1028    /// Fixtures: `tests/fixtures/by-kind/implicit_to_string_cast/`.
1029    ImplicitToStringCast { class: String },
1030    /// Emitted by `mir-analyzer/src/call/args.rs`.
1031    /// Fixtures: `tests/fixtures/by-kind/implicit_float_to_int_cast/`.
1032    ImplicitFloatToIntCast { from: String },
1033    /// Emitted by `mir-analyzer/src/parser/mod.rs`.
1034    /// Fixtures: `tests/fixtures/by-kind/parse_error/`.
1035    ParseError {
1036        message: String,
1037        /// The parser's stable kebab-case identifier, e.g. `version-too-low`.
1038        code: String,
1039    },
1040    /// Emitted by `mir-analyzer/src/parser/mod.rs`.
1041    /// Fixtures: `tests/fixtures/by-kind/compile_error/`.
1042    CompileError {
1043        message: String,
1044        /// The parser's stable kebab-case identifier, e.g. `magic-method-static`.
1045        code: String,
1046    },
1047    /// Emitted by `mir-analyzer/src/collector/annotation.rs`.
1048    /// Fixtures: `tests/fixtures/by-kind/invalid_docblock/`.
1049    InvalidDocblock { message: String },
1050    /// A docblock type is invalid. Not currently emitted; kept for configuration compatibility.
1051    InvalidDocblockType { message: String },
1052    /// Emitted by `mir-analyzer/src/call/args/types.rs`.
1053    /// Fixtures: `tests/fixtures/by-kind/mixed_argument/`.
1054    MixedArgument { param: String, fn_name: String },
1055    /// Emitted by `mir-analyzer/src/expr/assignment.rs` and `mir-analyzer/src/stmt/control_flow.rs`.
1056    /// Fixtures: `tests/fixtures/by-kind/mixed_assignment/`.
1057    MixedAssignment { var: String },
1058    /// Emitted by `mir-analyzer/src/call/method.rs`.
1059    /// Fixtures: `tests/fixtures/by-kind/mixed_method_call/`.
1060    MixedMethodCall { method: String },
1061    /// Emitted when a PHP reference assignment is used (e.g. `$b = &$arr[$x]`).
1062    /// Fixtures: `tests/fixtures/by-kind/unsupported_reference_usage/`.
1063    UnsupportedReferenceUsage,
1064    /// Emitted when a property is accessed on an interface that has `@seal-properties`
1065    /// but the property is not declared with `@property`/`@property-read`/`@property-write`.
1066    /// Fixtures: `tests/fixtures/by-kind/undefined_property/magic_interface_*.phpt`.
1067    NoInterfaceProperties { property: String },
1068    /// Emitted when a class referenced only in a docblock (`@return`, `@param`, etc.)
1069    /// does not exist.
1070    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/missing_class.phpt`.
1071    UndefinedDocblockClass { name: String },
1072    /// Emitted when a class with non-nullable uninitialized properties has no constructor.
1073    /// Fixtures: `tests/fixtures/by-kind/missing_constructor/`.
1074    MissingConstructor { class: String },
1075    /// Emitted when the constructor has a reachable exit path that doesn't
1076    /// assign a native-typed, non-nullable, default-less property declared
1077    /// directly on the class — reading it afterward throws PHP's "must not
1078    /// be accessed before initialization". Scoped to the class's own
1079    /// properties only (a property inherited from a parent class is that
1080    /// parent's own constructor's concern) and abstains entirely if the
1081    /// constructor calls out to any method/function that could have
1082    /// initialized the property on its behalf, to avoid flagging common
1083    /// delegating-init patterns it can't see into.
1084    /// Emitted by `mir-analyzer/src/body_analysis/classes.rs`.
1085    /// Fixtures: `tests/fixtures/by-kind/property_possibly_uninitialized/`.
1086    PropertyPossiblyUninitialized { class: String, property: String },
1087    /// Emitted by `mir-analyzer/src/call/function.rs` when a dynamic call target is mixed.
1088    /// Fixtures: `tests/fixtures/by-kind/mixed_function_call/`.
1089    MixedFunctionCall,
1090    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
1091    /// Fixtures: `tests/fixtures/by-kind/mixed_return_statement/`.
1092    MixedReturnStatement { declared: String },
1093    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
1094    /// Fixtures: `tests/fixtures/by-kind/mixed_property_fetch/`.
1095    MixedPropertyFetch { property: String },
1096    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
1097    /// Fixtures: `tests/fixtures/by-kind/mixed_property_assignment/`.
1098    MixedPropertyAssignment { property: String },
1099    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
1100    /// Fixtures: `tests/fixtures/by-kind/mixed_array_access/`.
1101    MixedArrayAccess,
1102    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
1103    /// Fixtures: `tests/fixtures/by-kind/mixed_array_offset/`.
1104    MixedArrayOffset,
1105    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
1106    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`.
1107    MixedClone,
1108    /// `clone` of a value that is definitely not an object (e.g. `int`, `string`),
1109    /// of an enum, or of an object whose private `__clone()` is out of scope.
1110    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
1111    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`, `tests/fixtures/by-kind/invalid_clone/`.
1112    InvalidClone { ty: String, reason: CloneFailure },
1113    /// `clone` of a union where some members are not objects (e.g. `int|Exception`).
1114    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
1115    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`.
1116    PossiblyInvalidClone { ty: String },
1117    /// A `__toString` method that does not return a `string`.
1118    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1119    /// Fixtures: `tests/fixtures/by-kind/implicit_to_string_cast/`.
1120    InvalidToString { class: String },
1121    /// Emitted by `mir-analyzer/src/class/mod.rs`.
1122    /// Fixtures: `tests/fixtures/by-kind/circular_inheritance/`.
1123    CircularInheritance { class: String },
1124
1125    // --- Trait constraints --------------------------------------------------
1126    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1127    /// Fixtures: `tests/fixtures/by-kind/invalid_trait_use/`.
1128    InvalidTraitUse { trait_name: String, reason: String },
1129    /// Emitted by `mir-analyzer/src/expr/mod.rs` and `mir-analyzer/src/call/function.rs`.
1130    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/` (var_dump, shell_exec, backtick).
1131    ForbiddenCode { message: String },
1132
1133    // --- Attribute validation -----------------------------------------------
1134    /// Emitted by `mir-analyzer/src/attributes.rs`.
1135    /// Fixtures: `tests/fixtures/by-kind/invalid_attribute/`.
1136    InvalidAttribute { message: String },
1137    /// Emitted by `mir-analyzer/src/attributes.rs`.
1138    /// Fixtures: `tests/fixtures/by-kind/undefined_class/missing_attribute_on_*.phpt`.
1139    UndefinedAttributeClass { name: String },
1140
1141    // --- Case sensitivity (PHP 8.6 deprecation) -----------------------------
1142    /// Emitted by `mir-analyzer/src/call/function.rs`.
1143    /// Fixtures: `tests/fixtures/by-kind/wrong_case_function/`.
1144    WrongCaseFunction { used: String, canonical: String },
1145    /// Emitted by `mir-analyzer/src/call/method.rs` and `src/call/static_call.rs`.
1146    /// Fixtures: `tests/fixtures/by-kind/wrong_case_method/`.
1147    WrongCaseMethod {
1148        class: String,
1149        used: String,
1150        canonical: String,
1151    },
1152    /// Emitted by `mir-analyzer/src/expr/objects.rs` and `src/call/static_call.rs`.
1153    /// Fixtures: `tests/fixtures/by-kind/wrong_case_class/`.
1154    WrongCaseClass { used: String, canonical: String },
1155    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1156    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/class_redefinition*.phpt`.
1157    DuplicateClass { name: String },
1158    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1159    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/interface_redefinition*.phpt`.
1160    DuplicateInterface { name: String },
1161    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1162    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/trait_redefinition*.phpt`.
1163    DuplicateTrait { name: String },
1164    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1165    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/enum_redefinition*.phpt`.
1166    DuplicateEnum { name: String },
1167    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
1168    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/function_redefinition*.phpt`.
1169    DuplicateFunction { name: String },
1170
1171    // --- Compile-time warnings ----------------------------------------------
1172    /// A `use` of a single-segment name with no alias outside any namespace —
1173    /// PHP warns that it has no effect.
1174    /// Emitted by `mir-analyzer/src/collector/mod.rs`.
1175    /// Fixtures: `tests/fixtures/by-kind/use_statement_has_no_effect/`.
1176    UseStatementHasNoEffect { name: String },
1177    /// A method other than the constructor is declared both `private` and
1178    /// `final` — PHP warns since a private method is never overridden.
1179    /// Emitted by `mir-analyzer/src/collector/mod.rs`.
1180    /// Fixtures: `tests/fixtures/by-kind/private_final_method/`.
1181    PrivateFinalMethod { class: String, method: String },
1182    /// A magic method PHP calls from outside the class (`__get`, `__call`,
1183    /// `__toString`, ...) is not public — PHP warns.
1184    /// Emitted by `mir-analyzer/src/collector/mod.rs`.
1185    /// Fixtures: `tests/fixtures/by-kind/non_public_magic_method/`.
1186    NonPublicMagicMethod { class: String, method: String },
1187    /// The result of a `#[\NoDiscard]` function or method is discarded (PHP 8.5+ warning).
1188    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
1189    /// Fixtures: `tests/fixtures/by-kind/no_discard_return_ignored/`.
1190    NoDiscardReturnIgnored {
1191        /// `function name` or `method Class::name`.
1192        callee: String,
1193        message: Option<String>,
1194    },
1195    /// The analyzer panicked on this file; its other issues are missing.
1196    /// Emitted by `mir-analyzer/src/batch/run.rs`.
1197    AnalyzerError { message: String },
1198
1199    // --- Plugins --------------------------------------------------------------
1200    /// Raised by a registered plugin (mir-plugin). `name` is the plugin's own
1201    /// issue identifier, used for display and suppression matching.
1202    PluginIssue { name: String, message: String },
1203}
1204
1205fn append_deprecation_message(base: String, message: &Option<Arc<str>>) -> String {
1206    match message.as_deref().filter(|m| !m.is_empty()) {
1207        Some(msg) => format!("{base}: {msg}"),
1208        None => base,
1209    }
1210}
1211
1212impl IssueKind {
1213    /// Diagnostics claiming a condition always (or never) holds.
1214    pub fn is_constant_condition(&self) -> bool {
1215        matches!(
1216            self,
1217            IssueKind::RedundantCondition { .. }
1218                | IssueKind::ImpossibleIdenticalComparison { .. }
1219                | IssueKind::ImpossibleLooseComparison { .. }
1220                | IssueKind::TypeDoesNotContainType { .. }
1221                | IssueKind::DocblockTypeContradiction { .. }
1222                | IssueKind::ParadoxicalCondition { .. }
1223        )
1224    }
1225
1226    /// Default severity for this issue kind.
1227    pub fn default_severity(&self) -> Severity {
1228        match self {
1229            // Errors (always blocking)
1230            IssueKind::NonStaticSelfCall { .. }
1231            | IssueKind::DirectConstructorCall { .. }
1232            | IssueKind::InvalidScope { .. }
1233            | IssueKind::UndefinedVariable { .. }
1234            | IssueKind::UndefinedFunction { .. }
1235            | IssueKind::UndefinedMethod { .. }
1236            | IssueKind::UndefinedClass { .. }
1237            | IssueKind::NotAnInterface { .. }
1238            | IssueKind::UndefinedConstant { .. }
1239            | IssueKind::InaccessibleClassConstant { .. }
1240            | IssueKind::InaccessibleProperty { .. }
1241            | IssueKind::InvalidReturnType { .. }
1242            | IssueKind::InvalidArgument { .. }
1243            | IssueKind::InvalidUnpack { .. }
1244            | IssueKind::TooFewArguments { .. }
1245            | IssueKind::TooManyArguments { .. }
1246            | IssueKind::InvalidNamedArgument { .. }
1247            | IssueKind::InvalidNamedArguments { .. }
1248            | IssueKind::InvalidPassByReference { .. }
1249            | IssueKind::InvalidThrow { .. }
1250            | IssueKind::InvalidCatch { .. }
1251            | IssueKind::InvalidStaticInvocation { .. }
1252            | IssueKind::UnimplementedAbstractMethod { .. }
1253            | IssueKind::UnimplementedInterfaceMethod { .. }
1254            | IssueKind::MethodSignatureMismatch { .. }
1255            | IssueKind::InvalidExtendClass { .. }
1256            | IssueKind::FinalMethodOverridden { .. }
1257            | IssueKind::OverriddenMethodAccess { .. }
1258            | IssueKind::OverriddenPropertyAccess { .. }
1259            | IssueKind::AbstractInstantiation { .. }
1260            | IssueKind::AbstractMethodCall { .. }
1261            | IssueKind::InterfaceInstantiation { .. }
1262            | IssueKind::EnumInstantiation { .. }
1263            | IssueKind::TraitInstantiation { .. }
1264            | IssueKind::InvalidDynamicProperty { .. }
1265            | IssueKind::InvalidOverride { .. }
1266            | IssueKind::InvalidTemplateParam { .. }
1267            | IssueKind::ReadonlyPropertyAssignment { .. }
1268            | IssueKind::ReadonlyPropertyAlreadyInitialized { .. }
1269            | IssueKind::ParseError { .. }
1270            | IssueKind::CompileError { .. }
1271            | IssueKind::AnalyzerError { .. }
1272            | IssueKind::TaintedInput { .. }
1273            | IssueKind::TaintedHtml
1274            | IssueKind::TaintedSql
1275            | IssueKind::TaintedShell
1276            | IssueKind::TaintedLlmPrompt
1277            | IssueKind::TaintedHeader
1278            | IssueKind::TaintedCookie
1279            | IssueKind::TaintedSsrf
1280            | IssueKind::TaintedLdap
1281            | IssueKind::TaintedXpath
1282            | IssueKind::TaintedCallable
1283            | IssueKind::TaintedFile
1284            | IssueKind::TaintedInclude
1285            | IssueKind::TaintedEval
1286            | IssueKind::TaintedUnserialize
1287            | IssueKind::TaintedXml
1288            | IssueKind::TaintedLog
1289            | IssueKind::TaintedCsv
1290            | IssueKind::TaintedNoSql
1291            | IssueKind::TaintedRegex
1292            | IssueKind::TaintedEnvironment
1293            | IssueKind::TaintedCommandArgument
1294            | IssueKind::TaintedMassAssignment { .. }
1295            | IssueKind::CircularInheritance { .. }
1296            | IssueKind::InvalidTraitUse { .. }
1297            | IssueKind::UndefinedTrait { .. }
1298            | IssueKind::TraitConstantAccessedDirectly { .. }
1299            | IssueKind::UndefinedTraitAliasMethod { .. }
1300            | IssueKind::InvalidClone { .. }
1301            | IssueKind::InvalidToString { .. }
1302            | IssueKind::TypeCheckMismatch { .. }
1303            | IssueKind::PropertyTypeRedeclarationMismatch { .. }
1304            | IssueKind::ReadonlyPropertyRedeclarationMismatch { .. }
1305            | IssueKind::StaticPropertyRedeclarationMismatch { .. }
1306            | IssueKind::ReadonlyClassExtendsMismatch { .. }
1307            | IssueKind::InvalidReadonlyPropertyDeclaration { .. }
1308            | IssueKind::BackedEnumCaseTypeMismatch { .. }
1309            | IssueKind::DuplicateEnumCaseValue { .. }
1310            | IssueKind::DivisionByZero { .. }
1311            | IssueKind::InvalidMemberName { .. }
1312            | IssueKind::NativeResourceType { .. }
1313            | IssueKind::ParentNotFound => Severity::Error,
1314            IssueKind::Trace { .. } => Severity::Info,
1315
1316            // Warnings (shown at default error level)
1317            IssueKind::NullArgument { .. }
1318            | IssueKind::NullPropertyFetch { .. }
1319            | IssueKind::NullMethodCall { .. }
1320            | IssueKind::NullArrayAccess
1321            | IssueKind::NullableReturnStatement { .. }
1322            | IssueKind::InvalidPropertyFetch { .. }
1323            | IssueKind::InvalidMethodCall { .. }
1324            | IssueKind::InvalidArrayAccess { .. }
1325            | IssueKind::InvalidArrayAssignment { .. }
1326            | IssueKind::InvalidPropertyAssignment { .. }
1327            | IssueKind::InvalidArrayOffset { .. }
1328            | IssueKind::NonExistentArrayOffset { .. }
1329            | IssueKind::PossiblyInvalidArrayOffset { .. }
1330            | IssueKind::UndefinedProperty { .. }
1331            | IssueKind::InvalidOperand { .. }
1332            | IssueKind::InvalidScalarArgument { .. }
1333            | IssueKind::ImplicitToStringCast { .. }
1334            | IssueKind::ImplicitFloatToIntCast { .. }
1335            | IssueKind::UnusedVariable { .. }
1336            | IssueKind::UnusedForeachValue { .. }
1337            | IssueKind::ImpurePropertyAssignment { .. }
1338            | IssueKind::ImpureMethodCall { .. }
1339            | IssueKind::ImpureGlobalVariable { .. }
1340            | IssueKind::ImpureStaticVariable { .. }
1341            | IssueKind::ImpureStaticPropertyAssignment { .. }
1342            | IssueKind::ImpureStaticPropertyAccess { .. }
1343            | IssueKind::ImpureFunctionCall { .. }
1344            | IssueKind::ImpureByRefAssignment { .. }
1345            | IssueKind::ImmutablePropertyModification { .. }
1346            | IssueKind::UnsupportedReferenceUsage
1347            | IssueKind::ParadoxicalCondition { .. }
1348            | IssueKind::UnhandledMatchCondition { .. }
1349            | IssueKind::InvalidStringClass { .. }
1350            | IssueKind::ImpossibleIdenticalComparison { .. }
1351            | IssueKind::ImpossibleLooseComparison { .. }
1352            | IssueKind::DuplicateArrayKey { .. }
1353            | IssueKind::ForbiddenCode { .. }
1354            | IssueKind::UndefinedThrowsDocblock { .. }
1355            | IssueKind::InvalidDocblockType { .. }
1356            | IssueKind::UseStatementHasNoEffect { .. }
1357            | IssueKind::PrivateFinalMethod { .. }
1358            | IssueKind::NonPublicMagicMethod { .. }
1359            | IssueKind::InsecurePasswordHash { .. }
1360            | IssueKind::WeakCryptography { .. }
1361            | IssueKind::InsecureSessionConfig { .. }
1362            | IssueKind::InsecureRandomness { .. }
1363            | IssueKind::UnsafeUnserialize
1364            | IssueKind::UnserializeGadget { .. }
1365            | IssueKind::MissingSensitiveParameter { .. }
1366            | IssueKind::QuotedShellEscape
1367            | IssueKind::UnrestrictedFileUpload
1368            | IssueKind::HostHeaderInjection { .. }
1369            | IssueKind::ResourceExhaustion { .. }
1370            | IssueKind::SpoofableClientIp
1371            | IssueKind::CodeAfterRedirect
1372            | IssueKind::InsecureCheckResult { .. }
1373            | IssueKind::LdapAnonymousBind
1374            | IssueKind::InsecureFilePermissions { .. }
1375            | IssueKind::HardcodedCredential { .. }
1376            | IssueKind::InsecureCors
1377            | IssueKind::PredictableSeed { .. }
1378            | IssueKind::ObfuscatedCode
1379            | IssueKind::InsecureTls { .. }
1380            | IssueKind::TimingUnsafeComparison { .. }
1381            | IssueKind::UnescapedLikeWildcard
1382            | IssueKind::UnquotedSqlEscape
1383            | IssueKind::InsufficientHtmlEscape
1384            | IssueKind::MissingAuthorizationCheck { .. }
1385            | IssueKind::UntracedTaint { .. }
1386            | IssueKind::NoDiscardReturnIgnored { .. } => Severity::Warning,
1387
1388            // PossiblyUndefined: shown at default error level (same as Warning)
1389            IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
1390
1391            // Possibly-null / possibly-invalid (only shown in strict mode, level ≥ 7)
1392            IssueKind::PossiblyNullArgument { .. }
1393            | IssueKind::PossiblyInvalidArgument { .. }
1394            | IssueKind::PossiblyNullPropertyFetch { .. }
1395            | IssueKind::PossiblyNullMethodCall { .. }
1396            | IssueKind::PossiblyUndefinedMethod { .. }
1397            | IssueKind::PossiblyNullArrayAccess
1398            | IssueKind::PossiblyInvalidArrayAccess { .. }
1399            | IssueKind::PossiblyInvalidClone { .. }
1400            | IssueKind::PossiblyInvalidOperand { .. }
1401            | IssueKind::PossiblyNullOperand { .. }
1402            | IssueKind::PossiblyRawObjectIteration { .. }
1403            | IssueKind::InvalidGeneratorIteration { .. }
1404            | IssueKind::PossiblyNullPropertyAssignmentValue { .. }
1405            | IssueKind::PossiblyFalsePropertyAssignmentValue { .. }
1406            | IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => Severity::Info,
1407
1408            IssueKind::RawObjectIteration { .. } => Severity::Warning,
1409
1410            // Info
1411            IssueKind::RedundantCondition { .. }
1412            | IssueKind::RedundantCast { .. }
1413            | IssueKind::UnnecessaryVarAnnotation { .. }
1414            | IssueKind::TypeDoesNotContainType { .. }
1415            | IssueKind::DocblockTypeContradiction { .. }
1416            | IssueKind::UnevaluatedCode { .. }
1417            | IssueKind::IfThisIsMismatch { .. }
1418            | IssueKind::UnusedParam { .. }
1419            | IssueKind::UnreachableCode
1420            | IssueKind::UnreachableCatch { .. }
1421            | IssueKind::UnusedMethod { .. }
1422            | IssueKind::UnusedProperty { .. }
1423            | IssueKind::UnusedFunction { .. }
1424            | IssueKind::UnusedClass { .. }
1425            | IssueKind::UnusedConstant { .. }
1426            | IssueKind::UnusedSuppress { .. }
1427            | IssueKind::ArgumentTypeCoercion { .. }
1428            | IssueKind::PropertyTypeCoercion { .. }
1429            | IssueKind::LessSpecificReturnStatement { .. }
1430            | IssueKind::DeprecatedCall { .. }
1431            | IssueKind::DeprecatedProperty { .. }
1432            | IssueKind::DeprecatedConstant { .. }
1433            | IssueKind::OptionalParameterBeforeRequired { .. }
1434            | IssueKind::ImplicitlyNullableParameter { .. }
1435            | IssueKind::DeprecatedSyntax { .. }
1436            | IssueKind::DynamicPropertyCreation { .. }
1437            | IssueKind::DeprecatedInterface { .. }
1438            | IssueKind::DeprecatedTrait { .. }
1439            | IssueKind::DeprecatedMethodCall { .. }
1440            | IssueKind::DeprecatedMethod { .. }
1441            | IssueKind::DeprecatedClass { .. }
1442            | IssueKind::InternalMethod { .. }
1443            | IssueKind::MissingReturnType { .. }
1444            | IssueKind::MissingClosureReturnType
1445            | IssueKind::MissingParamType { .. }
1446            | IssueKind::MissingPropertyType { .. }
1447            | IssueKind::MismatchingDocblockReturnType { .. }
1448            | IssueKind::MismatchingDocblockParamType { .. }
1449            | IssueKind::InvalidDocblock { .. }
1450            | IssueKind::InvalidCast { .. }
1451            | IssueKind::MixedArgument { .. }
1452            | IssueKind::MixedAssignment { .. }
1453            | IssueKind::MixedMethodCall { .. }
1454            | IssueKind::NoInterfaceProperties { .. }
1455            | IssueKind::UndefinedDocblockClass { .. }
1456            | IssueKind::MissingConstructor { .. }
1457            | IssueKind::PropertyPossiblyUninitialized { .. }
1458            | IssueKind::MixedFunctionCall
1459            | IssueKind::MixedReturnStatement { .. }
1460            | IssueKind::MixedPropertyFetch { .. }
1461            | IssueKind::MixedPropertyAssignment { .. }
1462            | IssueKind::MixedArrayAccess
1463            | IssueKind::MixedArrayOffset
1464            | IssueKind::MixedClone
1465            | IssueKind::ShadowedTemplateParam { .. }
1466            | IssueKind::MissingThrowsDocblock { .. }
1467            | IssueKind::WrongCaseFunction { .. }
1468            | IssueKind::WrongCaseMethod { .. }
1469            | IssueKind::WrongCaseClass { .. }
1470            | IssueKind::InvalidAttribute { .. }
1471            | IssueKind::UndefinedAttributeClass { .. }
1472            | IssueKind::NonInvariantDocblockPropertyType { .. } => Severity::Info,
1473            IssueKind::DuplicateClass { .. }
1474            | IssueKind::DuplicateInterface { .. }
1475            | IssueKind::DuplicateTrait { .. }
1476            | IssueKind::DuplicateEnum { .. }
1477            | IssueKind::DuplicateFunction { .. } => Severity::Error,
1478            // Plugins pick their own severity per issue; Error is only the
1479            // fallback when none was set.
1480            IssueKind::PluginIssue { .. } => Severity::Error,
1481        }
1482    }
1483
1484    /// Stable error code (e.g. `"MIR0005"`).
1485    ///
1486    /// Codes are assigned in bands by category and are part of the public API:
1487    /// once a code ships, it must never be reused for a different issue kind.
1488    /// New variants take the next free slot in their band; obsolete variants
1489    /// retire their code (the slot stays burnt). Bands have headroom for growth.
1490    ///
1491    /// Bands:
1492    ///
1493    /// | Range         | Category                        |
1494    /// |---------------|---------------------------------|
1495    /// | 0001 – 0099   | Undefined symbols               |
1496    /// | 0100 – 0199   | Nullability                     |
1497    /// | 0200 – 0299   | Type mismatches                 |
1498    /// | 0300 – 0399   | Array / offset                  |
1499    /// | 0400 – 0499   | Redundancy                      |
1500    /// | 0500 – 0599   | Dead code                       |
1501    /// | 0600 – 0699   | Readonly                        |
1502    /// | 0700 – 0799   | Inheritance                     |
1503    /// | 0800 – 0899   | Security (taint)                |
1504    /// | 0900 – 0999   | Generics                        |
1505    /// | 1000 – 1099   | Deprecation / internal          |
1506    /// | 1100 – 1199   | Missing types / docblocks       |
1507    /// | 1200 – 1299   | Mixed                           |
1508    /// | 1300 – 1399   | Trait                           |
1509    /// | 1400 – 1499   | Parse                           |
1510    /// | 1500 – 1599   | Other                           |
1511    /// | 1600 – 1699   | Attribute / duplicate declarations |
1512    /// | 1700 – 1799   | Purity                          |
1513    pub fn code(&self) -> &'static str {
1514        match self {
1515            // Undefined (0001-0099)
1516            IssueKind::NonStaticSelfCall { .. } => "MIR0216",
1517            IssueKind::DirectConstructorCall { .. } => "MIR0217",
1518            IssueKind::InvalidScope { .. } => "MIR0001",
1519            IssueKind::UndefinedVariable { .. } => "MIR0002",
1520            IssueKind::UndefinedFunction { .. } => "MIR0003",
1521            IssueKind::UndefinedMethod { .. } => "MIR0004",
1522            IssueKind::PossiblyUndefinedMethod { .. } => "MIR0015",
1523            IssueKind::InvalidDynamicProperty { .. } => "MIR0016",
1524            IssueKind::UndefinedClass { .. } => "MIR0005",
1525            IssueKind::UndefinedProperty { .. } => "MIR0006",
1526            IssueKind::UndefinedConstant { .. } => "MIR0007",
1527            IssueKind::InaccessibleClassConstant { .. } => "MIR0011",
1528            IssueKind::InaccessibleProperty { .. } => "MIR0014",
1529            IssueKind::TraitConstantAccessedDirectly { .. } => "MIR0012",
1530            IssueKind::UndefinedTraitAliasMethod { .. } => "MIR0013",
1531            IssueKind::PossiblyUndefinedVariable { .. } => "MIR0008",
1532            IssueKind::UndefinedTrait { .. } => "MIR0009",
1533            IssueKind::ParentNotFound => "MIR0010",
1534
1535            // Nullability (0100-0199)
1536            IssueKind::NullArgument { .. } => "MIR0100",
1537            IssueKind::NullPropertyFetch { .. } => "MIR0101",
1538            IssueKind::NullMethodCall { .. } => "MIR0102",
1539            IssueKind::NullArrayAccess => "MIR0103",
1540            IssueKind::PossiblyNullArgument { .. } => "MIR0104",
1541            IssueKind::PossiblyInvalidArgument { .. } => "MIR0105",
1542            IssueKind::PossiblyNullPropertyFetch { .. } => "MIR0106",
1543            IssueKind::PossiblyNullMethodCall { .. } => "MIR0107",
1544            IssueKind::PossiblyNullArrayAccess => "MIR0108",
1545            IssueKind::NullableReturnStatement { .. } => "MIR0109",
1546            IssueKind::LessSpecificReturnStatement { .. } => "MIR0110",
1547
1548            // Type mismatches (0200-0299)
1549            IssueKind::InvalidReturnType { .. } => "MIR0200",
1550            IssueKind::InvalidArgument { .. } => "MIR0201",
1551            IssueKind::InvalidScalarArgument { .. } => "MIR0238",
1552            IssueKind::TooFewArguments { .. } => "MIR0202",
1553            IssueKind::TooManyArguments { .. } => "MIR0203",
1554            IssueKind::InvalidNamedArgument { .. } => "MIR0204",
1555            IssueKind::InvalidNamedArguments { .. } => "MIR0224",
1556            IssueKind::InvalidPassByReference { .. } => "MIR0205",
1557            IssueKind::InvalidPropertyFetch { .. } => "MIR0218",
1558            IssueKind::InvalidArrayAccess { .. } => "MIR0219",
1559            IssueKind::PossiblyInvalidArrayAccess { .. } => "MIR0227",
1560            IssueKind::InvalidArrayAssignment { .. } => "MIR0220",
1561            IssueKind::InvalidPropertyAssignment { .. } => "MIR0206",
1562            IssueKind::PossiblyNullPropertyAssignmentValue { .. } => "MIR0232",
1563            IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => "MIR0233",
1564            IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => "MIR0234",
1565            IssueKind::InvalidCast { .. } => "MIR0207",
1566            IssueKind::InvalidStaticInvocation { .. } => "MIR0215",
1567            IssueKind::InvalidOperand { .. } => "MIR0208",
1568            IssueKind::PossiblyInvalidOperand { .. } => "MIR0213",
1569            IssueKind::PossiblyNullOperand { .. } => "MIR0214",
1570            IssueKind::DivisionByZero { .. } => "MIR0229",
1571            IssueKind::InvalidMethodCall { .. } => "MIR0230",
1572            IssueKind::InvalidMemberName { .. } => "MIR0235",
1573            IssueKind::NativeResourceType { .. } => "MIR0236",
1574            IssueKind::InvalidUnpack { .. } => "MIR0231",
1575            IssueKind::RawObjectIteration { .. } => "MIR0222",
1576            IssueKind::PossiblyRawObjectIteration { .. } => "MIR0223",
1577            IssueKind::InvalidGeneratorIteration { .. } => "MIR0237",
1578            IssueKind::MismatchingDocblockReturnType { .. } => "MIR0209",
1579            IssueKind::MismatchingDocblockParamType { .. } => "MIR0210",
1580            IssueKind::InvalidStringClass { .. } => "MIR0211",
1581            IssueKind::NotAnInterface { .. } => "MIR0228",
1582            IssueKind::TypeCheckMismatch { .. } => "MIR0212",
1583            IssueKind::Trace { .. } => "MIR0221",
1584            IssueKind::ArgumentTypeCoercion { .. } => "MIR0225",
1585            IssueKind::PropertyTypeCoercion { .. } => "MIR0226",
1586
1587            // Array / offset (0300-0399)
1588            IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1589            IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1590            IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1591            IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1592
1593            // Redundancy (0400-0499)
1594            IssueKind::RedundantCondition { .. } => "MIR0400",
1595            IssueKind::RedundantCast { .. } => "MIR0401",
1596            IssueKind::UnnecessaryVarAnnotation { .. } => "MIR0402",
1597            IssueKind::TypeDoesNotContainType { .. } => "MIR0403",
1598            IssueKind::ParadoxicalCondition { .. } => "MIR0404",
1599            IssueKind::UnhandledMatchCondition { .. } => "MIR0405",
1600            IssueKind::DocblockTypeContradiction { .. } => "MIR0406",
1601            IssueKind::UnevaluatedCode { .. } => "MIR0407",
1602            IssueKind::ImpossibleIdenticalComparison { .. } => "MIR0408",
1603            IssueKind::ImpossibleLooseComparison { .. } => "MIR0409",
1604
1605            // Dead code (0500-0599)
1606            IssueKind::UnusedVariable { .. } => "MIR0500",
1607            IssueKind::UnusedParam { .. } => "MIR0501",
1608            IssueKind::UnreachableCode => "MIR0502",
1609            IssueKind::UnusedMethod { .. } => "MIR0503",
1610            IssueKind::UnusedProperty { .. } => "MIR0504",
1611            IssueKind::UnusedFunction { .. } => "MIR0505",
1612            IssueKind::UnusedForeachValue { .. } => "MIR0506",
1613            IssueKind::UnusedClass { .. } => "MIR0507",
1614            IssueKind::UnusedSuppress { .. } => "MIR0508",
1615            IssueKind::UnusedConstant { .. } => "MIR0509",
1616
1617            // Purity (1700-1799)
1618            IssueKind::ImpurePropertyAssignment { .. } => "MIR1700",
1619            IssueKind::ImpureMethodCall { .. } => "MIR1701",
1620            IssueKind::ImpureGlobalVariable { .. } => "MIR1702",
1621            IssueKind::ImpureStaticVariable { .. } => "MIR1703",
1622            IssueKind::ImpureStaticPropertyAssignment { .. } => "MIR1706",
1623            IssueKind::ImpureByRefAssignment { .. } => "MIR1707",
1624            IssueKind::ImpureStaticPropertyAccess { .. } => "MIR1708",
1625            IssueKind::ImpureFunctionCall { .. } => "MIR1704",
1626            IssueKind::ImmutablePropertyModification { .. } => "MIR1705",
1627            IssueKind::UnsupportedReferenceUsage => "MIR1506",
1628            IssueKind::NoInterfaceProperties { .. } => "MIR1504",
1629            IssueKind::UndefinedDocblockClass { .. } => "MIR1505",
1630            IssueKind::MissingConstructor { .. } => "MIR1507",
1631            IssueKind::PropertyPossiblyUninitialized { .. } => "MIR1510",
1632            IssueKind::MixedFunctionCall => "MIR1211",
1633            IssueKind::MixedReturnStatement { .. } => "MIR1212",
1634
1635            // Readonly (0600-0699)
1636            IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1637            IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1638
1639            // Inheritance (0700-0799)
1640            IssueKind::UnimplementedAbstractMethod { .. } => "MIR0700",
1641            IssueKind::UnimplementedInterfaceMethod { .. } => "MIR0701",
1642            IssueKind::MethodSignatureMismatch { .. } => "MIR0702",
1643            IssueKind::OverriddenMethodAccess { .. } => "MIR0703",
1644            IssueKind::OverriddenPropertyAccess { .. } => "MIR0710",
1645            IssueKind::PropertyTypeRedeclarationMismatch { .. } => "MIR0712",
1646            IssueKind::BackedEnumCaseTypeMismatch { .. } => "MIR0713",
1647            IssueKind::DuplicateEnumCaseValue { .. } => "MIR0718",
1648            IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => "MIR0714",
1649            IssueKind::StaticPropertyRedeclarationMismatch { .. } => "MIR0715",
1650            IssueKind::ReadonlyClassExtendsMismatch { .. } => "MIR0716",
1651            IssueKind::InvalidReadonlyPropertyDeclaration { .. } => "MIR0717",
1652            IssueKind::InvalidExtendClass { .. } => "MIR0704",
1653            IssueKind::FinalMethodOverridden { .. } => "MIR0705",
1654            IssueKind::AbstractInstantiation { .. } => "MIR0706",
1655            IssueKind::AbstractMethodCall { .. } => "MIR0711",
1656            IssueKind::InterfaceInstantiation { .. } => "MIR0709",
1657            IssueKind::EnumInstantiation { .. } => "MIR0719",
1658            IssueKind::TraitInstantiation { .. } => "MIR0720",
1659            IssueKind::NonInvariantDocblockPropertyType { .. } => "MIR0721",
1660            IssueKind::CircularInheritance { .. } => "MIR0707",
1661            IssueKind::InvalidOverride { .. } => "MIR0708",
1662
1663            // Security / taint (0800-0899)
1664            IssueKind::TaintedMassAssignment { .. } => "MIR0823",
1665            IssueKind::TaintedCommandArgument => "MIR0824",
1666            IssueKind::QuotedShellEscape => "MIR0825",
1667            IssueKind::UnrestrictedFileUpload => "MIR0826",
1668            IssueKind::HostHeaderInjection { .. } => "MIR0827",
1669            IssueKind::TaintedNoSql => "MIR0828",
1670            IssueKind::TaintedRegex => "MIR0843",
1671            IssueKind::TaintedEnvironment => "MIR0844",
1672            IssueKind::UnescapedLikeWildcard => "MIR0845",
1673            IssueKind::UnquotedSqlEscape => "MIR0846",
1674            IssueKind::InsufficientHtmlEscape => "MIR0847",
1675            IssueKind::MissingAuthorizationCheck { .. } => "MIR0848",
1676            IssueKind::UntracedTaint { .. } => "MIR0849",
1677            IssueKind::TaintedCsv => "MIR0829",
1678            IssueKind::TaintedLog => "MIR0830",
1679            IssueKind::ResourceExhaustion { .. } => "MIR0831",
1680            IssueKind::SpoofableClientIp => "MIR0832",
1681            IssueKind::CodeAfterRedirect => "MIR0833",
1682            IssueKind::InsecureCheckResult { .. } => "MIR0834",
1683            IssueKind::LdapAnonymousBind => "MIR0835",
1684            IssueKind::InsecureFilePermissions { .. } => "MIR0836",
1685            IssueKind::HardcodedCredential { .. } => "MIR0837",
1686            IssueKind::InsecureCors => "MIR0838",
1687            IssueKind::PredictableSeed { .. } => "MIR0839",
1688            IssueKind::ObfuscatedCode => "MIR0840",
1689            IssueKind::InsecureTls { .. } => "MIR0841",
1690            IssueKind::TimingUnsafeComparison { .. } => "MIR0842",
1691            IssueKind::TaintedInput { .. } => "MIR0800",
1692            IssueKind::TaintedHtml => "MIR0801",
1693            IssueKind::TaintedSql => "MIR0802",
1694            IssueKind::TaintedShell => "MIR0803",
1695            IssueKind::TaintedLlmPrompt => "MIR0804",
1696            IssueKind::TaintedHeader => "MIR0805",
1697            IssueKind::TaintedCookie => "MIR0806",
1698            IssueKind::TaintedSsrf => "MIR0807",
1699            IssueKind::TaintedLdap => "MIR0808",
1700            IssueKind::TaintedXpath => "MIR0809",
1701            IssueKind::TaintedCallable => "MIR0810",
1702            IssueKind::TaintedFile => "MIR0811",
1703            IssueKind::TaintedInclude => "MIR0812",
1704            IssueKind::TaintedEval => "MIR0813",
1705            IssueKind::TaintedUnserialize => "MIR0814",
1706            IssueKind::MissingSensitiveParameter { .. } => "MIR0822",
1707            IssueKind::UnserializeGadget { .. } => "MIR0821",
1708            IssueKind::UnsafeUnserialize => "MIR0820",
1709            IssueKind::TaintedXml => "MIR0819",
1710            IssueKind::InsecureRandomness { .. } => "MIR0818",
1711            IssueKind::InsecureSessionConfig { .. } => "MIR0817",
1712            IssueKind::WeakCryptography { .. } => "MIR0816",
1713            IssueKind::InsecurePasswordHash { .. } => "MIR0815",
1714
1715            // Generics (0900-0999)
1716            IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1717            IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1718            IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1719
1720            // Deprecation / internal (1000-1099)
1721            IssueKind::DeprecatedCall { .. } => "MIR1000",
1722            IssueKind::WrongCaseFunction { .. } => "MIR1009",
1723            IssueKind::WrongCaseMethod { .. } => "MIR1010",
1724            IssueKind::WrongCaseClass { .. } => "MIR1011",
1725            IssueKind::DeprecatedProperty { .. } => "MIR1005",
1726            IssueKind::DeprecatedInterface { .. } => "MIR1006",
1727            IssueKind::DeprecatedTrait { .. } => "MIR1007",
1728            IssueKind::DeprecatedConstant { .. } => "MIR1008",
1729            IssueKind::DeprecatedMethodCall { .. } => "MIR1001",
1730            IssueKind::DeprecatedMethod { .. } => "MIR1002",
1731            IssueKind::DeprecatedClass { .. } => "MIR1003",
1732            IssueKind::InternalMethod { .. } => "MIR1004",
1733            IssueKind::OptionalParameterBeforeRequired { .. } => "MIR1012",
1734            IssueKind::ImplicitlyNullableParameter { .. } => "MIR1013",
1735            IssueKind::DynamicPropertyCreation { .. } => "MIR1014",
1736            IssueKind::DeprecatedSyntax { .. } => "MIR1015",
1737
1738            // Missing types / docblocks (1100-1199)
1739            IssueKind::MissingReturnType { .. } => "MIR1100",
1740            IssueKind::MissingParamType { .. } => "MIR1101",
1741            IssueKind::MissingPropertyType { .. } => "MIR1104",
1742            IssueKind::MissingClosureReturnType => "MIR1105",
1743            IssueKind::MissingThrowsDocblock { .. } => "MIR1102",
1744            IssueKind::InvalidDocblock { .. } => "MIR1103",
1745            IssueKind::UndefinedThrowsDocblock { .. } => "MIR1106",
1746            IssueKind::InvalidDocblockType { .. } => "MIR1107",
1747
1748            // Mixed (1200-1299)
1749            IssueKind::MixedArgument { .. } => "MIR1200",
1750            IssueKind::MixedAssignment { .. } => "MIR1201",
1751            IssueKind::MixedMethodCall { .. } => "MIR1202",
1752            IssueKind::MixedPropertyFetch { .. } => "MIR1203",
1753            IssueKind::MixedPropertyAssignment { .. } => "MIR1208",
1754            IssueKind::MixedArrayAccess => "MIR1209",
1755            IssueKind::MixedArrayOffset => "MIR1210",
1756            IssueKind::MixedClone => "MIR1204",
1757            IssueKind::InvalidClone { .. } => "MIR1205",
1758            IssueKind::PossiblyInvalidClone { .. } => "MIR1206",
1759            IssueKind::InvalidToString { .. } => "MIR1207",
1760
1761            // Trait (1300-1399)
1762            IssueKind::InvalidTraitUse { .. } => "MIR1300",
1763            IssueKind::ForbiddenCode { .. } => "MIR1301",
1764
1765            // Parse (1400-1499)
1766            IssueKind::ParseError { .. } => "MIR1400",
1767            IssueKind::CompileError { .. } => "MIR1401",
1768
1769            // Attribute (1600-1699)
1770            IssueKind::InvalidAttribute { .. } => "MIR1600",
1771            IssueKind::UndefinedAttributeClass { .. } => "MIR1601",
1772            IssueKind::DuplicateClass { .. } => "MIR1602",
1773            IssueKind::DuplicateInterface { .. } => "MIR1603",
1774            IssueKind::DuplicateTrait { .. } => "MIR1604",
1775            IssueKind::DuplicateEnum { .. } => "MIR1605",
1776            IssueKind::DuplicateFunction { .. } => "MIR1606",
1777
1778            // Other (1500-1599)
1779            IssueKind::InvalidThrow { .. } => "MIR1500",
1780            IssueKind::InvalidCatch { .. } => "MIR1503",
1781            IssueKind::UnreachableCatch { .. } => "MIR1508",
1782            IssueKind::PluginIssue { .. } => "MIR1509",
1783            IssueKind::ImplicitToStringCast { .. } => "MIR1501",
1784            IssueKind::ImplicitFloatToIntCast { .. } => "MIR1502",
1785            IssueKind::UseStatementHasNoEffect { .. } => "MIR1511",
1786            IssueKind::PrivateFinalMethod { .. } => "MIR1512",
1787            IssueKind::NonPublicMagicMethod { .. } => "MIR1513",
1788            IssueKind::NoDiscardReturnIgnored { .. } => "MIR1514",
1789            IssueKind::AnalyzerError { .. } => "MIR1515",
1790        }
1791    }
1792
1793    /// Returns the default [`Severity`] for a stable issue code (e.g. `"MIR0005"`).
1794    ///
1795    /// Useful when a caller holds a bare code string — from config, suppression
1796    /// annotations, or serialised diagnostics — and needs to recover the severity
1797    /// without constructing a full [`IssueKind`]. Returns `None` for unknown codes.
1798    pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1799        match code {
1800            // Errors
1801            "MIR0001" | "MIR0002" | "MIR0003" | "MIR0004" | "MIR0005" | "MIR0007" | "MIR0009"
1802            | "MIR0010" | "MIR0011" | "MIR0012" | "MIR0013" | "MIR0014" | "MIR0016" | "MIR0200"
1803            | "MIR0201" | "MIR0202" | "MIR0203" | "MIR0204" | "MIR0205" | "MIR0212" | "MIR0215"
1804            | "MIR0216" | "MIR0217" | "MIR0224" | "MIR0231" | "MIR0235" | "MIR0236" | "MIR0600"
1805            | "MIR0601" | "MIR0700" | "MIR0701" | "MIR0702" | "MIR0703" | "MIR0704" | "MIR0705"
1806            | "MIR0706" | "MIR0707" | "MIR0708" | "MIR0709" | "MIR0710" | "MIR0711" | "MIR0712"
1807            | "MIR0713" | "MIR0714" | "MIR0715" | "MIR0716" | "MIR0717" | "MIR0718" | "MIR0719"
1808            | "MIR0720" | "MIR0228" | "MIR0229" | "MIR0800" | "MIR0801" | "MIR0802" | "MIR0803"
1809            | "MIR0804" | "MIR0805" | "MIR0806" | "MIR0807" | "MIR0808" | "MIR0809" | "MIR0810"
1810            | "MIR0811" | "MIR0812" | "MIR0813" | "MIR0814" | "MIR0819" | "MIR0900" | "MIR1205"
1811            | "MIR1207" | "MIR1300" | "MIR1400" | "MIR1401" | "MIR1500" | "MIR1503" | "MIR1602"
1812            | "MIR1603" | "MIR1604" | "MIR1605" | "MIR1606" | "MIR0823" | "MIR0824" | "MIR0828"
1813            | "MIR0829" | "MIR0830" | "MIR0843" | "MIR0844" | "MIR1515" => Some(Severity::Error),
1814
1815            // Warnings
1816            "MIR0006" | "MIR0008" | "MIR0100" | "MIR0101" | "MIR0102" | "MIR0103" | "MIR0109"
1817            | "MIR0206" | "MIR0208" | "MIR0211" | "MIR0218" | "MIR0230" | "MIR0219" | "MIR0220"
1818            | "MIR0222" | "MIR0300" | "MIR0301" | "MIR0302" | "MIR0303" | "MIR0404" | "MIR0405"
1819            | "MIR0408" | "MIR0500" | "MIR0506" | "MIR1301" | "MIR1501" | "MIR1502" | "MIR1700"
1820            | "MIR1701" | "MIR1702" | "MIR1703" | "MIR1704" | "MIR1705" | "MIR1706" | "MIR1707"
1821            | "MIR1708" | "MIR1506" | "MIR1106" | "MIR1107" | "MIR1511" | "MIR1512" | "MIR1513"
1822            | "MIR1514" | "MIR0238" | "MIR0815" | "MIR0816" | "MIR0817" | "MIR0818" | "MIR0820"
1823            | "MIR0821" | "MIR0822" | "MIR0825" | "MIR0826" | "MIR0827" | "MIR0831" | "MIR0832"
1824            | "MIR0833" | "MIR0834" | "MIR0835" | "MIR0836" | "MIR0837" | "MIR0838" | "MIR0839"
1825            | "MIR0840" | "MIR0841" | "MIR0842" | "MIR0845" | "MIR0846" | "MIR0847" | "MIR0848"
1826            | "MIR0849" => Some(Severity::Warning),
1827
1828            // Info
1829            "MIR0015" | "MIR0104" | "MIR0105" | "MIR0106" | "MIR0107" | "MIR0108" | "MIR0207"
1830            | "MIR0232" | "MIR0233" | "MIR0234" | "MIR0209" | "MIR0210" | "MIR0213" | "MIR0214"
1831            | "MIR0221" | "MIR0223" | "MIR0400" | "MIR0401" | "MIR0402" | "MIR0403" | "MIR0501"
1832            | "MIR0502" | "MIR0503" | "MIR0504" | "MIR0505" | "MIR0507" | "MIR0508" | "MIR0509"
1833            | "MIR0901" | "MIR1000" | "MIR1001" | "MIR1002" | "MIR1003" | "MIR1004" | "MIR1005"
1834            | "MIR1006" | "MIR1007" | "MIR1008" | "MIR1009" | "MIR1010" | "MIR1011" | "MIR1012"
1835            | "MIR1013" | "MIR1014" | "MIR1015" | "MIR1100" | "MIR1101" | "MIR1102" | "MIR1103"
1836            | "MIR1104" | "MIR1105" | "MIR1200" | "MIR1201" | "MIR1202" | "MIR1203" | "MIR1204"
1837            | "MIR1206" | "MIR1208" | "MIR1209" | "MIR1210" | "MIR1211" | "MIR1212" | "MIR1504"
1838            | "MIR1505" | "MIR1507" | "MIR1508" | "MIR1600" | "MIR1601" | "MIR0225" | "MIR0226"
1839            | "MIR0227" | "MIR0406" | "MIR0407" | "MIR0902" | "MIR1510" | "MIR0721" | "MIR0237"
1840            | "MIR0110" => Some(Severity::Info),
1841
1842            _ => None,
1843        }
1844    }
1845
1846    /// Identifier name used in config and `@psalm-suppress` / `@suppress` annotations.
1847    pub fn name(&self) -> &'static str {
1848        match self {
1849            IssueKind::NonStaticSelfCall { .. } => "NonStaticSelfCall",
1850            IssueKind::DirectConstructorCall { .. } => "DirectConstructorCall",
1851            IssueKind::InvalidScope { .. } => "InvalidScope",
1852            IssueKind::UndefinedVariable { .. } => "UndefinedVariable",
1853            IssueKind::UndefinedFunction { .. } => "UndefinedFunction",
1854            IssueKind::UndefinedMethod { .. } => "UndefinedMethod",
1855            IssueKind::PossiblyUndefinedMethod { .. } => "PossiblyUndefinedMethod",
1856            IssueKind::UndefinedClass { .. } => "UndefinedClass",
1857            IssueKind::UndefinedProperty { .. } => "UndefinedProperty",
1858            IssueKind::UndefinedConstant { .. } => "UndefinedConstant",
1859            IssueKind::InaccessibleClassConstant { .. } => "InaccessibleClassConstant",
1860            IssueKind::InaccessibleProperty { .. } => "InaccessibleProperty",
1861            IssueKind::TraitConstantAccessedDirectly { .. } => "TraitConstantAccessedDirectly",
1862            IssueKind::UndefinedTraitAliasMethod { .. } => "UndefinedTraitAliasMethod",
1863            IssueKind::PossiblyUndefinedVariable { .. } => "PossiblyUndefinedVariable",
1864            IssueKind::UndefinedTrait { .. } => "UndefinedTrait",
1865            IssueKind::ParentNotFound => "ParentNotFound",
1866            IssueKind::InvalidStringClass { .. } => "InvalidStringClass",
1867            IssueKind::NotAnInterface { .. } => "NotAnInterface",
1868            IssueKind::NullArgument { .. } => "NullArgument",
1869            IssueKind::NullPropertyFetch { .. } => "NullPropertyFetch",
1870            IssueKind::NullMethodCall { .. } => "NullMethodCall",
1871            IssueKind::NullArrayAccess => "NullArrayAccess",
1872            IssueKind::PossiblyNullArgument { .. } => "PossiblyNullArgument",
1873            IssueKind::PossiblyInvalidArgument { .. } => "PossiblyInvalidArgument",
1874            IssueKind::PossiblyNullPropertyFetch { .. } => "PossiblyNullPropertyFetch",
1875            IssueKind::PossiblyNullMethodCall { .. } => "PossiblyNullMethodCall",
1876            IssueKind::PossiblyNullArrayAccess => "PossiblyNullArrayAccess",
1877            IssueKind::NullableReturnStatement { .. } => "NullableReturnStatement",
1878            IssueKind::InvalidReturnType { .. } => "InvalidReturnType",
1879            IssueKind::InvalidArgument { .. } => "InvalidArgument",
1880            IssueKind::InvalidScalarArgument { .. } => "InvalidScalarArgument",
1881            IssueKind::LessSpecificReturnStatement { .. } => "LessSpecificReturnStatement",
1882            IssueKind::TooFewArguments { .. } => "TooFewArguments",
1883            IssueKind::TooManyArguments { .. } => "TooManyArguments",
1884            IssueKind::InvalidNamedArgument { .. } => "InvalidNamedArgument",
1885            IssueKind::InvalidNamedArguments { .. } => "InvalidNamedArguments",
1886            IssueKind::InvalidPassByReference { .. } => "InvalidPassByReference",
1887            IssueKind::InvalidPropertyFetch { .. } => "InvalidPropertyFetch",
1888            IssueKind::InvalidMethodCall { .. } => "InvalidMethodCall",
1889            IssueKind::InvalidMemberName { .. } => "InvalidMemberName",
1890            IssueKind::NativeResourceType { .. } => "NativeResourceType",
1891            IssueKind::InvalidUnpack { .. } => "InvalidUnpack",
1892            IssueKind::InvalidArrayAccess { .. } => "InvalidArrayAccess",
1893            IssueKind::PossiblyInvalidArrayAccess { .. } => "PossiblyInvalidArrayAccess",
1894            IssueKind::InvalidArrayAssignment { .. } => "InvalidArrayAssignment",
1895            IssueKind::InvalidPropertyAssignment { .. } => "InvalidPropertyAssignment",
1896            IssueKind::PossiblyNullPropertyAssignmentValue { .. } => {
1897                "PossiblyNullPropertyAssignmentValue"
1898            }
1899            IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => {
1900                "PossiblyFalsePropertyAssignmentValue"
1901            }
1902            IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => {
1903                "PossiblyInvalidPropertyAssignmentValue"
1904            }
1905            IssueKind::InvalidCast { .. } => "InvalidCast",
1906            IssueKind::InvalidStaticInvocation { .. } => "InvalidStaticInvocation",
1907            IssueKind::InvalidOperand { .. } => "InvalidOperand",
1908            IssueKind::PossiblyInvalidOperand { .. } => "PossiblyInvalidOperand",
1909            IssueKind::PossiblyNullOperand { .. } => "PossiblyNullOperand",
1910            IssueKind::DivisionByZero { .. } => "DivisionByZero",
1911            IssueKind::RawObjectIteration { .. } => "RawObjectIteration",
1912            IssueKind::PossiblyRawObjectIteration { .. } => "PossiblyRawObjectIteration",
1913            IssueKind::InvalidGeneratorIteration { .. } => "InvalidGeneratorIteration",
1914            IssueKind::MismatchingDocblockReturnType { .. } => "MismatchingDocblockReturnType",
1915            IssueKind::MismatchingDocblockParamType { .. } => "MismatchingDocblockParamType",
1916            IssueKind::TypeCheckMismatch { .. } => "TypeCheckMismatch",
1917            IssueKind::DocblockTypeContradiction { .. } => "DocblockTypeContradiction",
1918            IssueKind::ImpossibleIdenticalComparison { .. } => "ImpossibleIdenticalComparison",
1919            IssueKind::ImpossibleLooseComparison { .. } => "ImpossibleLooseComparison",
1920            IssueKind::UnevaluatedCode { .. } => "UnevaluatedCode",
1921            IssueKind::IfThisIsMismatch { .. } => "IfThisIsMismatch",
1922            IssueKind::Trace { .. } => "Trace",
1923            IssueKind::InvalidArrayOffset { .. } => "InvalidArrayOffset",
1924            IssueKind::NonExistentArrayOffset { .. } => "NonExistentArrayOffset",
1925            IssueKind::PossiblyInvalidArrayOffset { .. } => "PossiblyInvalidArrayOffset",
1926            IssueKind::DuplicateArrayKey { .. } => "DuplicateArrayKey",
1927            IssueKind::RedundantCondition { .. } => "RedundantCondition",
1928            IssueKind::RedundantCast { .. } => "RedundantCast",
1929            IssueKind::UnnecessaryVarAnnotation { .. } => "UnnecessaryVarAnnotation",
1930            IssueKind::TypeDoesNotContainType { .. } => "TypeDoesNotContainType",
1931            IssueKind::ParadoxicalCondition { .. } => "ParadoxicalCondition",
1932            IssueKind::UnhandledMatchCondition { .. } => "UnhandledMatchCondition",
1933            IssueKind::UnusedVariable { .. } => "UnusedVariable",
1934            IssueKind::UnusedParam { .. } => "UnusedParam",
1935            IssueKind::UnreachableCode => "UnreachableCode",
1936            IssueKind::UnusedMethod { .. } => "UnusedMethod",
1937            IssueKind::UnusedProperty { .. } => "UnusedProperty",
1938            IssueKind::UnusedFunction { .. } => "UnusedFunction",
1939            IssueKind::UnusedForeachValue { .. } => "UnusedForeachValue",
1940            IssueKind::UnusedClass { .. } => "UnusedClass",
1941            IssueKind::UnusedConstant { .. } => "UnusedConstant",
1942            IssueKind::UnusedSuppress { .. } => "UnusedSuppress",
1943            IssueKind::ArgumentTypeCoercion { .. } => "ArgumentTypeCoercion",
1944            IssueKind::PropertyTypeCoercion { .. } => "PropertyTypeCoercion",
1945            IssueKind::ImpurePropertyAssignment { .. } => "ImpurePropertyAssignment",
1946            IssueKind::ImpureMethodCall { .. } => "ImpureMethodCall",
1947            IssueKind::ImpureGlobalVariable { .. } => "ImpureGlobalVariable",
1948            IssueKind::ImpureStaticVariable { .. } => "ImpureStaticVariable",
1949            IssueKind::ImpureByRefAssignment { .. } => "ImpureByRefAssignment",
1950            IssueKind::ImpureStaticPropertyAssignment { .. } => "ImpureStaticPropertyAssignment",
1951            IssueKind::ImpureStaticPropertyAccess { .. } => "ImpureStaticPropertyAccess",
1952            IssueKind::ImpureFunctionCall { .. } => "ImpureFunctionCall",
1953            IssueKind::ImmutablePropertyModification { .. } => "ImmutablePropertyModification",
1954            IssueKind::UnsupportedReferenceUsage => "UnsupportedReferenceUsage",
1955            IssueKind::NoInterfaceProperties { .. } => "NoInterfaceProperties",
1956            IssueKind::UndefinedDocblockClass { .. } => "UndefinedDocblockClass",
1957            IssueKind::MissingConstructor { .. } => "MissingConstructor",
1958            IssueKind::PropertyPossiblyUninitialized { .. } => "PropertyPossiblyUninitialized",
1959            IssueKind::MixedFunctionCall => "MixedFunctionCall",
1960            IssueKind::MixedReturnStatement { .. } => "MixedReturnStatement",
1961            IssueKind::UnimplementedAbstractMethod { .. } => "UnimplementedAbstractMethod",
1962            IssueKind::UnimplementedInterfaceMethod { .. } => "UnimplementedInterfaceMethod",
1963            IssueKind::MethodSignatureMismatch { .. } => "MethodSignatureMismatch",
1964            IssueKind::OverriddenMethodAccess { .. } => "OverriddenMethodAccess",
1965            IssueKind::OverriddenPropertyAccess { .. } => "OverriddenPropertyAccess",
1966            IssueKind::PropertyTypeRedeclarationMismatch { .. } => {
1967                "PropertyTypeRedeclarationMismatch"
1968            }
1969            IssueKind::NonInvariantDocblockPropertyType { .. } => {
1970                "NonInvariantDocblockPropertyType"
1971            }
1972            IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => {
1973                "ReadonlyPropertyRedeclarationMismatch"
1974            }
1975            IssueKind::StaticPropertyRedeclarationMismatch { .. } => {
1976                "StaticPropertyRedeclarationMismatch"
1977            }
1978            IssueKind::ReadonlyClassExtendsMismatch { .. } => "ReadonlyClassExtendsMismatch",
1979            IssueKind::InvalidReadonlyPropertyDeclaration { .. } => {
1980                "InvalidReadonlyPropertyDeclaration"
1981            }
1982            IssueKind::BackedEnumCaseTypeMismatch { .. } => "BackedEnumCaseTypeMismatch",
1983            IssueKind::DuplicateEnumCaseValue { .. } => "DuplicateEnumCaseValue",
1984            IssueKind::InvalidExtendClass { .. } => "InvalidExtendClass",
1985            IssueKind::FinalMethodOverridden { .. } => "FinalMethodOverridden",
1986            IssueKind::AbstractInstantiation { .. } => "AbstractInstantiation",
1987            IssueKind::AbstractMethodCall { .. } => "AbstractMethodCall",
1988            IssueKind::InterfaceInstantiation { .. } => "InterfaceInstantiation",
1989            IssueKind::EnumInstantiation { .. } => "EnumInstantiation",
1990            IssueKind::TraitInstantiation { .. } => "TraitInstantiation",
1991            IssueKind::InvalidDynamicProperty { .. } => "InvalidDynamicProperty",
1992            IssueKind::InvalidOverride { .. } => "InvalidOverride",
1993            IssueKind::ReadonlyPropertyAssignment { .. } => "ReadonlyPropertyAssignment",
1994            IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => {
1995                "ReadonlyPropertyAlreadyInitialized"
1996            }
1997            IssueKind::InvalidTemplateParam { .. } => "InvalidTemplateParam",
1998            IssueKind::ShadowedTemplateParam { .. } => "ShadowedTemplateParam",
1999            IssueKind::TaintedInput { .. } => "TaintedInput",
2000            IssueKind::TaintedHtml => "TaintedHtml",
2001            IssueKind::TaintedSql => "TaintedSql",
2002            IssueKind::TaintedShell => "TaintedShell",
2003            IssueKind::TaintedLlmPrompt => "TaintedLlmPrompt",
2004            IssueKind::TaintedHeader => "TaintedHeader",
2005            IssueKind::TaintedCookie => "TaintedCookie",
2006            IssueKind::TaintedSsrf => "TaintedSsrf",
2007            IssueKind::TaintedLdap => "TaintedLdap",
2008            IssueKind::TaintedXpath => "TaintedXpath",
2009            IssueKind::TaintedCallable => "TaintedCallable",
2010            IssueKind::TaintedFile => "TaintedFile",
2011            IssueKind::TaintedInclude => "TaintedInclude",
2012            IssueKind::TaintedEval => "TaintedEval",
2013            IssueKind::TaintedUnserialize => "TaintedUnserialize",
2014            IssueKind::TaintedMassAssignment { .. } => "TaintedMassAssignment",
2015            IssueKind::TaintedCommandArgument => "TaintedCommandArgument",
2016            IssueKind::QuotedShellEscape => "QuotedShellEscape",
2017            IssueKind::UnrestrictedFileUpload => "UnrestrictedFileUpload",
2018            IssueKind::HostHeaderInjection { .. } => "HostHeaderInjection",
2019            IssueKind::TaintedNoSql => "TaintedNoSql",
2020            IssueKind::TaintedRegex => "TaintedRegex",
2021            IssueKind::TaintedEnvironment => "TaintedEnvironment",
2022            IssueKind::UnescapedLikeWildcard => "UnescapedLikeWildcard",
2023            IssueKind::UnquotedSqlEscape => "UnquotedSqlEscape",
2024            IssueKind::InsufficientHtmlEscape => "InsufficientHtmlEscape",
2025            IssueKind::MissingAuthorizationCheck { .. } => "MissingAuthorizationCheck",
2026            IssueKind::UntracedTaint { .. } => "UntracedTaint",
2027            IssueKind::TaintedCsv => "TaintedCsv",
2028            IssueKind::TaintedLog => "TaintedLog",
2029            IssueKind::ResourceExhaustion { .. } => "ResourceExhaustion",
2030            IssueKind::SpoofableClientIp => "SpoofableClientIp",
2031            IssueKind::CodeAfterRedirect => "CodeAfterRedirect",
2032            IssueKind::InsecureCheckResult { .. } => "InsecureCheckResult",
2033            IssueKind::LdapAnonymousBind => "LdapAnonymousBind",
2034            IssueKind::InsecureFilePermissions { .. } => "InsecureFilePermissions",
2035            IssueKind::HardcodedCredential { .. } => "HardcodedCredential",
2036            IssueKind::InsecureCors => "InsecureCors",
2037            IssueKind::PredictableSeed { .. } => "PredictableSeed",
2038            IssueKind::ObfuscatedCode => "ObfuscatedCode",
2039            IssueKind::InsecureTls { .. } => "InsecureTls",
2040            IssueKind::TimingUnsafeComparison { .. } => "TimingUnsafeComparison",
2041            IssueKind::MissingSensitiveParameter { .. } => "MissingSensitiveParameter",
2042            IssueKind::UnserializeGadget { .. } => "UnserializeGadget",
2043            IssueKind::UnsafeUnserialize => "UnsafeUnserialize",
2044            IssueKind::TaintedXml => "TaintedXml",
2045            IssueKind::InsecureRandomness { .. } => "InsecureRandomness",
2046            IssueKind::InsecureSessionConfig { .. } => "InsecureSessionConfig",
2047            IssueKind::WeakCryptography { .. } => "WeakCryptography",
2048            IssueKind::InsecurePasswordHash { .. } => "InsecurePasswordHash",
2049            IssueKind::DeprecatedCall { .. } => "DeprecatedCall",
2050            IssueKind::DeprecatedProperty { .. } => "DeprecatedProperty",
2051            IssueKind::DeprecatedConstant { .. } => "DeprecatedConstant",
2052            IssueKind::DeprecatedInterface { .. } => "DeprecatedInterface",
2053            IssueKind::DeprecatedTrait { .. } => "DeprecatedTrait",
2054            IssueKind::DeprecatedMethodCall { .. } => "DeprecatedMethodCall",
2055            IssueKind::DeprecatedMethod { .. } => "DeprecatedMethod",
2056            IssueKind::DeprecatedClass { .. } => "DeprecatedClass",
2057            IssueKind::InternalMethod { .. } => "InternalMethod",
2058            IssueKind::OptionalParameterBeforeRequired { .. } => "OptionalParameterBeforeRequired",
2059            IssueKind::ImplicitlyNullableParameter { .. } => "ImplicitlyNullableParameter",
2060            IssueKind::DeprecatedSyntax { .. } => "DeprecatedSyntax",
2061            IssueKind::DynamicPropertyCreation { .. } => "DynamicPropertyCreation",
2062            IssueKind::MissingReturnType { .. } => "MissingReturnType",
2063            IssueKind::MissingClosureReturnType => "MissingClosureReturnType",
2064            IssueKind::MissingParamType { .. } => "MissingParamType",
2065            IssueKind::MissingPropertyType { .. } => "MissingPropertyType",
2066            IssueKind::InvalidThrow { .. } => "InvalidThrow",
2067            IssueKind::InvalidCatch { .. } => "InvalidCatch",
2068            IssueKind::UnreachableCatch { .. } => "UnreachableCatch",
2069            IssueKind::MissingThrowsDocblock { .. } => "MissingThrowsDocblock",
2070            IssueKind::ImplicitToStringCast { .. } => "ImplicitToStringCast",
2071            IssueKind::ImplicitFloatToIntCast { .. } => "ImplicitFloatToIntCast",
2072            IssueKind::ParseError { .. } => "ParseError",
2073            IssueKind::CompileError { .. } => "CompileError",
2074            IssueKind::InvalidDocblock { .. } => "InvalidDocblock",
2075            IssueKind::UndefinedThrowsDocblock { .. } => "UndefinedThrowsDocblock",
2076            IssueKind::InvalidDocblockType { .. } => "InvalidDocblockType",
2077            IssueKind::MixedArgument { .. } => "MixedArgument",
2078            IssueKind::MixedAssignment { .. } => "MixedAssignment",
2079            IssueKind::MixedMethodCall { .. } => "MixedMethodCall",
2080            IssueKind::MixedPropertyFetch { .. } => "MixedPropertyFetch",
2081            IssueKind::MixedPropertyAssignment { .. } => "MixedPropertyAssignment",
2082            IssueKind::MixedArrayAccess => "MixedArrayAccess",
2083            IssueKind::MixedArrayOffset => "MixedArrayOffset",
2084            IssueKind::MixedClone => "MixedClone",
2085            IssueKind::InvalidClone { .. } => "InvalidClone",
2086            IssueKind::PossiblyInvalidClone { .. } => "PossiblyInvalidClone",
2087            IssueKind::InvalidToString { .. } => "InvalidToString",
2088            IssueKind::CircularInheritance { .. } => "CircularInheritance",
2089            IssueKind::InvalidTraitUse { .. } => "InvalidTraitUse",
2090            IssueKind::ForbiddenCode { .. } => "ForbiddenCode",
2091            IssueKind::WrongCaseFunction { .. } => "WrongCaseFunction",
2092            IssueKind::WrongCaseMethod { .. } => "WrongCaseMethod",
2093            IssueKind::WrongCaseClass { .. } => "WrongCaseClass",
2094            IssueKind::InvalidAttribute { .. } => "InvalidAttribute",
2095            IssueKind::UndefinedAttributeClass { .. } => "UndefinedAttributeClass",
2096            IssueKind::DuplicateClass { .. } => "DuplicateClass",
2097            IssueKind::DuplicateInterface { .. } => "DuplicateInterface",
2098            IssueKind::DuplicateTrait { .. } => "DuplicateTrait",
2099            IssueKind::DuplicateEnum { .. } => "DuplicateEnum",
2100            IssueKind::DuplicateFunction { .. } => "DuplicateFunction",
2101            IssueKind::UseStatementHasNoEffect { .. } => "UseStatementHasNoEffect",
2102            IssueKind::PrivateFinalMethod { .. } => "PrivateFinalMethod",
2103            IssueKind::NonPublicMagicMethod { .. } => "NonPublicMagicMethod",
2104            IssueKind::NoDiscardReturnIgnored { .. } => "NoDiscardReturnIgnored",
2105            IssueKind::AnalyzerError { .. } => "AnalyzerError",
2106            IssueKind::PluginIssue { .. } => "PluginIssue",
2107        }
2108    }
2109
2110    /// The symbol Psalm's `<referencedClass>`-style issue-handler filters match.
2111    pub fn referenced_symbol(&self) -> Option<String> {
2112        use IssueKind::*;
2113        Some(match self {
2114            UndefinedClass { name }
2115            | UndefinedFunction { name }
2116            | UndefinedConstant { name }
2117            | UndefinedTrait { name }
2118            | UnusedFunction { name }
2119            | DeprecatedCall { name, .. }
2120            | DeprecatedClass { name, .. }
2121            | DeprecatedInterface { name, .. }
2122            | DeprecatedTrait { name, .. } => name.clone(),
2123            UnusedClass { class } => class.clone(),
2124            UndefinedMethod { class, method }
2125            | PossiblyUndefinedMethod { class, method }
2126            | UnusedMethod { class, method }
2127            | InternalMethod { class, method }
2128            | DeprecatedMethod { class, method, .. }
2129            | DeprecatedMethodCall { class, method, .. } => format!("{class}::{method}"),
2130            UndefinedProperty { class, property }
2131            | InaccessibleProperty { class, property }
2132            | UnusedProperty { class, property }
2133            | DeprecatedProperty {
2134                class, property, ..
2135            } => format!("{class}::${property}"),
2136            InaccessibleClassConstant { class, constant }
2137            | UnusedConstant { class, constant }
2138            | DeprecatedConstant {
2139                class, constant, ..
2140            } => format!("{class}::{constant}"),
2141            UndefinedVariable { name }
2142            | PossiblyUndefinedVariable { name }
2143            | UnusedVariable { name } => format!("${name}"),
2144            _ => return None,
2145        })
2146    }
2147
2148    /// Like [`IssueKind::name`], but for plugin-raised issues returns the
2149    /// plugin's own issue name. Use this for suppression / issue-handler
2150    /// matching so `@mir-suppress MyPluginIssue` works.
2151    pub fn display_name(&self) -> &str {
2152        match self {
2153            IssueKind::PluginIssue { name, .. } => name,
2154            other => other.name(),
2155        }
2156    }
2157
2158    /// Human-readable message for this issue.
2159    pub fn message(&self) -> String {
2160        match self {
2161            IssueKind::NonStaticSelfCall { class, method } => {
2162                format!("Non-static method {class}::{method}() cannot be called statically")
2163            }
2164            IssueKind::DirectConstructorCall { class } => {
2165                format!("Cannot call constructor of {class} directly")
2166            }
2167            IssueKind::InvalidScope { in_class } => {
2168                if *in_class {
2169                    "$this cannot be used in a static method".to_string()
2170                } else {
2171                    "$this cannot be used outside of a class".to_string()
2172                }
2173            }
2174            IssueKind::UndefinedVariable { name } => format!("Variable ${name} is not defined"),
2175            IssueKind::UndefinedFunction { name } => format!("Function {name}() is not defined"),
2176            IssueKind::UndefinedMethod { class, method } => {
2177                format!("Method {class}::{method}() does not exist")
2178            }
2179            IssueKind::PossiblyUndefinedMethod { class, method } => {
2180                format!("Method {class}::{method}() might not exist")
2181            }
2182            IssueKind::UndefinedClass { name } => format!("Class {name} does not exist"),
2183            IssueKind::UndefinedProperty { class, property } => {
2184                format!("Property {class}::${property} does not exist")
2185            }
2186            IssueKind::UndefinedConstant { name } => format!("Constant {name} is not defined"),
2187            IssueKind::InaccessibleClassConstant { class, constant } => {
2188                format!("Cannot access constant {class}::{constant}")
2189            }
2190            IssueKind::InaccessibleProperty { class, property } => {
2191                format!("Cannot access property {class}::${property}")
2192            }
2193            IssueKind::PossiblyUndefinedVariable { name } => {
2194                format!("Variable ${name} might not be defined")
2195            }
2196            IssueKind::UndefinedTrait { name } => format!("Trait {name} does not exist"),
2197            IssueKind::TraitConstantAccessedDirectly {
2198                trait_name,
2199                constant,
2200            } => {
2201                format!("Cannot access trait constant {trait_name}::{constant} directly")
2202            }
2203            IssueKind::UndefinedTraitAliasMethod { trait_name, method } => match trait_name {
2204                Some(t) => {
2205                    format!("An alias was defined for {t}::{method} but this method does not exist")
2206                }
2207                None => format!("An alias was defined for {method} but this method does not exist"),
2208            },
2209            IssueKind::ParentNotFound => {
2210                "Cannot use parent:: when current class has no parent".to_string()
2211            }
2212            IssueKind::InvalidStringClass { actual } => {
2213                format!("Dynamic class instantiation requires string or class-string type, got '{actual}'")
2214            }
2215            IssueKind::NotAnInterface { name } => {
2216                format!("{name} is not an interface")
2217            }
2218
2219            IssueKind::NullArgument { param, fn_name } => {
2220                format!("Argument ${param} of {fn_name}() cannot be null")
2221            }
2222            IssueKind::NullPropertyFetch { property } => {
2223                format!("Cannot access property ${property} on null")
2224            }
2225            IssueKind::NullMethodCall { method } => {
2226                format!("Cannot call method {method}() on null")
2227            }
2228            IssueKind::NullArrayAccess => "Cannot access array on null".to_string(),
2229            IssueKind::PossiblyNullArgument { param, fn_name } => {
2230                format!("Argument ${param} of {fn_name}() might be null")
2231            }
2232            IssueKind::PossiblyInvalidArgument {
2233                param,
2234                fn_name,
2235                expected,
2236                actual,
2237            } => {
2238                format!("Argument ${param} of {fn_name}() expects '{expected}', possibly different type '{actual}' provided")
2239            }
2240            IssueKind::PossiblyNullPropertyFetch { property } => {
2241                format!("Cannot access property ${property} on possibly null value")
2242            }
2243            IssueKind::PossiblyNullMethodCall { method } => {
2244                format!("Cannot call method {method}() on possibly null value")
2245            }
2246            IssueKind::PossiblyNullArrayAccess => {
2247                "Cannot access array on possibly null value".to_string()
2248            }
2249            IssueKind::NullableReturnStatement { expected, actual } => {
2250                format!("Return type '{actual}' is not compatible with declared '{expected}'")
2251            }
2252
2253            IssueKind::InvalidReturnType { expected, actual } => {
2254                format!("Return type '{actual}' is not compatible with declared '{expected}'")
2255            }
2256            IssueKind::LessSpecificReturnStatement { expected, actual } => {
2257                format!("Return type '{actual}' is less specific than declared '{expected}'")
2258            }
2259            IssueKind::InvalidScalarArgument {
2260                param,
2261                fn_name,
2262                expected,
2263                actual,
2264            } => {
2265                format!("Argument ${param} of {fn_name}() expects '{expected}', got scalar '{actual}'")
2266            }
2267            IssueKind::InvalidArgument {
2268                param,
2269                fn_name,
2270                expected,
2271                actual,
2272            } => {
2273                format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}'")
2274            }
2275            IssueKind::TooFewArguments {
2276                fn_name,
2277                expected,
2278                actual,
2279            } => {
2280                format!(
2281                    "Too few arguments for {}(): expected {}, got {}",
2282                    fn_name, expected, actual
2283                )
2284            }
2285            IssueKind::TooManyArguments {
2286                fn_name,
2287                expected,
2288                actual,
2289            } => {
2290                format!(
2291                    "Too many arguments for {}(): expected {}, got {}",
2292                    fn_name, expected, actual
2293                )
2294            }
2295            IssueKind::InvalidNamedArgument {
2296                fn_name,
2297                name,
2298                overwrites: true,
2299            } => {
2300                format!(
2301                    "{}() argument ${} overwrites a previous argument",
2302                    fn_name, name
2303                )
2304            }
2305            IssueKind::InvalidNamedArgument { fn_name, name, .. } => {
2306                format!("{}() has no parameter named ${}", fn_name, name)
2307            }
2308            IssueKind::InvalidNamedArguments { fn_name } => {
2309                format!("{}() does not accept named arguments", fn_name)
2310            }
2311            IssueKind::InvalidPassByReference { fn_name, param } => {
2312                format!(
2313                    "Argument ${} of {}() must be passed by reference",
2314                    param, fn_name
2315                )
2316            }
2317            IssueKind::InvalidPropertyFetch { ty } => {
2318                format!("Cannot fetch property on non-object type '{ty}'")
2319            }
2320            IssueKind::InvalidMethodCall { method, ty } => {
2321                format!("Cannot call method {method}() on non-object type '{ty}'")
2322            }
2323            IssueKind::InvalidMemberName { member, ty } if member == "method" => {
2324                format!("Method name must be a string, '{ty}' given")
2325            }
2326            IssueKind::InvalidMemberName { member, ty } => {
2327                format!("Object of type '{ty}' cannot be converted to a {member} name")
2328            }
2329            IssueKind::NativeResourceType { class } => {
2330                format!("'resource' is not a native type; PHP reads it as class '{class}', which no resource satisfies")
2331            }
2332            IssueKind::InvalidUnpack { ty } if ty.is_empty() => {
2333                "Only arrays and Traversables can be unpacked".to_string()
2334            }
2335            IssueKind::InvalidUnpack { ty } => {
2336                format!("Only arrays and Traversables can be unpacked, {ty} given")
2337            }
2338            IssueKind::InvalidArrayAccess { ty } => {
2339                format!("Cannot use [] operator on non-array type '{ty}'")
2340            }
2341            IssueKind::PossiblyInvalidArrayAccess { ty } => {
2342                format!("Possibly invalid array access: '{ty}' might not support []")
2343            }
2344            IssueKind::InvalidArrayAssignment { ty } => {
2345                format!("Cannot use [] assignment on non-array type '{ty}'")
2346            }
2347            IssueKind::InvalidPropertyAssignment {
2348                property,
2349                expected,
2350                actual,
2351            } => {
2352                format!("Property ${property} expects '{expected}', cannot assign '{actual}'")
2353            }
2354            IssueKind::PossiblyNullPropertyAssignmentValue {
2355                property,
2356                expected,
2357                actual,
2358            } => {
2359                format!("Property ${property} expects '{expected}', the assigned '{actual}' might be null")
2360            }
2361            IssueKind::PossiblyFalsePropertyAssignmentValue {
2362                property,
2363                expected,
2364                actual,
2365            } => {
2366                format!("Property ${property} expects '{expected}', the assigned '{actual}' might be false")
2367            }
2368            IssueKind::PossiblyInvalidPropertyAssignmentValue {
2369                property,
2370                expected,
2371                actual,
2372            } => {
2373                format!("Property ${property} expects '{expected}', the assigned '{actual}' might not match")
2374            }
2375            IssueKind::InvalidCast { from, to } => {
2376                format!("Cannot cast '{from}' to '{to}'")
2377            }
2378            IssueKind::InvalidStaticInvocation { class, method } => {
2379                format!("Non-static method {class}::{method}() cannot be called statically")
2380            }
2381            IssueKind::InvalidOperand { op, left, right } => {
2382                if right.is_empty() {
2383                    format!("Operator '{op}' not supported for operand of type '{left}'")
2384                } else {
2385                    format!("Operator '{op}' not supported between '{left}' and '{right}'")
2386                }
2387            }
2388            IssueKind::PossiblyInvalidOperand { op, left, right } => {
2389                format!("Operator '{op}' might not be supported between '{left}' and '{right}'")
2390            }
2391            IssueKind::PossiblyNullOperand { op, ty } => {
2392                format!("Operator '{op}' operand '{ty}' might be null")
2393            }
2394            IssueKind::DivisionByZero { op } => {
2395                format!("Division by zero: right operand of '{op}' is always 0")
2396            }
2397            IssueKind::RawObjectIteration { ty } => {
2398                format!("Cannot iterate over non-iterable object '{ty}'")
2399            }
2400            IssueKind::PossiblyRawObjectIteration { ty } => {
2401                format!("Cannot iterate over possibly non-iterable object '{ty}'")
2402            }
2403            IssueKind::InvalidGeneratorIteration { ty, send } => {
2404                format!("foreach sends null to '{ty}', but its send type is '{send}'")
2405            }
2406            IssueKind::MismatchingDocblockReturnType { declared, inferred } => {
2407                format!("Docblock return type '{declared}' does not match inferred '{inferred}'")
2408            }
2409            IssueKind::MismatchingDocblockParamType {
2410                param,
2411                declared,
2412                inferred,
2413            } => {
2414                format!(
2415                    "Docblock type '{declared}' for ${param} does not match inferred '{inferred}'"
2416                )
2417            }
2418            IssueKind::TypeCheckMismatch {
2419                var,
2420                expected,
2421                actual,
2422            } => {
2423                format!("Type of {var} is expected to be {expected}, got {actual}")
2424            }
2425            IssueKind::Trace {
2426                variable,
2427                type_info,
2428            } => {
2429                format!("Type of ${variable} is {type_info}")
2430            }
2431
2432            IssueKind::InvalidArrayOffset { expected, actual } => {
2433                format!("Array offset expects '{expected}', got '{actual}'")
2434            }
2435            IssueKind::NonExistentArrayOffset { key } => {
2436                format!("Array offset '{key}' does not exist")
2437            }
2438            IssueKind::PossiblyInvalidArrayOffset { expected, actual } => {
2439                format!("Array offset might be invalid: expects '{expected}', got '{actual}'")
2440            }
2441            IssueKind::DuplicateArrayKey { key } => {
2442                format!("Array key {key} is duplicated — the earlier entry is silently overwritten")
2443            }
2444
2445            IssueKind::RedundantCondition {
2446                always_true,
2447                unreachable,
2448            } => match unreachable {
2449                Some(branch) => {
2450                    format!("Condition is always {always_true}, so the {branch} is never reached")
2451                }
2452                None => format!("Condition is always {always_true}, so the check is redundant"),
2453            },
2454            IssueKind::RedundantCast { from, to } => {
2455                format!("Casting '{from}' to '{to}' is redundant")
2456            }
2457            IssueKind::UnnecessaryVarAnnotation { var } => {
2458                format!("@var annotation for ${var} is unnecessary")
2459            }
2460            IssueKind::TypeDoesNotContainType { left, right } => {
2461                format!("Type '{left}' can never contain type '{right}'")
2462            }
2463            IssueKind::ParadoxicalCondition { value } => {
2464                format!("Value {value} is duplicated; this branch can never be reached")
2465            }
2466            IssueKind::UnhandledMatchCondition { detail } => {
2467                format!("Unhandled match condition: {detail}")
2468            }
2469            IssueKind::DocblockTypeContradiction { expr, declared } => {
2470                format!("Type '{declared}' makes '{expr}' impossible — this can never hold")
2471            }
2472            IssueKind::ImpossibleIdenticalComparison { op, left, right } => {
2473                let result = if op == "===" { "false" } else { "true" };
2474                format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be identical")
2475            }
2476            IssueKind::ImpossibleLooseComparison { op, left, right } => {
2477                let result = if op == "==" { "false" } else { "true" };
2478                format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be loosely equal")
2479            }
2480            IssueKind::UnevaluatedCode { reason } => reason.clone(),
2481            IssueKind::IfThisIsMismatch {
2482                class,
2483                method,
2484                expected,
2485                actual,
2486            } => {
2487                format!(
2488                    "Cannot call {class}::{method}() — @if-this-is requires $this to be '{expected}', but it is '{actual}'"
2489                )
2490            }
2491
2492            IssueKind::UnusedVariable { name } => format!("Variable ${name} is never read"),
2493            IssueKind::UnusedParam { name } => format!("Parameter ${name} is never used"),
2494            IssueKind::UnreachableCode => "Unreachable code detected".to_string(),
2495            IssueKind::UnusedMethod { class, method } => {
2496                format!("Private method {class}::{method}() is never called")
2497            }
2498            IssueKind::UnusedProperty { class, property } => {
2499                format!("Private property {class}::${property} is never read")
2500            }
2501            IssueKind::UnusedFunction { name } => {
2502                format!("Function {name}() is never called")
2503            }
2504            IssueKind::UnusedForeachValue { name } => {
2505                format!("Foreach value ${name} is never read")
2506            }
2507            IssueKind::UnusedClass { class } => {
2508                format!("Class {class} is never referenced")
2509            }
2510            IssueKind::UnusedConstant { class, constant } => {
2511                format!("Private constant {class}::{constant} is never used")
2512            }
2513            IssueKind::UnusedSuppress { kind } => {
2514                format!("Suppress annotation for '{kind}' is never used")
2515            }
2516            IssueKind::ArgumentTypeCoercion {
2517                param,
2518                fn_name,
2519                expected,
2520                actual,
2521            } => {
2522                format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}' — coercion may fail at runtime")
2523            }
2524            IssueKind::PropertyTypeCoercion {
2525                property,
2526                expected,
2527                actual,
2528            } => {
2529                format!("Property ${property} expects '{expected}', cannot assign '{actual}' — coercion may fail at runtime")
2530            }
2531            IssueKind::ImpurePropertyAssignment { property } => {
2532                format!("Assigning to property {property} of a parameter in a pure or external-mutation-free context")
2533            }
2534            IssueKind::ImpureMethodCall { method } => {
2535                format!("Calling impure method {method}() in a pure or immutable context")
2536            }
2537            IssueKind::ImpureGlobalVariable { variable } => {
2538                format!("Using global variable ${variable} in a @pure function")
2539            }
2540            IssueKind::ImpureStaticVariable { variable } => {
2541                format!("Using static variable ${variable} in a @pure function")
2542            }
2543            IssueKind::ImpureByRefAssignment { variable } => {
2544                format!("Assigning to by-reference parameter ${variable} in a @pure function")
2545            }
2546            IssueKind::ImpureStaticPropertyAssignment { class, property } => {
2547                format!("Assigning to static property {class}::${property} in a @pure function")
2548            }
2549            IssueKind::ImpureStaticPropertyAccess { class, property } => {
2550                format!("Reading static property {class}::${property} in a @pure function")
2551            }
2552            IssueKind::ImpureFunctionCall { fn_name } => {
2553                format!("Calling impure function {fn_name}() in a @pure function")
2554            }
2555            IssueKind::ImmutablePropertyModification { receiver, property } => {
2556                format!("Assigning to property {property} of {receiver} in an immutable context (@psalm-immutable class or @psalm-mutation-free method)")
2557            }
2558
2559            IssueKind::UnimplementedAbstractMethod { class, method } => {
2560                format!("Class {class} must implement abstract method {method}()")
2561            }
2562            IssueKind::UnimplementedInterfaceMethod {
2563                class,
2564                interface,
2565                method,
2566            } => {
2567                format!("Class {class} must implement {interface}::{method}() from interface")
2568            }
2569            IssueKind::MethodSignatureMismatch {
2570                class,
2571                method,
2572                detail,
2573            } => {
2574                format!("Method {class}::{method}() signature mismatch: {detail}")
2575            }
2576            IssueKind::OverriddenMethodAccess {
2577                class,
2578                method,
2579                parent,
2580                visibility,
2581            } => {
2582                let weaker = if visibility == "public" {
2583                    ""
2584                } else {
2585                    " or weaker"
2586                };
2587                format!("Access level to {class}::{method}() must be {visibility} (as in class {parent}){weaker}")
2588            }
2589            IssueKind::OverriddenPropertyAccess {
2590                class,
2591                property,
2592                parent,
2593                visibility,
2594            } => {
2595                let weaker = if visibility == "public" {
2596                    ""
2597                } else {
2598                    " or weaker"
2599                };
2600                format!("Access level to {class}::${property} must be {visibility} (as in class {parent}){weaker}")
2601            }
2602            IssueKind::PropertyTypeRedeclarationMismatch {
2603                class,
2604                property,
2605                parent,
2606                expected,
2607                covariant,
2608                before_php85,
2609            } => {
2610                if expected.is_empty() && *before_php85 {
2611                    format!(
2612                        "Type of {class}::${property} must not be defined (as in class {parent})"
2613                    )
2614                } else if expected.is_empty() {
2615                    format!(
2616                        "Type of {class}::${property} must be omitted to match the parent definition in class {parent}"
2617                    )
2618                } else {
2619                    let subtype = if *covariant { "subtype of " } else { "" };
2620                    format!(
2621                        "Type of {class}::${property} must be {subtype}{expected} (as in class {parent})"
2622                    )
2623                }
2624            }
2625            IssueKind::NonInvariantDocblockPropertyType {
2626                class,
2627                property,
2628                parent,
2629                expected,
2630                actual,
2631            } => format!(
2632                "Docblock type '{actual}' of {class}::${property} is not invariant with '{expected}' in class {parent}"
2633            ),
2634            IssueKind::ReadonlyPropertyRedeclarationMismatch {
2635                parent_class,
2636                class,
2637                property,
2638                parent_readonly,
2639            } => {
2640                if *parent_readonly {
2641                    format!(
2642                        "Cannot redeclare readonly property {parent_class}::${property} as non-readonly {class}::${property}"
2643                    )
2644                } else {
2645                    format!(
2646                        "Cannot redeclare non-readonly property {parent_class}::${property} as readonly {class}::${property}"
2647                    )
2648                }
2649            }
2650            IssueKind::StaticPropertyRedeclarationMismatch {
2651                parent_class,
2652                class,
2653                property,
2654                parent_static,
2655            } => {
2656                if *parent_static {
2657                    format!(
2658                        "Cannot redeclare static property {parent_class}::${property} as non-static {class}::${property}"
2659                    )
2660                } else {
2661                    format!(
2662                        "Cannot redeclare non-static property {parent_class}::${property} as static {class}::${property}"
2663                    )
2664                }
2665            }
2666            IssueKind::BackedEnumCaseTypeMismatch {
2667                expected, actual, ..
2668            } => format!("Enum case type {actual} does not match enum backing type {expected}"),
2669            IssueKind::DuplicateEnumCaseValue {
2670                enum_name,
2671                first_case,
2672                case_name,
2673            } => {
2674                format!(
2675                    "Duplicate value in enum {enum_name} for cases {first_case} and {case_name}"
2676                )
2677            }
2678            IssueKind::ReadonlyClassExtendsMismatch {
2679                parent,
2680                child,
2681                parent_readonly,
2682            } => {
2683                if *parent_readonly {
2684                    format!("Non-readonly class {child} cannot extend readonly class {parent}")
2685                } else {
2686                    format!("Readonly class {child} cannot extend non-readonly class {parent}")
2687                }
2688            }
2689            IssueKind::InvalidReadonlyPropertyDeclaration { class, property } => {
2690                format!("Readonly property {class}::${property} cannot have default value")
2691            }
2692            IssueKind::ReadonlyPropertyAssignment {
2693                class,
2694                property,
2695                unset: true,
2696            } => format!("Cannot unset readonly property {class}::${property}"),
2697            IssueKind::ReadonlyPropertyAssignment {
2698                class, property, ..
2699            } => {
2700                format!(
2701                    "Cannot assign to readonly property {class}::${property} outside of constructor"
2702                )
2703            }
2704            IssueKind::ReadonlyPropertyAlreadyInitialized { class, property } => {
2705                format!(
2706                    "Cannot modify readonly property {class}::${property} — already initialized"
2707                )
2708            }
2709            IssueKind::InvalidExtendClass {
2710                parent,
2711                child,
2712                reason,
2713            } => match reason {
2714                Some(reason) => reason.clone(),
2715                None => format!("Class {child} cannot extend final class {parent}"),
2716            },
2717            IssueKind::InvalidTemplateParam {
2718                name,
2719                expected_bound,
2720                actual,
2721            } => {
2722                if actual.split('|').any(|part| part == "false") {
2723                    format!(
2724                        "Template type '{name}' inferred as '{actual}' can be false and therefore does not satisfy bound '{expected_bound}'"
2725                    )
2726                } else {
2727                    format!(
2728                        "Template type '{name}' inferred as '{actual}' does not satisfy bound '{expected_bound}'"
2729                    )
2730                }
2731            }
2732            IssueKind::ShadowedTemplateParam { name } => {
2733                format!(
2734                    "Method template parameter '{name}' shadows class-level template parameter with the same name"
2735                )
2736            }
2737            IssueKind::FinalMethodOverridden {
2738                class,
2739                method,
2740                parent,
2741            } => {
2742                format!("Method {class}::{method}() cannot override final method from {parent}")
2743            }
2744            IssueKind::AbstractInstantiation { class } => {
2745                format!("Cannot instantiate abstract class {class}")
2746            }
2747            IssueKind::AbstractMethodCall { class, method } => {
2748                format!("Cannot call abstract method {class}::{method}()")
2749            }
2750            IssueKind::InterfaceInstantiation { class } => {
2751                format!("Cannot instantiate interface {class}")
2752            }
2753            IssueKind::EnumInstantiation { class } => format!("Cannot instantiate enum {class}"),
2754            IssueKind::TraitInstantiation { class } => format!("Cannot instantiate trait {class}"),
2755            IssueKind::InvalidDynamicProperty { class, property } => {
2756                format!("Cannot create dynamic property {class}::${property}")
2757            }
2758            IssueKind::DynamicPropertyCreation { class, property } => {
2759                format!("Creation of dynamic property {class}::${property} is deprecated")
2760            }
2761            IssueKind::InvalidOverride { class, member } => {
2762                let kind = if member.starts_with('$') {
2763                    "property"
2764                } else if member.ends_with("()") {
2765                    "method"
2766                } else {
2767                    "constant"
2768                };
2769                format!(
2770                    "{class}::{member} has #[\\Override] attribute, but no matching parent {kind} exists"
2771                )
2772            }
2773
2774            IssueKind::TaintedInput { sink } => format!("Tainted input reaching sink '{sink}'"),
2775            IssueKind::TaintedHtml => "Tainted HTML output — possible XSS".to_string(),
2776            IssueKind::TaintedSql => "Tainted SQL query — possible SQL injection".to_string(),
2777            IssueKind::TaintedShell => {
2778                "Tainted shell command — possible command injection".to_string()
2779            }
2780            IssueKind::TaintedLlmPrompt => {
2781                "Tainted LLM prompt — possible prompt injection".to_string()
2782            }
2783            IssueKind::TaintedHeader => {
2784                "Tainted HTTP header — possible header injection or open redirect".to_string()
2785            }
2786            IssueKind::TaintedCookie => "Tainted cookie — possible cookie injection".to_string(),
2787            IssueKind::TaintedSsrf => {
2788                "Tainted URL — possible server-side request forgery".to_string()
2789            }
2790            IssueKind::TaintedLdap => "Tainted LDAP query — possible LDAP injection".to_string(),
2791            IssueKind::TaintedXpath => "Tainted XPath query — possible XPath injection".to_string(),
2792            IssueKind::TaintedCallable => {
2793                "Tainted callable — user input chooses the code that runs".to_string()
2794            }
2795            IssueKind::TaintedFile => "Tainted file path — possible path traversal".to_string(),
2796            IssueKind::TaintedInclude => {
2797                "Tainted include path — possible file inclusion".to_string()
2798            }
2799            IssueKind::TaintedEval => "Tainted code — possible code injection".to_string(),
2800            IssueKind::TaintedUnserialize => {
2801                "Tainted unserialize() payload — possible object injection".to_string()
2802            }
2803            IssueKind::TaintedMassAssignment { target } => format!("Tainted {target} — user input chooses what gets overwritten (mass assignment)"),
2804            IssueKind::TaintedCommandArgument => "Tainted command argument can start with '-' — possible argument injection".to_string(),
2805            IssueKind::QuotedShellEscape => "escapeshellarg() result placed inside quotes — its own quotes close them, so the value runs unquoted".to_string(),
2806            IssueKind::UnrestrictedFileUpload => "Uploaded file saved under the client's file name with no extension check — possible web shell upload".to_string(),
2807            IssueKind::HostHeaderInjection { target } => format!("{target} built from the request's Host header — the client can point it at their own server"),
2808            IssueKind::TaintedNoSql => "Tainted NoSQL query — possible NoSQL injection".to_string(),
2809            IssueKind::TaintedRegex => "Tainted regular expression — possible ReDoS or regex injection".to_string(),
2810            IssueKind::TaintedEnvironment => "Tainted environment or PHP setting — the client can switch the app's environment, inject LD_PRELOAD or change PHP's configuration".to_string(),
2811            IssueKind::UnescapedLikeWildcard => "Request data in a LIKE pattern without escaping % and _ — the client can match every row or force a slow scan".to_string(),
2812            IssueKind::UnquotedSqlEscape => "Quote-escaped request data placed in SQL outside quotes — escaping quotes doesn't stop injection there".to_string(),
2813            IssueKind::InsufficientHtmlEscape => "HTML-escaped request data placed where the escaping doesn't protect it — possible XSS".to_string(),
2814            IssueKind::MissingAuthorizationCheck { handler, missing, who } => format!("{handler} changes site state without {missing} — {who} can trigger it"),
2815            IssueKind::UntracedTaint { call, reason } => format!("Tainted data is passed to {call}, which can't be resolved because {reason}, so the sinks behind it aren't checked"),
2816            IssueKind::TaintedCsv => "Tainted CSV field — possible spreadsheet formula injection".to_string(),
2817            IssueKind::TaintedLog => "Tainted log message — possible log injection".to_string(),
2818            IssueKind::ResourceExhaustion { function } => format!("{function}() takes its size, count or duration straight from the request — possible denial of service"),
2819            IssueKind::SpoofableClientIp => "Client IP from a header the client can forge decides a check — possible IP allowlist bypass".to_string(),
2820            IssueKind::CodeAfterRedirect => "Location redirect isn't followed by exit — the code after it still runs".to_string(),
2821            IssueKind::InsecureCheckResult { reason } => format!("Insecure check: {reason}"),
2822            IssueKind::LdapAnonymousBind => "ldap_bind() with a request password that may be empty — an empty password is an anonymous bind, which succeeds".to_string(),
2823            IssueKind::InsecureFilePermissions { reason } => format!("Insecure file permissions: {reason}"),
2824            IssueKind::HardcodedCredential { what } => format!("Hard-coded credential: {what} is written in the source"),
2825            IssueKind::InsecureCors => "CORS reflects the request's Origin while allowing credentials — any site can read authenticated responses".to_string(),
2826            IssueKind::PredictableSeed { function } => format!("{function}() seeds the generator with a guessable value, so every mt_rand() and rand() result after it is predictable"),
2827            IssueKind::ObfuscatedCode => "Code run from decoded data — the shape of a web shell or backdoor".to_string(),
2828            IssueKind::InsecureTls { reason } => format!("TLS verification disabled: {reason} and anyone on the network can intercept the connection"),
2829            IssueKind::TimingUnsafeComparison { what } => format!("{what}, which returns sooner the fewer leading characters match; use hash_equals()"),
2830            IssueKind::MissingSensitiveParameter { param } => format!("Parameter ${param} looks like a secret but lacks #[\\SensitiveParameter], so its value can appear in stack traces and logs"),
2831            IssueKind::UnserializeGadget { class, method } => format!("{class}::{method}() makes a call an unserialized object controls: a dangerous call on its property, a method of any class, or any function"),
2832            IssueKind::UnsafeUnserialize => "unserialize() of non-literal data without allowed_classes can instantiate any class".to_string(),
2833            IssueKind::TaintedXml => "Tainted XML parsed with entity expansion, DTD loading or huge documents enabled — possible XXE or XML denial of service".to_string(),
2834            IssueKind::InsecureRandomness { context } => format!("Insecure randomness: {context} comes from a non-cryptographic generator; use random_bytes() or random_int()"),
2835            IssueKind::InsecureSessionConfig { reason } => format!("Insecure session handling: {reason}"),
2836            IssueKind::WeakCryptography { reason } => format!("Weak cryptography: {reason}"),
2837            IssueKind::InsecurePasswordHash { reason } => format!("Insecure password hashing: {reason}"),
2838
2839            IssueKind::DeprecatedCall { name, message } => {
2840                let base = format!("Call to deprecated function {name}");
2841                append_deprecation_message(base, message)
2842            }
2843            IssueKind::DeprecatedProperty {
2844                class,
2845                property,
2846                message,
2847            } => {
2848                let base = format!("Property {class}::${property} is deprecated");
2849                append_deprecation_message(base, message)
2850            }
2851            IssueKind::DeprecatedConstant {
2852                class,
2853                constant,
2854                message,
2855            } => {
2856                let base = format!("Constant {class}::{constant} is deprecated");
2857                append_deprecation_message(base, message)
2858            }
2859            IssueKind::OptionalParameterBeforeRequired { message }
2860            | IssueKind::ImplicitlyNullableParameter { message }
2861            | IssueKind::DeprecatedSyntax { message } => message.clone(),
2862            IssueKind::DeprecatedInterface { name, message } => {
2863                let base = format!("Interface {name} is deprecated");
2864                append_deprecation_message(base, message)
2865            }
2866            IssueKind::DeprecatedTrait { name, message } => {
2867                let base = format!("Trait {name} is deprecated");
2868                append_deprecation_message(base, message)
2869            }
2870            IssueKind::DeprecatedMethodCall {
2871                class,
2872                method,
2873                message,
2874            } => {
2875                let base = format!("Call to deprecated method {class}::{method}");
2876                append_deprecation_message(base, message)
2877            }
2878            IssueKind::DeprecatedMethod {
2879                class,
2880                method,
2881                message,
2882            } => {
2883                let base = format!("Method {class}::{method}() is deprecated");
2884                append_deprecation_message(base, message)
2885            }
2886            IssueKind::DeprecatedClass { name, message } => {
2887                let base = format!("Class {name} is deprecated");
2888                append_deprecation_message(base, message)
2889            }
2890            IssueKind::InternalMethod { class, method } => {
2891                format!("Method {class}::{method}() is marked @internal")
2892            }
2893            IssueKind::MissingReturnType { fn_name } => {
2894                format!("Function {fn_name}() has no return type annotation")
2895            }
2896            IssueKind::MissingClosureReturnType => {
2897                "Closure has no return type annotation".to_string()
2898            }
2899            IssueKind::MissingParamType { fn_name, param } => {
2900                format!("Parameter ${param} of {fn_name}() has no type annotation")
2901            }
2902            IssueKind::MissingPropertyType { class, property } => {
2903                format!("Property {class}::${property} has no type annotation")
2904            }
2905            IssueKind::InvalidThrow { ty } => {
2906                format!("Thrown type '{ty}' does not extend Throwable")
2907            }
2908            IssueKind::InvalidCatch { ty } => {
2909                format!("Caught type '{ty}' does not extend Throwable")
2910            }
2911            IssueKind::UnreachableCatch { ty, shadowed_by } => {
2912                format!("Catch block for '{ty}' is unreachable — already caught by '{shadowed_by}'")
2913            }
2914            IssueKind::MissingThrowsDocblock { class } => {
2915                format!("Exception {class} is thrown but not declared in @throws")
2916            }
2917            IssueKind::ImplicitToStringCast { class } => {
2918                format!("Class {class} is implicitly cast to string")
2919            }
2920            IssueKind::ImplicitFloatToIntCast { from } => {
2921                format!("Implicit cast from {from} to int truncates the fractional part")
2922            }
2923            IssueKind::ParseError { message, code } => format!("{message} [{code}]"),
2924            IssueKind::CompileError { message, code } => {
2925                format!("{message} [{code}]")
2926            }
2927            IssueKind::InvalidDocblock { message } => message.clone(),
2928            IssueKind::UndefinedThrowsDocblock { name } => {
2929                format!("@throws class '{name}' does not exist")
2930            }
2931            IssueKind::InvalidDocblockType { message } => message.clone(),
2932            IssueKind::MixedArgument { param, fn_name } => {
2933                format!("Argument ${param} of {fn_name}() is mixed")
2934            }
2935            IssueKind::MixedAssignment { var } => {
2936                format!("Variable ${var} is assigned a mixed type")
2937            }
2938            IssueKind::MixedMethodCall { method } => {
2939                format!("Method {method}() called on mixed type")
2940            }
2941            IssueKind::UnsupportedReferenceUsage => {
2942                "Reference assignment is not supported".to_string()
2943            }
2944            IssueKind::NoInterfaceProperties { property } => {
2945                format!("Property ${property} is not defined on this interface")
2946            }
2947            IssueKind::UndefinedDocblockClass { name } => {
2948                format!("Docblock type '{name}' does not exist")
2949            }
2950            IssueKind::MissingConstructor { class } => {
2951                format!("Class {class} has uninitialized properties but no constructor")
2952            }
2953            IssueKind::PropertyPossiblyUninitialized { class, property } => {
2954                format!(
2955                    "Property {class}::${property} may be left uninitialized by the constructor"
2956                )
2957            }
2958            IssueKind::MixedFunctionCall => "Cannot call mixed type as a function".to_string(),
2959            IssueKind::MixedReturnStatement { declared } => {
2960                format!("Cannot return a mixed type from function with declared return type '{declared}'")
2961            }
2962            IssueKind::MixedPropertyFetch { property } => {
2963                format!("Property ${property} fetched on mixed type")
2964            }
2965            IssueKind::MixedPropertyAssignment { property } => {
2966                format!("Property ${property} assigned on mixed type")
2967            }
2968            IssueKind::MixedArrayAccess => "Array access on mixed type".to_string(),
2969            IssueKind::MixedArrayOffset => "Mixed type used as array offset".to_string(),
2970            IssueKind::MixedClone => "cannot clone mixed".to_string(),
2971            IssueKind::InvalidClone { ty, reason } => match reason {
2972                CloneFailure::NonObject => format!("cannot clone non-object {ty}"),
2973                CloneFailure::Enum => {
2974                    format!("Trying to clone an uncloneable object of class {ty}")
2975                }
2976                CloneFailure::PrivateMethod { owner, scope } => match scope {
2977                    Some(scope) => {
2978                        format!("Call to private method {owner}::__clone() from scope {scope}")
2979                    }
2980                    None => format!("Call to private method {owner}::__clone() from global scope"),
2981                },
2982            },
2983            IssueKind::PossiblyInvalidClone { ty } => {
2984                format!("cannot clone possibly non-object {ty}")
2985            }
2986            IssueKind::InvalidToString { class } => {
2987                format!("Method {class}::__toString() must return a string")
2988            }
2989            IssueKind::CircularInheritance { class } => {
2990                format!("Class {class} has a circular inheritance chain")
2991            }
2992            IssueKind::InvalidTraitUse { trait_name, reason } => {
2993                format!("Trait {trait_name} used incorrectly: {reason}")
2994            }
2995            IssueKind::WrongCaseFunction { used, canonical } => {
2996                format!("Function name '{used}' has incorrect casing; use '{canonical}'")
2997            }
2998            IssueKind::WrongCaseMethod {
2999                class,
3000                used,
3001                canonical,
3002            } => {
3003                format!("Method name '{class}::{used}' has incorrect casing; use '{canonical}'")
3004            }
3005            IssueKind::WrongCaseClass { used, canonical } => {
3006                format!("Class name '{used}' has incorrect casing; use '{canonical}'")
3007            }
3008            IssueKind::InvalidAttribute { message } => message.clone(),
3009            IssueKind::UndefinedAttributeClass { name } => {
3010                format!("Attribute class {name} does not exist")
3011            }
3012            IssueKind::ForbiddenCode { message } => message.clone(),
3013            IssueKind::DuplicateClass { name } => {
3014                format!("Class {name} has already been defined")
3015            }
3016            IssueKind::DuplicateInterface { name } => {
3017                format!("Interface {name} has already been defined")
3018            }
3019            IssueKind::DuplicateTrait { name } => {
3020                format!("Trait {name} has already been defined")
3021            }
3022            IssueKind::DuplicateEnum { name } => {
3023                format!("Enum {name} has already been defined")
3024            }
3025            IssueKind::DuplicateFunction { name } => {
3026                format!("Function {name}() has already been defined")
3027            }
3028            IssueKind::UseStatementHasNoEffect { name } => {
3029                format!("The use statement with non-compound name '{name}' has no effect")
3030            }
3031            IssueKind::PrivateFinalMethod { class, method } => {
3032                format!("Private method {class}::{method}() cannot be final as it is never overridden by other classes")
3033            }
3034            IssueKind::NoDiscardReturnIgnored { callee, message } => {
3035                let reason = message.as_deref().map(|m| format!(", {m}")).unwrap_or_default();
3036                format!("The return value of {callee}() should either be used or intentionally ignored by casting it as (void){reason}")
3037            }
3038            IssueKind::NonPublicMagicMethod { class, method } => {
3039                format!("The magic method {class}::{method}() must have public visibility")
3040            }
3041            IssueKind::AnalyzerError { message } => {
3042                format!("mir failed to analyze this file ({message}); please report it")
3043            }
3044            IssueKind::PluginIssue { message, .. } => message.clone(),
3045        }
3046    }
3047}
3048
3049// ---------------------------------------------------------------------------
3050// Issue
3051// ---------------------------------------------------------------------------
3052
3053/// One hop of user-controlled data on its way to a taint sink.
3054#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3055pub struct TaintStep {
3056    /// Source text of the expression holding the data at this hop.
3057    pub label: String,
3058    pub location: Location,
3059}
3060
3061#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3062pub struct Issue {
3063    pub kind: IssueKind,
3064    pub severity: Severity,
3065    pub location: Location,
3066    pub snippet: Option<String>,
3067    pub suppressed: bool,
3068    /// Where a taint issue's data came from, source first.
3069    #[serde(default)]
3070    pub taint_trace: Option<Box<[TaintStep]>>,
3071}
3072
3073impl Issue {
3074    pub fn new(kind: IssueKind, location: Location) -> Self {
3075        let severity = kind.default_severity();
3076        Self {
3077            severity,
3078            kind,
3079            location,
3080            snippet: None,
3081            suppressed: false,
3082            taint_trace: None,
3083        }
3084    }
3085
3086    pub fn with_snippet(mut self, snippet: impl Into<String>) -> Self {
3087        self.snippet = Some(snippet.into());
3088        self
3089    }
3090
3091    pub fn suppress(mut self) -> Self {
3092        self.suppressed = true;
3093        self
3094    }
3095}
3096
3097// ---------------------------------------------------------------------------
3098// IssueBuffer — collects issues for a single file pass
3099// ---------------------------------------------------------------------------
3100
3101#[derive(Debug, Default)]
3102pub struct IssueBuffer {
3103    issues: Vec<Issue>,
3104    seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
3105    /// Issue names suppressed at the file level (from `@psalm-suppress` / `@suppress` on the file docblock)
3106    file_suppressions: Vec<String>,
3107    discard: bool,
3108}
3109
3110impl IssueBuffer {
3111    pub fn new() -> Self {
3112        Self::default()
3113    }
3114
3115    pub fn discarding(mut self) -> Self {
3116        self.discard = true;
3117        self
3118    }
3119
3120    pub fn is_discarding(&self) -> bool {
3121        self.discard
3122    }
3123
3124    pub fn add(&mut self, issue: Issue) {
3125        if self.discard {
3126            return;
3127        }
3128        let key = (
3129            issue.kind.name(),
3130            issue.location.file.clone(),
3131            issue.location.line,
3132            issue.location.col_start,
3133        );
3134        if self.seen.insert(key) {
3135            self.issues.push(issue);
3136        }
3137    }
3138
3139    /// Whether an issue collected so far satisfies `pred`.
3140    pub fn any(&self, pred: impl Fn(&Issue) -> bool) -> bool {
3141        self.issues.iter().any(pred)
3142    }
3143
3144    /// True when an issue that already explains a constant condition (an
3145    /// impossible comparison) starts inside `span`.
3146    pub fn has_impossible_comparison_within(&self, span: &Location) -> bool {
3147        self.issues.iter().any(|i| {
3148            matches!(
3149                i.kind,
3150                IssueKind::ImpossibleIdenticalComparison { .. }
3151                    | IssueKind::ImpossibleLooseComparison { .. }
3152                    | IssueKind::DocblockTypeContradiction { .. }
3153                    | IssueKind::TypeDoesNotContainType { .. }
3154            ) && i.location.file == span.file
3155                && (i.location.line, i.location.col_start) >= (span.line, span.col_start)
3156                && (i.location.line, i.location.col_start) < (span.line_end, span.col_end)
3157        })
3158    }
3159
3160    pub fn add_suppression(&mut self, name: impl Into<String>) {
3161        self.file_suppressions.push(name.into());
3162    }
3163
3164    /// Consume the buffer and return unsuppressed issues.
3165    pub fn into_issues(self) -> Vec<Issue> {
3166        self.issues
3167            .into_iter()
3168            .filter(|i| !i.suppressed)
3169            .filter(|i| {
3170                !self
3171                    .file_suppressions
3172                    .iter()
3173                    .any(|s| s == i.kind.display_name())
3174            })
3175            .collect()
3176    }
3177
3178    /// Like `into_issues` but keeps suppressed issues (with `suppressed = true`)
3179    /// so callers that need to detect unused suppressions can see which issues
3180    /// were silenced. File-level suppressions are also marked `suppressed = true`
3181    /// rather than dropped.
3182    pub fn into_all_issues(self) -> Vec<Issue> {
3183        self.issues
3184            .into_iter()
3185            .map(|mut i| {
3186                if self
3187                    .file_suppressions
3188                    .iter()
3189                    .any(|s| s == i.kind.display_name())
3190                {
3191                    i.suppressed = true;
3192                }
3193                i
3194            })
3195            .collect()
3196    }
3197
3198    /// Mark all issues added since index `from` as suppressed if their issue
3199    /// name appears in `suppressions`. Used for `@psalm-suppress` / `@suppress` on statements.
3200    pub fn suppress_range(&mut self, from: usize, suppressions: &[String]) {
3201        if suppressions.is_empty() {
3202            return;
3203        }
3204        for issue in self.issues[from..].iter_mut() {
3205            if suppressions.iter().any(|s| s == issue.kind.display_name()) {
3206                issue.suppressed = true;
3207            }
3208        }
3209    }
3210
3211    /// Mark issues added since index `from` as suppressed when `pred` holds.
3212    pub fn suppress_range_where(&mut self, from: usize, pred: impl Fn(&Issue) -> bool) {
3213        for issue in self.issues[from..].iter_mut().filter(|i| pred(i)) {
3214            issue.suppressed = true;
3215        }
3216    }
3217
3218    /// Current number of buffered issues. Use before analyzing a statement to
3219    /// get the `from` index for `suppress_range`.
3220    pub fn issue_count(&self) -> usize {
3221        self.issues.len()
3222    }
3223
3224    /// Discard every issue added since index `mark`, un-marking their
3225    /// locations as `seen` so a later `add()` at the same spot isn't silently
3226    /// deduplicated away. Used to roll back a speculative analysis pass (e.g.
3227    /// an unstabilized loop fixed-point iteration) whose diagnostics were
3228    /// provisional and must not leak into the final result.
3229    pub fn truncate_to(&mut self, mark: usize) {
3230        for issue in self.issues.drain(mark..) {
3231            let key = (
3232                issue.kind.name(),
3233                issue.location.file.clone(),
3234                issue.location.line,
3235                issue.location.col_start,
3236            );
3237            self.seen.remove(&key);
3238        }
3239    }
3240
3241    /// Remove and return the issues added since `mark` whose kind satisfies `pred`.
3242    pub fn take_since(&mut self, mark: usize, pred: impl Fn(&IssueKind) -> bool) -> Vec<Issue> {
3243        self.take_range(mark, self.issues.len(), pred)
3244    }
3245
3246    /// Like `take_since`, limited to issues before index `end`.
3247    pub fn take_range(
3248        &mut self,
3249        mark: usize,
3250        mut end: usize,
3251        pred: impl Fn(&IssueKind) -> bool,
3252    ) -> Vec<Issue> {
3253        let mut taken = Vec::new();
3254        let mut i = mark;
3255        while i < end {
3256            if pred(&self.issues[i].kind) {
3257                let issue = self.issues.remove(i);
3258                self.seen.remove(&(
3259                    issue.kind.name(),
3260                    issue.location.file.clone(),
3261                    issue.location.line,
3262                    issue.location.col_start,
3263                ));
3264                end -= 1;
3265                taken.push(issue);
3266            } else {
3267                i += 1;
3268            }
3269        }
3270        taken
3271    }
3272
3273    pub fn is_empty(&self) -> bool {
3274        self.issues.is_empty()
3275    }
3276
3277    pub fn len(&self) -> usize {
3278        self.issues.len()
3279    }
3280
3281    pub fn error_count(&self) -> usize {
3282        self.issues
3283            .iter()
3284            .filter(|i| !i.suppressed && i.severity == Severity::Error)
3285            .count()
3286    }
3287
3288    pub fn warning_count(&self) -> usize {
3289        self.issues
3290            .iter()
3291            .filter(|i| !i.suppressed && i.severity == Severity::Warning)
3292            .count()
3293    }
3294}
3295
3296#[cfg(test)]
3297mod code_tests {
3298    use super::*;
3299    use std::collections::HashSet;
3300
3301    /// Returns one instance of every `IssueKind` variant.
3302    ///
3303    /// Updating `IssueKind` without updating this list will compile (it's a
3304    /// regular `Vec`), but `codes_cover_every_variant` will catch the omission
3305    /// — the test below asserts the count matches the exhaustive `code()` arm.
3306    fn one_of_each() -> Vec<IssueKind> {
3307        let s = || String::new();
3308        vec![
3309            IssueKind::InvalidScope { in_class: false },
3310            IssueKind::NonStaticSelfCall {
3311                class: s(),
3312                method: s(),
3313            },
3314            IssueKind::DirectConstructorCall { class: s() },
3315            IssueKind::UndefinedVariable { name: s() },
3316            IssueKind::UndefinedFunction { name: s() },
3317            IssueKind::UndefinedMethod {
3318                class: s(),
3319                method: s(),
3320            },
3321            IssueKind::PossiblyUndefinedMethod {
3322                class: s(),
3323                method: s(),
3324            },
3325            IssueKind::UndefinedClass { name: s() },
3326            IssueKind::NotAnInterface { name: s() },
3327            IssueKind::UndefinedProperty {
3328                class: s(),
3329                property: s(),
3330            },
3331            IssueKind::UndefinedConstant { name: s() },
3332            IssueKind::InaccessibleClassConstant {
3333                class: s(),
3334                constant: s(),
3335            },
3336            IssueKind::InaccessibleProperty {
3337                class: s(),
3338                property: s(),
3339            },
3340            IssueKind::PossiblyUndefinedVariable { name: s() },
3341            IssueKind::UndefinedTrait { name: s() },
3342            IssueKind::TraitConstantAccessedDirectly {
3343                trait_name: s(),
3344                constant: s(),
3345            },
3346            IssueKind::UndefinedTraitAliasMethod {
3347                trait_name: Some(s()),
3348                method: s(),
3349            },
3350            IssueKind::ParentNotFound,
3351            IssueKind::NullArgument {
3352                param: s(),
3353                fn_name: s(),
3354            },
3355            IssueKind::NullPropertyFetch { property: s() },
3356            IssueKind::NullMethodCall { method: s() },
3357            IssueKind::NullArrayAccess,
3358            IssueKind::PossiblyNullArgument {
3359                param: s(),
3360                fn_name: s(),
3361            },
3362            IssueKind::PossiblyInvalidArgument {
3363                param: s(),
3364                fn_name: s(),
3365                expected: s(),
3366                actual: s(),
3367            },
3368            IssueKind::PossiblyNullPropertyFetch { property: s() },
3369            IssueKind::PossiblyNullMethodCall { method: s() },
3370            IssueKind::PossiblyNullArrayAccess,
3371            IssueKind::NullableReturnStatement {
3372                expected: s(),
3373                actual: s(),
3374            },
3375            IssueKind::InvalidReturnType {
3376                expected: s(),
3377                actual: s(),
3378            },
3379            IssueKind::LessSpecificReturnStatement {
3380                expected: s(),
3381                actual: s(),
3382            },
3383            IssueKind::InvalidArgument {
3384                param: s(),
3385                fn_name: s(),
3386                expected: s(),
3387                actual: s(),
3388            },
3389            IssueKind::InvalidScalarArgument {
3390                param: s(),
3391                fn_name: s(),
3392                expected: s(),
3393                actual: s(),
3394            },
3395            IssueKind::TooFewArguments {
3396                fn_name: s(),
3397                expected: 0,
3398                actual: 0,
3399            },
3400            IssueKind::TooManyArguments {
3401                fn_name: s(),
3402                expected: 0,
3403                actual: 0,
3404            },
3405            IssueKind::InvalidNamedArgument {
3406                fn_name: s(),
3407                name: s(),
3408                overwrites: false,
3409            },
3410            IssueKind::InvalidNamedArguments { fn_name: s() },
3411            IssueKind::InvalidPassByReference {
3412                fn_name: s(),
3413                param: s(),
3414            },
3415            IssueKind::InvalidPropertyFetch { ty: s() },
3416            IssueKind::InvalidMethodCall {
3417                method: s(),
3418                ty: s(),
3419            },
3420            IssueKind::InvalidMemberName {
3421                member: s(),
3422                ty: s(),
3423            },
3424            IssueKind::NativeResourceType { class: s() },
3425            IssueKind::InvalidUnpack { ty: s() },
3426            IssueKind::InvalidArrayAccess { ty: s() },
3427            IssueKind::PossiblyInvalidArrayAccess { ty: s() },
3428            IssueKind::InvalidArrayAssignment { ty: s() },
3429            IssueKind::InvalidPropertyAssignment {
3430                property: s(),
3431                expected: s(),
3432                actual: s(),
3433            },
3434            IssueKind::PossiblyNullPropertyAssignmentValue {
3435                property: s(),
3436                expected: s(),
3437                actual: s(),
3438            },
3439            IssueKind::PossiblyFalsePropertyAssignmentValue {
3440                property: s(),
3441                expected: s(),
3442                actual: s(),
3443            },
3444            IssueKind::PossiblyInvalidPropertyAssignmentValue {
3445                property: s(),
3446                expected: s(),
3447                actual: s(),
3448            },
3449            IssueKind::InvalidCast { from: s(), to: s() },
3450            IssueKind::InvalidStaticInvocation {
3451                class: s(),
3452                method: s(),
3453            },
3454            IssueKind::InvalidOperand {
3455                op: s(),
3456                left: s(),
3457                right: s(),
3458            },
3459            IssueKind::PossiblyInvalidOperand {
3460                op: s(),
3461                left: s(),
3462                right: s(),
3463            },
3464            IssueKind::PossiblyNullOperand { op: s(), ty: s() },
3465            IssueKind::DivisionByZero { op: s() },
3466            IssueKind::RawObjectIteration { ty: s() },
3467            IssueKind::PossiblyRawObjectIteration { ty: s() },
3468            IssueKind::InvalidGeneratorIteration { ty: s(), send: s() },
3469            IssueKind::MismatchingDocblockReturnType {
3470                declared: s(),
3471                inferred: s(),
3472            },
3473            IssueKind::MismatchingDocblockParamType {
3474                param: s(),
3475                declared: s(),
3476                inferred: s(),
3477            },
3478            IssueKind::TypeCheckMismatch {
3479                var: s(),
3480                expected: s(),
3481                actual: s(),
3482            },
3483            IssueKind::Trace {
3484                variable: s(),
3485                type_info: s(),
3486            },
3487            IssueKind::InvalidArrayOffset {
3488                expected: s(),
3489                actual: s(),
3490            },
3491            IssueKind::NonExistentArrayOffset { key: s() },
3492            IssueKind::PossiblyInvalidArrayOffset {
3493                expected: s(),
3494                actual: s(),
3495            },
3496            IssueKind::DuplicateArrayKey { key: s() },
3497            IssueKind::RedundantCondition {
3498                always_true: true,
3499                unreachable: None,
3500            },
3501            IssueKind::RedundantCast { from: s(), to: s() },
3502            IssueKind::UnnecessaryVarAnnotation { var: s() },
3503            IssueKind::TypeDoesNotContainType {
3504                left: s(),
3505                right: s(),
3506            },
3507            IssueKind::UnusedVariable { name: s() },
3508            IssueKind::UnusedParam { name: s() },
3509            IssueKind::UnreachableCode,
3510            IssueKind::UnhandledMatchCondition { detail: s() },
3511            IssueKind::UnusedMethod {
3512                class: s(),
3513                method: s(),
3514            },
3515            IssueKind::UnusedProperty {
3516                class: s(),
3517                property: s(),
3518            },
3519            IssueKind::UnusedFunction { name: s() },
3520            IssueKind::UnusedForeachValue { name: s() },
3521            IssueKind::UnusedClass { class: s() },
3522            IssueKind::UnusedConstant {
3523                class: s(),
3524                constant: s(),
3525            },
3526            IssueKind::UnusedSuppress { kind: s() },
3527            IssueKind::ArgumentTypeCoercion {
3528                param: s(),
3529                fn_name: s(),
3530                expected: s(),
3531                actual: s(),
3532            },
3533            IssueKind::PropertyTypeCoercion {
3534                property: s(),
3535                expected: s(),
3536                actual: s(),
3537            },
3538            IssueKind::ImpurePropertyAssignment { property: s() },
3539            IssueKind::ImpureMethodCall { method: s() },
3540            IssueKind::ImpureGlobalVariable { variable: s() },
3541            IssueKind::ImpureStaticVariable { variable: s() },
3542            IssueKind::ImpureByRefAssignment { variable: s() },
3543            IssueKind::ImpureStaticPropertyAssignment {
3544                class: s(),
3545                property: s(),
3546            },
3547            IssueKind::ImpureStaticPropertyAccess {
3548                class: s(),
3549                property: s(),
3550            },
3551            IssueKind::ImpureFunctionCall { fn_name: s() },
3552            IssueKind::ImmutablePropertyModification {
3553                receiver: s(),
3554                property: s(),
3555            },
3556            IssueKind::ReadonlyPropertyAssignment {
3557                class: s(),
3558                property: s(),
3559                unset: false,
3560            },
3561            IssueKind::ReadonlyPropertyAlreadyInitialized {
3562                class: s(),
3563                property: s(),
3564            },
3565            IssueKind::UnimplementedAbstractMethod {
3566                class: s(),
3567                method: s(),
3568            },
3569            IssueKind::UnimplementedInterfaceMethod {
3570                class: s(),
3571                interface: s(),
3572                method: s(),
3573            },
3574            IssueKind::MethodSignatureMismatch {
3575                class: s(),
3576                method: s(),
3577                detail: s(),
3578            },
3579            IssueKind::OverriddenMethodAccess {
3580                class: s(),
3581                method: s(),
3582                parent: s(),
3583                visibility: s(),
3584            },
3585            IssueKind::OverriddenPropertyAccess {
3586                class: s(),
3587                property: s(),
3588                parent: s(),
3589                visibility: s(),
3590            },
3591            IssueKind::PropertyTypeRedeclarationMismatch {
3592                class: s(),
3593                property: s(),
3594                parent: s(),
3595                expected: s(),
3596                covariant: false,
3597                before_php85: false,
3598            },
3599            IssueKind::NonInvariantDocblockPropertyType {
3600                class: s(),
3601                property: s(),
3602                parent: s(),
3603                expected: s(),
3604                actual: s(),
3605            },
3606            IssueKind::ReadonlyPropertyRedeclarationMismatch {
3607                parent_class: s(),
3608                class: s(),
3609                property: s(),
3610                parent_readonly: true,
3611            },
3612            IssueKind::StaticPropertyRedeclarationMismatch {
3613                parent_class: s(),
3614                class: s(),
3615                property: s(),
3616                parent_static: true,
3617            },
3618            IssueKind::ReadonlyClassExtendsMismatch {
3619                parent: s(),
3620                child: s(),
3621                parent_readonly: true,
3622            },
3623            IssueKind::InvalidReadonlyPropertyDeclaration {
3624                class: s(),
3625                property: s(),
3626            },
3627            IssueKind::BackedEnumCaseTypeMismatch {
3628                enum_name: s(),
3629                case_name: s(),
3630                expected: s(),
3631                actual: s(),
3632            },
3633            IssueKind::DuplicateEnumCaseValue {
3634                enum_name: s(),
3635                first_case: s(),
3636                case_name: s(),
3637            },
3638            IssueKind::InvalidExtendClass {
3639                parent: s(),
3640                child: s(),
3641                reason: None,
3642            },
3643            IssueKind::FinalMethodOverridden {
3644                class: s(),
3645                method: s(),
3646                parent: s(),
3647            },
3648            IssueKind::AbstractInstantiation { class: s() },
3649            IssueKind::AbstractMethodCall {
3650                class: s(),
3651                method: s(),
3652            },
3653            IssueKind::InterfaceInstantiation { class: s() },
3654            IssueKind::EnumInstantiation { class: s() },
3655            IssueKind::TraitInstantiation { class: s() },
3656            IssueKind::InvalidDynamicProperty {
3657                class: s(),
3658                property: s(),
3659            },
3660            IssueKind::DynamicPropertyCreation {
3661                class: s(),
3662                property: s(),
3663            },
3664            IssueKind::InvalidOverride {
3665                class: s(),
3666                member: s(),
3667            },
3668            IssueKind::CircularInheritance { class: s() },
3669            IssueKind::TaintedInput { sink: s() },
3670            IssueKind::TaintedHtml,
3671            IssueKind::TaintedSql,
3672            IssueKind::TaintedShell,
3673            IssueKind::TaintedLlmPrompt,
3674            IssueKind::TaintedHeader,
3675            IssueKind::TaintedCookie,
3676            IssueKind::TaintedSsrf,
3677            IssueKind::TaintedLdap,
3678            IssueKind::TaintedXpath,
3679            IssueKind::TaintedCallable,
3680            IssueKind::TaintedFile,
3681            IssueKind::TaintedInclude,
3682            IssueKind::TaintedEval,
3683            IssueKind::TaintedUnserialize,
3684            IssueKind::InsecurePasswordHash { reason: s() },
3685            IssueKind::WeakCryptography { reason: s() },
3686            IssueKind::InsecureSessionConfig { reason: s() },
3687            IssueKind::InsecureRandomness { context: s() },
3688            IssueKind::TaintedXml,
3689            IssueKind::UnsafeUnserialize,
3690            IssueKind::UnserializeGadget {
3691                class: s(),
3692                method: s(),
3693            },
3694            IssueKind::MissingSensitiveParameter { param: s() },
3695            IssueKind::ObfuscatedCode,
3696            IssueKind::InsecureTls { reason: s() },
3697            IssueKind::TimingUnsafeComparison { what: s() },
3698            IssueKind::PredictableSeed { function: s() },
3699            IssueKind::InsecureCors,
3700            IssueKind::HardcodedCredential { what: s() },
3701            IssueKind::InsecureFilePermissions { reason: s() },
3702            IssueKind::LdapAnonymousBind,
3703            IssueKind::InsecureCheckResult { reason: s() },
3704            IssueKind::CodeAfterRedirect,
3705            IssueKind::SpoofableClientIp,
3706            IssueKind::ResourceExhaustion { function: s() },
3707            IssueKind::TaintedLog,
3708            IssueKind::TaintedCsv,
3709            IssueKind::TaintedNoSql,
3710            IssueKind::TaintedRegex,
3711            IssueKind::TaintedEnvironment,
3712            IssueKind::UnescapedLikeWildcard,
3713            IssueKind::UnquotedSqlEscape,
3714            IssueKind::InsufficientHtmlEscape,
3715            IssueKind::MissingAuthorizationCheck {
3716                handler: s(),
3717                missing: s(),
3718                who: s(),
3719            },
3720            IssueKind::UntracedTaint {
3721                call: s(),
3722                reason: s(),
3723            },
3724            IssueKind::HostHeaderInjection { target: s() },
3725            IssueKind::UnrestrictedFileUpload,
3726            IssueKind::QuotedShellEscape,
3727            IssueKind::TaintedCommandArgument,
3728            IssueKind::TaintedMassAssignment { target: s() },
3729            IssueKind::InvalidTemplateParam {
3730                name: s(),
3731                expected_bound: s(),
3732                actual: s(),
3733            },
3734            IssueKind::ShadowedTemplateParam { name: s() },
3735            IssueKind::DeprecatedCall {
3736                name: s(),
3737                message: None,
3738            },
3739            IssueKind::DeprecatedProperty {
3740                class: s(),
3741                property: s(),
3742                message: None,
3743            },
3744            IssueKind::DeprecatedConstant {
3745                class: s(),
3746                constant: s(),
3747                message: None,
3748            },
3749            IssueKind::OptionalParameterBeforeRequired { message: s() },
3750            IssueKind::ImplicitlyNullableParameter { message: s() },
3751            IssueKind::DeprecatedSyntax { message: s() },
3752            IssueKind::DeprecatedInterface {
3753                name: s(),
3754                message: None,
3755            },
3756            IssueKind::DeprecatedTrait {
3757                name: s(),
3758                message: None,
3759            },
3760            IssueKind::DeprecatedMethodCall {
3761                class: s(),
3762                method: s(),
3763                message: None,
3764            },
3765            IssueKind::DeprecatedMethod {
3766                class: s(),
3767                method: s(),
3768                message: None,
3769            },
3770            IssueKind::DeprecatedClass {
3771                name: s(),
3772                message: None,
3773            },
3774            IssueKind::InternalMethod {
3775                class: s(),
3776                method: s(),
3777            },
3778            IssueKind::MissingReturnType { fn_name: s() },
3779            IssueKind::MissingClosureReturnType,
3780            IssueKind::MissingParamType {
3781                fn_name: s(),
3782                param: s(),
3783            },
3784            IssueKind::MissingPropertyType {
3785                class: s(),
3786                property: s(),
3787            },
3788            IssueKind::MissingThrowsDocblock { class: s() },
3789            IssueKind::InvalidDocblock { message: s() },
3790            IssueKind::UndefinedThrowsDocblock { name: s() },
3791            IssueKind::InvalidDocblockType { message: s() },
3792            IssueKind::MixedArgument {
3793                param: s(),
3794                fn_name: s(),
3795            },
3796            IssueKind::MixedAssignment { var: s() },
3797            IssueKind::MixedMethodCall { method: s() },
3798            IssueKind::UnsupportedReferenceUsage,
3799            IssueKind::NoInterfaceProperties { property: s() },
3800            IssueKind::UndefinedDocblockClass { name: s() },
3801            IssueKind::MissingConstructor { class: s() },
3802            IssueKind::PropertyPossiblyUninitialized {
3803                class: s(),
3804                property: s(),
3805            },
3806            IssueKind::MixedFunctionCall,
3807            IssueKind::MixedReturnStatement { declared: s() },
3808            IssueKind::MixedPropertyFetch { property: s() },
3809            IssueKind::MixedPropertyAssignment { property: s() },
3810            IssueKind::MixedArrayAccess,
3811            IssueKind::MixedArrayOffset,
3812            IssueKind::MixedClone,
3813            IssueKind::InvalidClone {
3814                ty: s(),
3815                reason: CloneFailure::NonObject,
3816            },
3817            IssueKind::PossiblyInvalidClone { ty: s() },
3818            IssueKind::InvalidToString { class: s() },
3819            IssueKind::InvalidTraitUse {
3820                trait_name: s(),
3821                reason: s(),
3822            },
3823            IssueKind::ParseError {
3824                message: s(),
3825                code: s(),
3826            },
3827            IssueKind::CompileError {
3828                message: s(),
3829                code: s(),
3830            },
3831            IssueKind::InvalidThrow { ty: s() },
3832            IssueKind::InvalidCatch { ty: s() },
3833            IssueKind::UnreachableCatch {
3834                ty: s(),
3835                shadowed_by: s(),
3836            },
3837            IssueKind::ImplicitToStringCast { class: s() },
3838            IssueKind::ImplicitFloatToIntCast { from: s() },
3839            IssueKind::WrongCaseFunction {
3840                used: s(),
3841                canonical: s(),
3842            },
3843            IssueKind::WrongCaseMethod {
3844                class: s(),
3845                used: s(),
3846                canonical: s(),
3847            },
3848            IssueKind::WrongCaseClass {
3849                used: s(),
3850                canonical: s(),
3851            },
3852            IssueKind::InvalidAttribute { message: s() },
3853            IssueKind::UndefinedAttributeClass { name: s() },
3854            IssueKind::ForbiddenCode { message: s() },
3855            IssueKind::DuplicateClass { name: s() },
3856            IssueKind::DuplicateInterface { name: s() },
3857            IssueKind::DuplicateTrait { name: s() },
3858            IssueKind::DuplicateEnum { name: s() },
3859            IssueKind::DuplicateFunction { name: s() },
3860            IssueKind::UseStatementHasNoEffect { name: s() },
3861            IssueKind::PrivateFinalMethod {
3862                class: s(),
3863                method: s(),
3864            },
3865            IssueKind::NonPublicMagicMethod {
3866                class: s(),
3867                method: s(),
3868            },
3869            IssueKind::NoDiscardReturnIgnored {
3870                callee: s(),
3871                message: None,
3872            },
3873            IssueKind::AnalyzerError { message: s() },
3874        ]
3875    }
3876
3877    #[test]
3878    fn codes_have_expected_shape() {
3879        for kind in one_of_each() {
3880            let code = kind.code();
3881            assert!(
3882                code.len() == 7
3883                    && code.starts_with("MIR")
3884                    && code[3..].chars().all(|c| c.is_ascii_digit()),
3885                "code {code:?} for {} does not match MIR####",
3886                kind.name(),
3887            );
3888        }
3889    }
3890
3891    #[test]
3892    fn codes_are_unique() {
3893        let kinds = one_of_each();
3894        let mut seen: HashSet<&'static str> = HashSet::new();
3895        for kind in &kinds {
3896            assert!(
3897                seen.insert(kind.code()),
3898                "duplicate code {} (variant {})",
3899                kind.code(),
3900                kind.name(),
3901            );
3902        }
3903    }
3904
3905    #[test]
3906    fn default_severity_for_code_round_trips() {
3907        for kind in one_of_each() {
3908            let code = kind.code();
3909            assert_eq!(
3910                IssueKind::default_severity_for_code(code),
3911                Some(kind.default_severity()),
3912                "severity mismatch for {code} (variant {})",
3913                kind.name(),
3914            );
3915        }
3916    }
3917
3918    #[test]
3919    fn default_severity_for_code_unknown_returns_none() {
3920        assert_eq!(IssueKind::default_severity_for_code("MIR9999"), None);
3921        assert_eq!(IssueKind::default_severity_for_code(""), None);
3922        assert_eq!(IssueKind::default_severity_for_code("mir0001"), None);
3923    }
3924
3925    /// Guards against forgetting to add a new variant to `one_of_each()`.
3926    /// If you add a variant, add it to `one_of_each()` *and* bump this count.
3927    #[test]
3928    fn one_of_each_has_every_variant() {
3929        // If this assertion fires after you added a new variant, also add it
3930        // to `one_of_each()` so the uniqueness and shape tests cover it.
3931        assert_eq!(one_of_each().len(), 232);
3932    }
3933}