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
7// ---------------------------------------------------------------------------
8// Severity
9// ---------------------------------------------------------------------------
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
12pub enum Severity {
13    /// Only shown with `--show-info`
14    Info,
15    /// Warnings — shown at default level
16    Warning,
17    /// Errors — always shown; non-zero exit code
18    Error,
19}
20
21impl fmt::Display for Severity {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        match self {
24            Severity::Info => write!(f, "info"),
25            Severity::Warning => write!(f, "warning"),
26            Severity::Error => write!(f, "error"),
27        }
28    }
29}
30
31// ---------------------------------------------------------------------------
32// Location
33// ---------------------------------------------------------------------------
34
35pub use mir_types::Location;
36
37// ---------------------------------------------------------------------------
38// IssueKind
39// ---------------------------------------------------------------------------
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[non_exhaustive]
43pub enum IssueKind {
44    // --- Undefined ----------------------------------------------------------
45    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
46    /// Fixtures: `tests/fixtures/by-kind/invalid_scope/`.
47    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
48    /// Fixtures: `tests/fixtures/by-kind/invalid_scope/self_non_static_invocation.phpt`.
49    NonStaticSelfCall { class: String, method: String },
50    InvalidScope {
51        /// `true` when inside a class but in a static method; `false` when outside a class.
52        in_class: bool,
53    },
54    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
55    /// Fixtures: `tests/fixtures/by-kind/undefined_variable/`.
56    UndefinedVariable { name: String },
57    /// Emitted by `mir-analyzer/src/call/function.rs`.
58    /// Fixtures: `tests/fixtures/by-kind/undefined_function/`.
59    UndefinedFunction { name: String },
60    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
61    /// Fixtures: `tests/fixtures/by-kind/undefined_method/`.
62    UndefinedMethod { class: String, method: String },
63    /// Emitted by `mir-analyzer/src/batch/mod.rs`.
64    /// Fixtures: `tests/fixtures/by-kind/undefined_class/`.
65    UndefinedClass { name: String },
66    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
67    /// Fixtures: `tests/fixtures/by-kind/undefined_property/`.
68    UndefinedProperty { class: String, property: String },
69    /// A private or protected property is read from outside the scope PHP
70    /// visibility rules allow — a fatal error at runtime.
71    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
72    /// Fixtures: `tests/fixtures/by-kind/inaccessible_property/`.
73    InaccessibleProperty { class: String, property: String },
74    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
75    /// Fixtures: `tests/fixtures/by-kind/undefined_constant/`.
76    UndefinedConstant { name: String },
77    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
78    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/invalid_*_class_const_fetch*.phpt`.
79    InaccessibleClassConstant { class: String, constant: String },
80    /// Emitted by `mir-analyzer/src/expr/variables.rs`.
81    /// Fixtures: `tests/fixtures/by-kind/possibly_undefined_variable/`.
82    PossiblyUndefinedVariable { name: String },
83    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
84    /// Fixtures: `tests/fixtures/by-kind/undefined_trait/`.
85    UndefinedTrait { name: String },
86    /// A trait's constant is fetched directly (`SomeTrait::CONST`) rather
87    /// than through a class that `use`s it — a PHP fatal error regardless of
88    /// whether the constant exists, since a trait is never itself a valid
89    /// constant-access target.
90    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
91    /// Fixtures: `tests/fixtures/by-kind/undefined_class/trait_constant_accessed_directly*.phpt`.
92    TraitConstantAccessedDirectly {
93        trait_name: String,
94        constant: String,
95    },
96    /// A trait `use` adaptation (`use T { T::missing as alias; }`, or an
97    /// unqualified `as` naming no method any used trait declares) aliases a
98    /// method that doesn't exist — a PHP fatal error at class-declaration
99    /// time, checked the same way a bad `insteadof`/undefined trait already
100    /// is by `check_trait_constraints`.
101    /// Emitted by `mir-analyzer/src/body_analysis/classes.rs`.
102    /// Fixtures: `tests/fixtures/by-kind/undefined_method/trait_alias*.phpt`.
103    UndefinedTraitAliasMethod {
104        trait_name: Option<String>,
105        method: String,
106    },
107    /// Emitted when `parent::` is used in a class that has no parent.
108    /// Fixtures: `tests/fixtures/by-kind/undefined_class/no_parent*.phpt`.
109    ParentNotFound,
110    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
111    /// Fixtures: `tests/fixtures/by-kind/invalid_string_class/`.
112    InvalidStringClass { actual: String },
113    /// Emitted by `mir-analyzer/src/call/args/types.rs` when an `interface-string`-typed
114    /// argument names a class or trait that exists but is not an interface.
115    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/interface_string_*.phpt`.
116    NotAnInterface { name: String },
117
118    // --- Nullability --------------------------------------------------------
119    /// Emitted by `mir-analyzer/src/call/args.rs`.
120    /// Fixtures: `tests/fixtures/by-kind/null_argument/`.
121    NullArgument { param: String, fn_name: String },
122    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
123    /// Fixtures: `tests/fixtures/by-kind/null_property_fetch/`.
124    NullPropertyFetch { property: String },
125    /// Emitted by `mir-analyzer/src/call/method.rs`.
126    /// Fixtures: `tests/fixtures/by-kind/null_method_call/`.
127    NullMethodCall { method: String },
128    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
129    /// Fixtures: `tests/fixtures/by-kind/null_array_access/`.
130    NullArrayAccess,
131    /// Emitted by `mir-analyzer/src/call/args.rs`.
132    /// Fixtures: `tests/fixtures/by-kind/possibly_null_argument/`.
133    PossiblyNullArgument { param: String, fn_name: String },
134    /// Emitted by `mir-analyzer/src/call/args.rs`.
135    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_argument/`.
136    PossiblyInvalidArgument {
137        param: String,
138        fn_name: String,
139        expected: String,
140        actual: String,
141    },
142    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
143    /// Fixtures: `tests/fixtures/by-kind/possibly_null_property_fetch/`.
144    PossiblyNullPropertyFetch { property: String },
145    /// Emitted by `mir-analyzer/src/call/method.rs`.
146    /// Fixtures: `tests/fixtures/by-kind/possibly_null_method_call/`.
147    PossiblyNullMethodCall { method: String },
148    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
149    /// Fixtures: `tests/fixtures/by-kind/possibly_null_array_access/`.
150    PossiblyNullArrayAccess,
151    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
152    /// Fixtures: `tests/fixtures/by-kind/nullable_return_statement/`.
153    NullableReturnStatement { expected: String, actual: String },
154
155    // --- Type mismatches ----------------------------------------------------
156    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
157    /// Fixtures: `tests/fixtures/by-kind/invalid_return_type/`.
158    InvalidReturnType { expected: String, actual: String },
159    /// Emitted by `mir-analyzer/src/call/args.rs`.
160    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/`.
161    InvalidArgument {
162        param: String,
163        fn_name: String,
164        expected: String,
165        actual: String,
166    },
167    /// Emitted by `mir-analyzer/src/call/callable.rs`.
168    /// Fixtures: `tests/fixtures/by-kind/too_few_arguments/`.
169    TooFewArguments {
170        fn_name: String,
171        expected: usize,
172        actual: usize,
173    },
174    /// Emitted by `mir-analyzer/src/call/function.rs`.
175    /// Fixtures: `tests/fixtures/by-kind/too_many_arguments/`.
176    TooManyArguments {
177        fn_name: String,
178        expected: usize,
179        actual: usize,
180    },
181    /// Emitted by `mir-analyzer/src/call/args.rs`.
182    /// Fixtures: `tests/fixtures/by-kind/invalid_named_argument/`.
183    InvalidNamedArgument { fn_name: String, name: String },
184    /// Emitted when a function/method tagged `@no-named-arguments` is called with named args.
185    /// Fixtures: `tests/fixtures/by-kind/invalid_named_argument/`.
186    InvalidNamedArguments { fn_name: String },
187    /// Emitted by `mir-analyzer/src/call/args.rs`.
188    /// Fixtures: `tests/fixtures/by-kind/invalid_pass_by_reference/`.
189    InvalidPassByReference { fn_name: String, param: String },
190    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
191    /// Fixtures: `tests/fixtures/by-kind/invalid_property_fetch/bad_fetch.phpt`.
192    InvalidPropertyFetch { ty: String },
193    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
194    /// Fixtures: `tests/fixtures/by-kind/invalid_array_access/`.
195    InvalidArrayAccess { ty: String },
196    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
197    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_array_access/`.
198    PossiblyInvalidArrayAccess { ty: String },
199    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
200    /// Fixtures: `tests/fixtures/by-kind/invalid_array_assignment/`.
201    InvalidArrayAssignment { ty: String },
202    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
203    /// Fixtures: `tests/fixtures/by-kind/invalid_property_assignment/`.
204    InvalidPropertyAssignment {
205        property: String,
206        expected: String,
207        actual: String,
208    },
209    /// Emitted by `mir-analyzer/src/expr/casts.rs`.
210    /// Fixtures: `tests/fixtures/by-kind/invalid_cast/`.
211    InvalidCast { from: String, to: String },
212    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
213    /// Fixtures: `tests/fixtures/by-kind/undefined_method/static_invocation*.phpt`.
214    InvalidStaticInvocation { class: String, method: String },
215    /// Emitted by `mir-analyzer/src/expr/binary.rs` and `unary.rs` for operations on
216    /// non-numeric or non-bitwise-compatible operands.
217    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
218    InvalidOperand {
219        op: String,
220        left: String,
221        right: String,
222    },
223    /// Emitted when a union-typed operand has some non-numeric/non-stringifiable members.
224    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
225    PossiblyInvalidOperand {
226        op: String,
227        left: String,
228        right: String,
229    },
230    /// Emitted when a divisor operand could be null (potential division by zero).
231    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
232    PossiblyNullOperand { op: String, ty: String },
233    /// Emitted when a divisor operand is DEFINITELY the literal `0` — an
234    /// unconditional runtime `DivisionByZeroError`.
235    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
236    DivisionByZero { op: String },
237    /// Emitted when `yield from` is used with a non-iterable object (no Traversable).
238    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
239    RawObjectIteration { ty: String },
240    /// Emitted when `yield from` might be used with a non-iterable object.
241    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/`.
242    PossiblyRawObjectIteration { ty: String },
243    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
244    /// Fixtures: `tests/fixtures/by-kind/mismatching_docblock_return_type/`.
245    MismatchingDocblockReturnType { declared: String, inferred: String },
246    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
247    /// Fixtures: `tests/fixtures/by-kind/mismatching_docblock_param_type/`.
248    MismatchingDocblockParamType {
249        param: String,
250        declared: String,
251        inferred: String,
252    },
253    /// Emitted by `@mir-check EXPR is TYPE` docblock directives (test-only —
254    /// never raised by real analysis of user code). `var` is the checked
255    /// expression's source text verbatim (e.g. `$x`, `$h->status`,
256    /// `self::$prop`), already including any `$` it needs.
257    /// Fixtures: `tests/fixtures/by-kind/type_check_mismatch/`.
258    TypeCheckMismatch {
259        var: String,
260        expected: String,
261        actual: String,
262    },
263
264    /// Emitted by `@trace $var` docblock annotation. Shows inferred type.
265    /// Fixtures: `tests/fixtures/by-kind/trace/`.
266    Trace { variable: String, type_info: String },
267
268    // --- Array issues -------------------------------------------------------
269    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
270    /// Fixtures: `tests/fixtures/by-kind/invalid_array_offset/`.
271    InvalidArrayOffset { expected: String, actual: String },
272    /// Emitted by `mir-analyzer/src/expr/arrays.rs` when a TKeyedArray is accessed with
273    /// a literal key that does not exist in the shape.
274    /// Fixtures: `tests/fixtures/by-kind/invalid_array_offset/`.
275    NonExistentArrayOffset { key: String },
276    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
277    /// Fixtures: `tests/fixtures/by-kind/possibly_invalid_array_offset/`.
278    PossiblyInvalidArrayOffset { expected: String, actual: String },
279    /// Emitted by `mir-analyzer/src/expr/arrays.rs` when an array literal repeats
280    /// the same key — the earlier entry is silently overwritten at runtime,
281    /// almost always a copy-paste mistake.
282    /// Fixtures: `tests/fixtures/by-kind/duplicate_array_key/`.
283    DuplicateArrayKey { key: String },
284
285    // --- Redundancy ---------------------------------------------------------
286    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs`.
287    /// Fixtures: `tests/fixtures/by-kind/redundant_condition/`.
288    RedundantCondition { ty: String },
289    /// Emitted by `mir-analyzer/src/expr/casts.rs`.
290    /// Fixtures: `tests/fixtures/by-kind/redundant_cast/`.
291    RedundantCast { from: String, to: String },
292    /// Emitted by `mir-analyzer/src/stmt/mod.rs`.
293    /// Fixtures: `tests/fixtures/by-kind/unnecessary_var_annotation/`.
294    UnnecessaryVarAnnotation { var: String },
295    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
296    /// Fixtures: `tests/fixtures/by-kind/type_does_not_contain_type/`.
297    TypeDoesNotContainType { left: String, right: String },
298    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
299    /// Fixtures: `tests/fixtures/by-kind/paradoxical_condition/`.
300    ParadoxicalCondition { value: String },
301    /// A docblock-declared type makes a subsequent assertion or comparison
302    /// impossible (e.g. `assert($a < 4)` on a `@param int<5, max> $a`).
303    /// Emitted by `mir-analyzer/src/narrowing.rs`.
304    /// Fixtures: `tests/fixtures/by-kind/docblock_type_contradiction/`.
305    DocblockTypeContradiction { expr: String, declared: String },
306    /// A `===` or `!==` comparison between two types that can never be strictly
307    /// equal — e.g. `$int === $string` or `$obj !== null` where `$obj` is a
308    /// non-nullable typed value.
309    /// Emitted by `mir-analyzer/src/expr/binary.rs`.
310    /// Fixtures: `tests/fixtures/by-kind/impossible_identical_comparison/`.
311    ImpossibleIdenticalComparison {
312        op: String,
313        left: String,
314        right: String,
315    },
316    /// A `==` or `!=` comparison between two types that can never be loosely
317    /// equal in PHP — e.g. `$obj == null`, `$arr == "foo"`, or a non-empty
318    /// array `== false`.  PHP's type-juggling rules make these always false (or
319    /// always true for `!=`), which almost certainly indicates a logic bug.
320    /// Emitted by `mir-analyzer/src/expr/binary.rs`.
321    /// Fixtures: `tests/fixtures/by-kind/impossible_loose_comparison/`.
322    ImpossibleLooseComparison {
323        op: String,
324        left: String,
325        right: String,
326    },
327    /// A `switch`/`match` arm that can never be reached given the subject's
328    /// inferred type — most often a `gettype()` arm tested against a string
329    /// that `gettype()` never returns (e.g. `case "int"` — it returns
330    /// `"integer"`).
331    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` and `mir-analyzer/src/expr/conditional.rs`.
332    /// Fixtures: `tests/fixtures/by-kind/unevaluated_code/`.
333    UnevaluatedCode { reason: String },
334
335    // --- Dead code ----------------------------------------------------------
336    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
337    /// Fixtures: `tests/fixtures/by-kind/unused_variable/`.
338    UnusedVariable { name: String },
339    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
340    /// Fixtures: `tests/fixtures/by-kind/unused_param/`.
341    UnusedParam { name: String },
342    /// Emitted by `mir-analyzer/src/stmt/mod.rs`.
343    /// Fixtures: `tests/fixtures/by-kind/unreachable_code/`.
344    UnreachableCode,
345    /// Emitted by `mir-analyzer/src/expr/conditional.rs`.
346    /// Fixtures: `tests/fixtures/by-kind/unreachable_code/`.
347    UnhandledMatchCondition { detail: String },
348    /// Emitted by `mir-analyzer/src/dead_code.rs`.
349    /// Fixtures: `tests/fixtures/by-kind/unused_method/`.
350    UnusedMethod { class: String, method: String },
351    /// Emitted by `mir-analyzer/src/dead_code.rs`.
352    /// Fixtures: `tests/fixtures/by-kind/unused_property/`.
353    UnusedProperty { class: String, property: String },
354    /// Emitted by `mir-analyzer/src/dead_code.rs`.
355    /// Fixtures: `tests/fixtures/by-kind/unused_function/`.
356    UnusedFunction { name: String },
357    /// Emitted by `mir-analyzer/src/diagnostics.rs`.
358    /// Fixtures: `tests/fixtures/by-kind/unused_foreach_value/`.
359    UnusedForeachValue { name: String },
360    /// Emitted by `mir-analyzer/src/dead_code.rs`.
361    /// Fixtures: `tests/fixtures/by-kind/unused_class/`.
362    UnusedClass { class: String },
363    /// Emitted by `mir-analyzer/src/batch/mod.rs` when a `@psalm-suppress` /
364    /// `@mir-suppress` / `@suppress` annotation does not match any actual issue.
365    /// Fixtures: `tests/fixtures/by-kind/unused_suppress/`.
366    UnusedSuppress { kind: String },
367
368    /// Emitted by `mir-analyzer/src/call/args/types.rs`.
369    /// Fixtures: `tests/fixtures/by-kind/argument_type_coercion/`.
370    ArgumentTypeCoercion {
371        param: String,
372        fn_name: String,
373        expected: String,
374        actual: String,
375    },
376
377    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
378    /// Fixtures: `tests/fixtures/by-kind/property_type_coercion/`.
379    PropertyTypeCoercion {
380        property: String,
381        expected: String,
382        actual: String,
383    },
384
385    // --- Purity -------------------------------------------------------------
386    /// Emitted when a @pure function assigns to a parameter's property.
387    ImpurePropertyAssignment { property: String },
388    /// Emitted when a @pure function calls an impure method on a parameter.
389    ImpureMethodCall { method: String },
390    /// Emitted when a @pure function uses a global variable.
391    ImpureGlobalVariable { variable: String },
392    /// Emitted when a @pure function uses a static variable.
393    ImpureStaticVariable { variable: String },
394    /// Emitted when a @pure function assigns to a class static property
395    /// (`self::$x = ...`, `Foo::$x = ...`) — static properties are shared
396    /// external state, same as a global variable.
397    ImpureStaticPropertyAssignment { class: String, property: String },
398    /// Emitted when a @pure function reads a class static property
399    /// (`self::$x`, `Foo::$x`) — reading shared external state is just as
400    /// non-deterministic across calls as writing it, mirroring
401    /// `ImpureGlobalVariable`'s treatment of a superglobal read.
402    ImpureStaticPropertyAccess { class: String, property: String },
403    /// Emitted when a @pure function assigns to one of its own by-reference
404    /// parameters (`function f(int &$x) { $x = 1; }`) — this mutates
405    /// caller-visible state through the reference, a side effect @pure
406    /// forbids just as much as a global/static-variable write.
407    ImpureByRefAssignment { variable: String },
408    /// Emitted by `mir-analyzer/src/call/function.rs` when a `@pure` function calls a
409    /// non-pure named function.
410    /// Fixtures: `tests/fixtures/by-kind/impure_function_call/`.
411    ImpureFunctionCall { fn_name: String },
412    /// Emitted when a non-constructor method of a `@psalm-immutable` class assigns to a
413    /// `$this` property, or when ANY code writes to a property of an object whose class is
414    /// `@psalm-immutable` (`receiver` is the rendered receiver expression — `$this` for the
415    /// former, the actual receiver's source text, e.g. `$b`, for the latter).
416    /// Fixtures: `tests/fixtures/by-kind/immutable_property_modification/`.
417    ImmutablePropertyModification { receiver: String, property: String },
418
419    // --- Readonly -----------------------------------------------------------
420    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
421    /// Fixtures: `tests/fixtures/by-kind/readonly_property_assignment/`.
422    ReadonlyPropertyAssignment { class: String, property: String },
423    /// A second write to a readonly property in a scope where writes are
424    /// otherwise allowed (the declaring constructor, or any method for a
425    /// native `readonly` property) — PHP throws `Error: Cannot modify
426    /// readonly property ... once initialized` on the second write.
427    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
428    /// Fixtures: `tests/fixtures/by-kind/readonly_property_already_initialized/`.
429    ReadonlyPropertyAlreadyInitialized { class: String, property: String },
430
431    // --- Inheritance --------------------------------------------------------
432    /// Emitted by `mir-analyzer/src/class/mod.rs`.
433    /// Fixtures: `tests/fixtures/by-kind/unimplemented_abstract_method/`.
434    UnimplementedAbstractMethod { class: String, method: String },
435    /// Emitted by `mir-analyzer/src/class/mod.rs`.
436    /// Fixtures: `tests/fixtures/by-kind/unimplemented_interface_method/`.
437    UnimplementedInterfaceMethod {
438        class: String,
439        interface: String,
440        method: String,
441    },
442    /// Emitted by `mir-analyzer/src/class/mod.rs`.
443    /// Fixtures: `tests/fixtures/by-kind/method_signature_mismatch/`.
444    MethodSignatureMismatch {
445        class: String,
446        method: String,
447        detail: String,
448    },
449    /// Emitted by `mir-analyzer/src/class/mod.rs`.
450    /// Fixtures: `tests/fixtures/by-kind/overridden_method_access/`.
451    OverriddenMethodAccess { class: String, method: String },
452    /// Emitted by `mir-analyzer/src/class/mod.rs`.
453    /// Fixtures: `tests/fixtures/by-kind/overridden_property_access/`.
454    OverriddenPropertyAccess { class: String, property: String },
455    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
456    /// Fixtures: `tests/fixtures/by-kind/property_type_redeclaration_mismatch/`.
457    PropertyTypeRedeclarationMismatch {
458        class: String,
459        property: String,
460        expected: String,
461        actual: String,
462    },
463    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
464    /// Fixtures: `tests/fixtures/by-kind/readonly_property_redeclaration_mismatch/`.
465    ReadonlyPropertyRedeclarationMismatch {
466        parent_class: String,
467        class: String,
468        property: String,
469        /// True when the parent's property is readonly and the child drops it;
470        /// false when the parent's property is non-readonly and the child adds it.
471        parent_readonly: bool,
472    },
473    /// Emitted by `mir-analyzer/src/class/overrides.rs`.
474    /// Fixtures: `tests/fixtures/by-kind/static_property_redeclaration_mismatch/`.
475    StaticPropertyRedeclarationMismatch {
476        parent_class: String,
477        class: String,
478        property: String,
479        /// True when the parent's property is static and the child redeclares it as
480        /// instance; false when the parent's is instance and the child redeclares it static.
481        parent_static: bool,
482    },
483    /// A `readonly class` extends a non-readonly parent, or vice versa — PHP
484    /// requires both sides of an extends relationship to agree on the
485    /// whole-class `readonly` modifier.
486    /// Emitted by `mir-analyzer/src/class/mod.rs`.
487    /// Fixtures: `tests/fixtures/by-kind/readonly_class_extends_mismatch/`.
488    ReadonlyClassExtendsMismatch {
489        parent: String,
490        child: String,
491        /// True when the parent is readonly and the child isn't; false when
492        /// the child is readonly and the parent isn't.
493        parent_readonly: bool,
494    },
495    /// A native `readonly` property declaration carries a default value — a
496    /// PHP fatal. (The sibling untyped-readonly-property fatal is already
497    /// caught by the parser itself as a `ParseError`.)
498    /// Emitted by `mir-analyzer/src/collector/class.rs`.
499    /// Fixtures: `tests/fixtures/by-kind/invalid_readonly_property_declaration/`.
500    InvalidReadonlyPropertyDeclaration { class: String, property: String },
501    /// Emitted by `mir-analyzer/src/collector/enum.rs`.
502    /// Fixtures: `tests/fixtures/by-kind/backed_enum_case_type_mismatch/`.
503    BackedEnumCaseTypeMismatch {
504        enum_name: String,
505        case_name: String,
506        expected: String,
507        actual: String,
508    },
509    /// Emitted by `mir-analyzer/src/call/method.rs`.
510    /// Fixtures: `tests/fixtures/by-kind/undefined_method/direct_constructor_call*.phpt`.
511    DirectConstructorCall { class: String },
512    /// Emitted by `mir-analyzer/src/class/mod.rs`.
513    /// Fixtures: `tests/fixtures/by-kind/invalid_extend_class/`.
514    InvalidExtendClass { parent: String, child: String },
515    /// Emitted by `mir-analyzer/src/class/mod.rs`.
516    /// Fixtures: `tests/fixtures/by-kind/final_method_overridden/`.
517    FinalMethodOverridden {
518        class: String,
519        method: String,
520        parent: String,
521    },
522    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
523    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/`.
524    AbstractInstantiation { class: String },
525    /// Emitted by `mir-analyzer/src/call/static_call.rs`.
526    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/prevent_abstract_method_call.phpt`.
527    AbstractMethodCall { class: String, method: String },
528    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
529    /// Fixtures: `tests/fixtures/by-kind/abstract_instantiation/interface_instantiation.phpt`.
530    InterfaceInstantiation { class: String },
531    /// Emitted by `mir-analyzer/src/class/mod.rs` when `#[Override]` is declared
532    /// but no overridable parent method exists.
533    /// Fixtures: `tests/fixtures/by-kind/method_signature_mismatch/`.
534    InvalidOverride {
535        class: String,
536        method: String,
537        detail: String,
538    },
539
540    // --- Security (taint) ---------------------------------------------------
541    /// Not yet emitted (generic taint sink; specific sinks use `TaintedHtml`, `TaintedSql`, `TaintedShell`).
542    /// No fixtures yet.
543    TaintedInput { sink: String },
544    /// Emitted by `mir-analyzer/src/call/function.rs`.
545    /// Fixtures: `tests/fixtures/by-kind/tainted_html/`.
546    TaintedHtml,
547    /// Emitted by `mir-analyzer/src/call/function.rs`.
548    /// Fixtures: `tests/fixtures/by-kind/tainted_sql/`.
549    TaintedSql,
550    /// Emitted by `mir-analyzer/src/call/function.rs`.
551    /// Fixtures: `tests/fixtures/by-kind/tainted_shell/`.
552    TaintedShell,
553    /// Emitted by `mir-analyzer/src/call/method.rs` when a tainted value reaches a
554    /// `@taint-sink llm_prompt` annotated parameter.
555    /// Fixtures: `tests/fixtures/by-kind/tainted_llm_prompt/`.
556    TaintedLlmPrompt,
557
558    // --- Generics -----------------------------------------------------------
559    /// Emitted by `mir-analyzer/src/call/function.rs`.
560    /// Fixtures: `tests/fixtures/by-kind/invalid_template_param/`.
561    InvalidTemplateParam {
562        name: String,
563        expected_bound: String,
564        actual: String,
565    },
566    /// Emitted by `mir-analyzer/src/call/method.rs`.
567    /// Fixtures: `tests/fixtures/by-kind/shadowed_template_param/`.
568    ShadowedTemplateParam { name: String },
569    /// A method annotated `@if-this-is X<Y>` was called on a receiver whose
570    /// type does not satisfy that constraint.
571    /// Emitted by `mir-analyzer/src/call/method.rs`.
572    /// Fixtures: `tests/fixtures/by-kind/if_this_is_mismatch/`.
573    IfThisIsMismatch {
574        class: String,
575        method: String,
576        expected: String,
577        actual: String,
578    },
579
580    // --- Other --------------------------------------------------------------
581    /// Emitted by `mir-analyzer/src/call/function.rs`.
582    /// Fixtures: `tests/fixtures/by-kind/deprecated_call/`.
583    DeprecatedCall {
584        name: String,
585        message: Option<Arc<str>>,
586    },
587    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
588    /// Fixtures: `tests/fixtures/by-kind/undefined_property/deprecated_property_*.phpt`.
589    DeprecatedProperty {
590        class: String,
591        property: String,
592        message: Option<Arc<str>>,
593    },
594    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
595    /// Fixtures: `tests/fixtures/by-kind/deprecated_call/deprecated_class_const_fetch*.phpt`.
596    DeprecatedConstant {
597        class: String,
598        constant: String,
599        message: Option<Arc<str>>,
600    },
601    /// Emitted by `mir-analyzer/src/class/mod.rs`.
602    /// Fixtures: `tests/fixtures/by-kind/deprecated_interface/`.
603    DeprecatedInterface {
604        name: String,
605        message: Option<Arc<str>>,
606    },
607    /// Emitted by `mir-analyzer/src/class/mod.rs`.
608    /// Fixtures: `tests/fixtures/by-kind/deprecated_trait/`.
609    DeprecatedTrait {
610        name: String,
611        message: Option<Arc<str>>,
612    },
613    /// Emitted by `mir-analyzer/src/call/method.rs`.
614    /// Fixtures: `tests/fixtures/by-kind/deprecated_method_call/`.
615    DeprecatedMethodCall {
616        class: String,
617        method: String,
618        message: Option<Arc<str>>,
619    },
620    /// Emitted by `mir-analyzer/src/call/method.rs`.
621    /// Fixtures: `tests/fixtures/by-kind/deprecated_method/`.
622    DeprecatedMethod {
623        class: String,
624        method: String,
625        message: Option<Arc<str>>,
626    },
627    /// Emitted by `mir-analyzer/src/class/mod.rs`.
628    /// Fixtures: `tests/fixtures/by-kind/deprecated_class/`.
629    DeprecatedClass {
630        name: String,
631        message: Option<Arc<str>>,
632    },
633    /// Emitted by `mir-analyzer/src/call/method.rs`.
634    /// Fixtures: `tests/fixtures/by-kind/internal_method/`.
635    InternalMethod { class: String, method: String },
636    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
637    /// Fixtures: `tests/fixtures/by-kind/missing_return_type/`.
638    MissingReturnType { fn_name: String },
639    /// Emitted by `mir-analyzer/src/expr/closures.rs`.
640    /// Fixtures: `tests/fixtures/by-kind/missing_closure_return_type/`.
641    MissingClosureReturnType,
642    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
643    /// Fixtures: `tests/fixtures/by-kind/missing_param_type/`.
644    MissingParamType { fn_name: String, param: String },
645    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
646    /// Fixtures: `tests/fixtures/by-kind/missing_param_type/` (property variants).
647    MissingPropertyType { class: String, property: String },
648    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
649    /// Fixtures: `tests/fixtures/by-kind/invalid_throw/`.
650    InvalidThrow { ty: String },
651    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs`.
652    /// Fixtures: `tests/fixtures/by-kind/invalid_catch/`.
653    InvalidCatch { ty: String },
654    /// Emitted by `mir-analyzer/src/stmt/control_flow.rs` when a `catch` type is a
655    /// subtype of (or identical to) a type already caught by an earlier `catch`
656    /// clause on the same `try` — the later block can never run.
657    /// Fixtures: `tests/fixtures/by-kind/invalid_catch/`.
658    UnreachableCatch { ty: String, shadowed_by: String },
659    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
660    /// Fixtures: `tests/fixtures/by-kind/missing_throws_docblock/`.
661    MissingThrowsDocblock { class: String },
662    /// Emitted by `mir-analyzer/src/stmt/expressions.rs`.
663    /// Fixtures: `tests/fixtures/by-kind/implicit_to_string_cast/`.
664    ImplicitToStringCast { class: String },
665    /// Emitted by `mir-analyzer/src/call/args.rs`.
666    /// Fixtures: `tests/fixtures/by-kind/implicit_float_to_int_cast/`.
667    ImplicitFloatToIntCast { from: String },
668    /// Emitted by `mir-analyzer/src/parser/mod.rs`.
669    /// Fixtures: `tests/fixtures/by-kind/parse_error/`.
670    ParseError { message: String },
671    /// Emitted by `mir-analyzer/src/collector/annotation.rs`.
672    /// Fixtures: `tests/fixtures/by-kind/invalid_docblock/`.
673    InvalidDocblock { message: String },
674    /// Emitted by `mir-analyzer/src/call/args/types.rs`.
675    /// Fixtures: `tests/fixtures/by-kind/mixed_argument/`.
676    MixedArgument { param: String, fn_name: String },
677    /// Emitted by `mir-analyzer/src/expr/assignment.rs` and `mir-analyzer/src/stmt/control_flow.rs`.
678    /// Fixtures: `tests/fixtures/by-kind/mixed_assignment/`.
679    MixedAssignment { var: String },
680    /// Emitted by `mir-analyzer/src/call/method.rs`.
681    /// Fixtures: `tests/fixtures/by-kind/mixed_method_call/`.
682    MixedMethodCall { method: String },
683    /// Emitted when a PHP reference assignment is used (e.g. `$b = &$arr[$x]`).
684    /// Fixtures: `tests/fixtures/by-kind/unsupported_reference_usage/`.
685    UnsupportedReferenceUsage,
686    /// Emitted when a property is accessed on an interface that has `@seal-properties`
687    /// but the property is not declared with `@property`/`@property-read`/`@property-write`.
688    /// Fixtures: `tests/fixtures/by-kind/undefined_property/magic_interface_*.phpt`.
689    NoInterfaceProperties { property: String },
690    /// Emitted when a class referenced only in a docblock (`@return`, `@param`, etc.)
691    /// does not exist.
692    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/missing_class.phpt`.
693    UndefinedDocblockClass { name: String },
694    /// Emitted when a class with non-nullable uninitialized properties has no constructor.
695    /// Fixtures: `tests/fixtures/by-kind/missing_constructor/`.
696    MissingConstructor { class: String },
697    /// Emitted when the constructor has a reachable exit path that doesn't
698    /// assign a native-typed, non-nullable, default-less property declared
699    /// directly on the class — reading it afterward throws PHP's "must not
700    /// be accessed before initialization". Scoped to the class's own
701    /// properties only (a property inherited from a parent class is that
702    /// parent's own constructor's concern) and abstains entirely if the
703    /// constructor calls out to any method/function that could have
704    /// initialized the property on its behalf, to avoid flagging common
705    /// delegating-init patterns it can't see into.
706    /// Emitted by `mir-analyzer/src/body_analysis/classes.rs`.
707    /// Fixtures: `tests/fixtures/by-kind/property_possibly_uninitialized/`.
708    PropertyPossiblyUninitialized { class: String, property: String },
709    /// Emitted by `mir-analyzer/src/call/function.rs` when a dynamic call target is mixed.
710    /// Fixtures: `tests/fixtures/by-kind/mixed_function_call/`.
711    MixedFunctionCall,
712    /// Emitted by `mir-analyzer/src/stmt/flow.rs`.
713    /// Fixtures: `tests/fixtures/by-kind/mixed_return_statement/`.
714    MixedReturnStatement { declared: String },
715    /// Emitted by `mir-analyzer/src/expr/objects.rs`.
716    /// Fixtures: `tests/fixtures/by-kind/mixed_property_fetch/`.
717    MixedPropertyFetch { property: String },
718    /// Emitted by `mir-analyzer/src/expr/assignment.rs`.
719    /// Fixtures: `tests/fixtures/by-kind/mixed_property_assignment/`.
720    MixedPropertyAssignment { property: String },
721    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
722    /// Fixtures: `tests/fixtures/by-kind/mixed_array_access/`.
723    MixedArrayAccess,
724    /// Emitted by `mir-analyzer/src/expr/arrays.rs`.
725    /// Fixtures: `tests/fixtures/by-kind/mixed_array_offset/`.
726    MixedArrayOffset,
727    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
728    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`.
729    MixedClone,
730    /// `clone` of a value that is definitely not an object (e.g. `int`, `string`).
731    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
732    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`.
733    InvalidClone { ty: String },
734    /// `clone` of a union where some members are not objects (e.g. `int|Exception`).
735    /// Emitted by `mir-analyzer/src/expr/mod.rs`.
736    /// Fixtures: `tests/fixtures/by-kind/mixed_clone/`.
737    PossiblyInvalidClone { ty: String },
738    /// A `__toString` method that does not return a `string`.
739    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
740    /// Fixtures: `tests/fixtures/by-kind/implicit_to_string_cast/`.
741    InvalidToString { class: String },
742    /// Emitted by `mir-analyzer/src/class/mod.rs`.
743    /// Fixtures: `tests/fixtures/by-kind/circular_inheritance/`.
744    CircularInheritance { class: String },
745
746    // --- Trait constraints --------------------------------------------------
747    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
748    /// Fixtures: `tests/fixtures/by-kind/invalid_trait_use/`.
749    InvalidTraitUse { trait_name: String, reason: String },
750    /// Emitted by `mir-analyzer/src/expr/mod.rs` and `mir-analyzer/src/call/function.rs`.
751    /// Fixtures: `tests/fixtures/by-kind/invalid_operand/` (var_dump, shell_exec, backtick).
752    ForbiddenCode { message: String },
753
754    // --- Attribute validation -----------------------------------------------
755    /// Emitted by `mir-analyzer/src/attributes.rs`.
756    /// Fixtures: `tests/fixtures/by-kind/invalid_attribute/`.
757    InvalidAttribute { message: String },
758    /// Emitted by `mir-analyzer/src/attributes.rs`.
759    /// Fixtures: `tests/fixtures/by-kind/undefined_class/missing_attribute_on_*.phpt`.
760    UndefinedAttributeClass { name: String },
761
762    // --- Case sensitivity (PHP 8.6 deprecation) -----------------------------
763    /// Emitted by `mir-analyzer/src/call/function.rs`.
764    /// Fixtures: `tests/fixtures/by-kind/wrong_case_function/`.
765    WrongCaseFunction { used: String, canonical: String },
766    /// Emitted by `mir-analyzer/src/call/method.rs` and `src/call/static_call.rs`.
767    /// Fixtures: `tests/fixtures/by-kind/wrong_case_method/`.
768    WrongCaseMethod {
769        class: String,
770        used: String,
771        canonical: String,
772    },
773    /// Emitted by `mir-analyzer/src/expr/objects.rs` and `src/call/static_call.rs`.
774    /// Fixtures: `tests/fixtures/by-kind/wrong_case_class/`.
775    WrongCaseClass { used: String, canonical: String },
776    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
777    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/class_redefinition*.phpt`.
778    DuplicateClass { name: String },
779    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
780    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/interface_redefinition*.phpt`.
781    DuplicateInterface { name: String },
782    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
783    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/trait_redefinition*.phpt`.
784    DuplicateTrait { name: String },
785    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
786    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/enum_redefinition*.phpt`.
787    DuplicateEnum { name: String },
788    /// Emitted by `mir-analyzer/src/body_analysis/mod.rs`.
789    /// Fixtures: `tests/fixtures/by-kind/invalid_argument/function_redefinition*.phpt`.
790    DuplicateFunction { name: String },
791
792    // --- Plugins --------------------------------------------------------------
793    /// Raised by a registered plugin (mir-plugin). `name` is the plugin's own
794    /// issue identifier, used for display and suppression matching.
795    PluginIssue { name: String, message: String },
796}
797
798fn append_deprecation_message(base: String, message: &Option<Arc<str>>) -> String {
799    match message.as_deref().filter(|m| !m.is_empty()) {
800        Some(msg) => format!("{base}: {msg}"),
801        None => base,
802    }
803}
804
805impl IssueKind {
806    /// Default severity for this issue kind.
807    pub fn default_severity(&self) -> Severity {
808        match self {
809            // Errors (always blocking)
810            IssueKind::NonStaticSelfCall { .. }
811            | IssueKind::DirectConstructorCall { .. }
812            | IssueKind::InvalidScope { .. }
813            | IssueKind::UndefinedVariable { .. }
814            | IssueKind::UndefinedFunction { .. }
815            | IssueKind::UndefinedMethod { .. }
816            | IssueKind::UndefinedClass { .. }
817            | IssueKind::NotAnInterface { .. }
818            | IssueKind::UndefinedConstant { .. }
819            | IssueKind::InaccessibleClassConstant { .. }
820            | IssueKind::InaccessibleProperty { .. }
821            | IssueKind::InvalidReturnType { .. }
822            | IssueKind::InvalidArgument { .. }
823            | IssueKind::TooFewArguments { .. }
824            | IssueKind::TooManyArguments { .. }
825            | IssueKind::InvalidNamedArgument { .. }
826            | IssueKind::InvalidNamedArguments { .. }
827            | IssueKind::InvalidPassByReference { .. }
828            | IssueKind::InvalidThrow { .. }
829            | IssueKind::InvalidCatch { .. }
830            | IssueKind::InvalidStaticInvocation { .. }
831            | IssueKind::UnimplementedAbstractMethod { .. }
832            | IssueKind::UnimplementedInterfaceMethod { .. }
833            | IssueKind::MethodSignatureMismatch { .. }
834            | IssueKind::InvalidExtendClass { .. }
835            | IssueKind::FinalMethodOverridden { .. }
836            | IssueKind::AbstractInstantiation { .. }
837            | IssueKind::AbstractMethodCall { .. }
838            | IssueKind::InterfaceInstantiation { .. }
839            | IssueKind::InvalidOverride { .. }
840            | IssueKind::InvalidTemplateParam { .. }
841            | IssueKind::ReadonlyPropertyAssignment { .. }
842            | IssueKind::ReadonlyPropertyAlreadyInitialized { .. }
843            | IssueKind::ParseError { .. }
844            | IssueKind::TaintedInput { .. }
845            | IssueKind::TaintedHtml
846            | IssueKind::TaintedSql
847            | IssueKind::TaintedShell
848            | IssueKind::TaintedLlmPrompt
849            | IssueKind::CircularInheritance { .. }
850            | IssueKind::InvalidTraitUse { .. }
851            | IssueKind::UndefinedTrait { .. }
852            | IssueKind::TraitConstantAccessedDirectly { .. }
853            | IssueKind::UndefinedTraitAliasMethod { .. }
854            | IssueKind::InvalidClone { .. }
855            | IssueKind::InvalidToString { .. }
856            | IssueKind::TypeCheckMismatch { .. }
857            | IssueKind::PropertyTypeRedeclarationMismatch { .. }
858            | IssueKind::ReadonlyPropertyRedeclarationMismatch { .. }
859            | IssueKind::StaticPropertyRedeclarationMismatch { .. }
860            | IssueKind::ReadonlyClassExtendsMismatch { .. }
861            | IssueKind::InvalidReadonlyPropertyDeclaration { .. }
862            | IssueKind::BackedEnumCaseTypeMismatch { .. }
863            | IssueKind::DivisionByZero { .. }
864            | IssueKind::ParentNotFound => Severity::Error,
865            IssueKind::Trace { .. } => Severity::Info,
866
867            // Warnings (shown at default error level)
868            IssueKind::NullArgument { .. }
869            | IssueKind::NullPropertyFetch { .. }
870            | IssueKind::NullMethodCall { .. }
871            | IssueKind::NullArrayAccess
872            | IssueKind::NullableReturnStatement { .. }
873            | IssueKind::InvalidPropertyFetch { .. }
874            | IssueKind::InvalidArrayAccess { .. }
875            | IssueKind::InvalidArrayAssignment { .. }
876            | IssueKind::InvalidPropertyAssignment { .. }
877            | IssueKind::InvalidArrayOffset { .. }
878            | IssueKind::NonExistentArrayOffset { .. }
879            | IssueKind::PossiblyInvalidArrayOffset { .. }
880            | IssueKind::UndefinedProperty { .. }
881            | IssueKind::InvalidOperand { .. }
882            | IssueKind::OverriddenMethodAccess { .. }
883            | IssueKind::OverriddenPropertyAccess { .. }
884            | IssueKind::ImplicitToStringCast { .. }
885            | IssueKind::ImplicitFloatToIntCast { .. }
886            | IssueKind::UnusedVariable { .. }
887            | IssueKind::UnusedForeachValue { .. }
888            | IssueKind::ImpurePropertyAssignment { .. }
889            | IssueKind::ImpureMethodCall { .. }
890            | IssueKind::ImpureGlobalVariable { .. }
891            | IssueKind::ImpureStaticVariable { .. }
892            | IssueKind::ImpureStaticPropertyAssignment { .. }
893            | IssueKind::ImpureStaticPropertyAccess { .. }
894            | IssueKind::ImpureFunctionCall { .. }
895            | IssueKind::ImpureByRefAssignment { .. }
896            | IssueKind::ImmutablePropertyModification { .. }
897            | IssueKind::UnsupportedReferenceUsage
898            | IssueKind::ParadoxicalCondition { .. }
899            | IssueKind::UnhandledMatchCondition { .. }
900            | IssueKind::InvalidStringClass { .. }
901            | IssueKind::ImpossibleIdenticalComparison { .. }
902            | IssueKind::ImpossibleLooseComparison { .. }
903            | IssueKind::DuplicateArrayKey { .. }
904            | IssueKind::ForbiddenCode { .. }
905            | IssueKind::PropertyPossiblyUninitialized { .. } => Severity::Warning,
906
907            // PossiblyUndefined: shown at default error level (same as Warning)
908            IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
909
910            // Possibly-null / possibly-invalid (only shown in strict mode, level ≥ 7)
911            IssueKind::PossiblyNullArgument { .. }
912            | IssueKind::PossiblyInvalidArgument { .. }
913            | IssueKind::PossiblyNullPropertyFetch { .. }
914            | IssueKind::PossiblyNullMethodCall { .. }
915            | IssueKind::PossiblyNullArrayAccess
916            | IssueKind::PossiblyInvalidArrayAccess { .. }
917            | IssueKind::PossiblyInvalidClone { .. }
918            | IssueKind::PossiblyInvalidOperand { .. }
919            | IssueKind::PossiblyNullOperand { .. }
920            | IssueKind::PossiblyRawObjectIteration { .. } => Severity::Info,
921
922            IssueKind::RawObjectIteration { .. } => Severity::Warning,
923
924            // Info
925            IssueKind::RedundantCondition { .. }
926            | IssueKind::RedundantCast { .. }
927            | IssueKind::UnnecessaryVarAnnotation { .. }
928            | IssueKind::TypeDoesNotContainType { .. }
929            | IssueKind::DocblockTypeContradiction { .. }
930            | IssueKind::UnevaluatedCode { .. }
931            | IssueKind::IfThisIsMismatch { .. }
932            | IssueKind::UnusedParam { .. }
933            | IssueKind::UnreachableCode
934            | IssueKind::UnreachableCatch { .. }
935            | IssueKind::UnusedMethod { .. }
936            | IssueKind::UnusedProperty { .. }
937            | IssueKind::UnusedFunction { .. }
938            | IssueKind::UnusedClass { .. }
939            | IssueKind::UnusedSuppress { .. }
940            | IssueKind::ArgumentTypeCoercion { .. }
941            | IssueKind::PropertyTypeCoercion { .. }
942            | IssueKind::DeprecatedCall { .. }
943            | IssueKind::DeprecatedProperty { .. }
944            | IssueKind::DeprecatedConstant { .. }
945            | IssueKind::DeprecatedInterface { .. }
946            | IssueKind::DeprecatedTrait { .. }
947            | IssueKind::DeprecatedMethodCall { .. }
948            | IssueKind::DeprecatedMethod { .. }
949            | IssueKind::DeprecatedClass { .. }
950            | IssueKind::InternalMethod { .. }
951            | IssueKind::MissingReturnType { .. }
952            | IssueKind::MissingClosureReturnType
953            | IssueKind::MissingParamType { .. }
954            | IssueKind::MissingPropertyType { .. }
955            | IssueKind::MismatchingDocblockReturnType { .. }
956            | IssueKind::MismatchingDocblockParamType { .. }
957            | IssueKind::InvalidDocblock { .. }
958            | IssueKind::InvalidCast { .. }
959            | IssueKind::MixedArgument { .. }
960            | IssueKind::MixedAssignment { .. }
961            | IssueKind::MixedMethodCall { .. }
962            | IssueKind::NoInterfaceProperties { .. }
963            | IssueKind::UndefinedDocblockClass { .. }
964            | IssueKind::MissingConstructor { .. }
965            | IssueKind::MixedFunctionCall
966            | IssueKind::MixedReturnStatement { .. }
967            | IssueKind::MixedPropertyFetch { .. }
968            | IssueKind::MixedPropertyAssignment { .. }
969            | IssueKind::MixedArrayAccess
970            | IssueKind::MixedArrayOffset
971            | IssueKind::MixedClone
972            | IssueKind::ShadowedTemplateParam { .. }
973            | IssueKind::MissingThrowsDocblock { .. }
974            | IssueKind::WrongCaseFunction { .. }
975            | IssueKind::WrongCaseMethod { .. }
976            | IssueKind::WrongCaseClass { .. }
977            | IssueKind::InvalidAttribute { .. }
978            | IssueKind::UndefinedAttributeClass { .. } => Severity::Info,
979            IssueKind::DuplicateClass { .. }
980            | IssueKind::DuplicateInterface { .. }
981            | IssueKind::DuplicateTrait { .. }
982            | IssueKind::DuplicateEnum { .. }
983            | IssueKind::DuplicateFunction { .. } => Severity::Error,
984            // Plugins pick their own severity per issue; Error is only the
985            // fallback when none was set.
986            IssueKind::PluginIssue { .. } => Severity::Error,
987        }
988    }
989
990    /// Stable error code (e.g. `"MIR0005"`).
991    ///
992    /// Codes are assigned in bands by category and are part of the public API:
993    /// once a code ships, it must never be reused for a different issue kind.
994    /// New variants take the next free slot in their band; obsolete variants
995    /// retire their code (the slot stays burnt). Bands have headroom for growth.
996    ///
997    /// Bands:
998    ///
999    /// | Range         | Category                        |
1000    /// |---------------|---------------------------------|
1001    /// | 0001 – 0099   | Undefined symbols               |
1002    /// | 0100 – 0199   | Nullability                     |
1003    /// | 0200 – 0299   | Type mismatches                 |
1004    /// | 0300 – 0399   | Array / offset                  |
1005    /// | 0400 – 0499   | Redundancy                      |
1006    /// | 0500 – 0599   | Dead code                       |
1007    /// | 0600 – 0699   | Readonly                        |
1008    /// | 0700 – 0799   | Inheritance                     |
1009    /// | 0800 – 0899   | Security (taint)                |
1010    /// | 0900 – 0999   | Generics                        |
1011    /// | 1000 – 1099   | Deprecation / internal          |
1012    /// | 1100 – 1199   | Missing types / docblocks       |
1013    /// | 1200 – 1299   | Mixed                           |
1014    /// | 1300 – 1399   | Trait                           |
1015    /// | 1400 – 1499   | Parse                           |
1016    /// | 1500 – 1599   | Other                           |
1017    /// | 1600 – 1699   | Attribute / duplicate declarations |
1018    /// | 1700 – 1799   | Purity                          |
1019    pub fn code(&self) -> &'static str {
1020        match self {
1021            // Undefined (0001-0099)
1022            IssueKind::NonStaticSelfCall { .. } => "MIR0216",
1023            IssueKind::DirectConstructorCall { .. } => "MIR0217",
1024            IssueKind::InvalidScope { .. } => "MIR0001",
1025            IssueKind::UndefinedVariable { .. } => "MIR0002",
1026            IssueKind::UndefinedFunction { .. } => "MIR0003",
1027            IssueKind::UndefinedMethod { .. } => "MIR0004",
1028            IssueKind::UndefinedClass { .. } => "MIR0005",
1029            IssueKind::UndefinedProperty { .. } => "MIR0006",
1030            IssueKind::UndefinedConstant { .. } => "MIR0007",
1031            IssueKind::InaccessibleClassConstant { .. } => "MIR0011",
1032            IssueKind::InaccessibleProperty { .. } => "MIR0014",
1033            IssueKind::TraitConstantAccessedDirectly { .. } => "MIR0012",
1034            IssueKind::UndefinedTraitAliasMethod { .. } => "MIR0013",
1035            IssueKind::PossiblyUndefinedVariable { .. } => "MIR0008",
1036            IssueKind::UndefinedTrait { .. } => "MIR0009",
1037            IssueKind::ParentNotFound => "MIR0010",
1038
1039            // Nullability (0100-0199)
1040            IssueKind::NullArgument { .. } => "MIR0100",
1041            IssueKind::NullPropertyFetch { .. } => "MIR0101",
1042            IssueKind::NullMethodCall { .. } => "MIR0102",
1043            IssueKind::NullArrayAccess => "MIR0103",
1044            IssueKind::PossiblyNullArgument { .. } => "MIR0104",
1045            IssueKind::PossiblyInvalidArgument { .. } => "MIR0105",
1046            IssueKind::PossiblyNullPropertyFetch { .. } => "MIR0106",
1047            IssueKind::PossiblyNullMethodCall { .. } => "MIR0107",
1048            IssueKind::PossiblyNullArrayAccess => "MIR0108",
1049            IssueKind::NullableReturnStatement { .. } => "MIR0109",
1050
1051            // Type mismatches (0200-0299)
1052            IssueKind::InvalidReturnType { .. } => "MIR0200",
1053            IssueKind::InvalidArgument { .. } => "MIR0201",
1054            IssueKind::TooFewArguments { .. } => "MIR0202",
1055            IssueKind::TooManyArguments { .. } => "MIR0203",
1056            IssueKind::InvalidNamedArgument { .. } => "MIR0204",
1057            IssueKind::InvalidNamedArguments { .. } => "MIR0224",
1058            IssueKind::InvalidPassByReference { .. } => "MIR0205",
1059            IssueKind::InvalidPropertyFetch { .. } => "MIR0218",
1060            IssueKind::InvalidArrayAccess { .. } => "MIR0219",
1061            IssueKind::PossiblyInvalidArrayAccess { .. } => "MIR0227",
1062            IssueKind::InvalidArrayAssignment { .. } => "MIR0220",
1063            IssueKind::InvalidPropertyAssignment { .. } => "MIR0206",
1064            IssueKind::InvalidCast { .. } => "MIR0207",
1065            IssueKind::InvalidStaticInvocation { .. } => "MIR0215",
1066            IssueKind::InvalidOperand { .. } => "MIR0208",
1067            IssueKind::PossiblyInvalidOperand { .. } => "MIR0213",
1068            IssueKind::PossiblyNullOperand { .. } => "MIR0214",
1069            IssueKind::DivisionByZero { .. } => "MIR0229",
1070            IssueKind::RawObjectIteration { .. } => "MIR0222",
1071            IssueKind::PossiblyRawObjectIteration { .. } => "MIR0223",
1072            IssueKind::MismatchingDocblockReturnType { .. } => "MIR0209",
1073            IssueKind::MismatchingDocblockParamType { .. } => "MIR0210",
1074            IssueKind::InvalidStringClass { .. } => "MIR0211",
1075            IssueKind::NotAnInterface { .. } => "MIR0228",
1076            IssueKind::TypeCheckMismatch { .. } => "MIR0212",
1077            IssueKind::Trace { .. } => "MIR0221",
1078            IssueKind::ArgumentTypeCoercion { .. } => "MIR0225",
1079            IssueKind::PropertyTypeCoercion { .. } => "MIR0226",
1080
1081            // Array / offset (0300-0399)
1082            IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1083            IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1084            IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1085            IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1086
1087            // Redundancy (0400-0499)
1088            IssueKind::RedundantCondition { .. } => "MIR0400",
1089            IssueKind::RedundantCast { .. } => "MIR0401",
1090            IssueKind::UnnecessaryVarAnnotation { .. } => "MIR0402",
1091            IssueKind::TypeDoesNotContainType { .. } => "MIR0403",
1092            IssueKind::ParadoxicalCondition { .. } => "MIR0404",
1093            IssueKind::UnhandledMatchCondition { .. } => "MIR0405",
1094            IssueKind::DocblockTypeContradiction { .. } => "MIR0406",
1095            IssueKind::UnevaluatedCode { .. } => "MIR0407",
1096            IssueKind::ImpossibleIdenticalComparison { .. } => "MIR0408",
1097            IssueKind::ImpossibleLooseComparison { .. } => "MIR0409",
1098
1099            // Dead code (0500-0599)
1100            IssueKind::UnusedVariable { .. } => "MIR0500",
1101            IssueKind::UnusedParam { .. } => "MIR0501",
1102            IssueKind::UnreachableCode => "MIR0502",
1103            IssueKind::UnusedMethod { .. } => "MIR0503",
1104            IssueKind::UnusedProperty { .. } => "MIR0504",
1105            IssueKind::UnusedFunction { .. } => "MIR0505",
1106            IssueKind::UnusedForeachValue { .. } => "MIR0506",
1107            IssueKind::UnusedClass { .. } => "MIR0507",
1108            IssueKind::UnusedSuppress { .. } => "MIR0508",
1109
1110            // Purity (1700-1799)
1111            IssueKind::ImpurePropertyAssignment { .. } => "MIR1700",
1112            IssueKind::ImpureMethodCall { .. } => "MIR1701",
1113            IssueKind::ImpureGlobalVariable { .. } => "MIR1702",
1114            IssueKind::ImpureStaticVariable { .. } => "MIR1703",
1115            IssueKind::ImpureStaticPropertyAssignment { .. } => "MIR1706",
1116            IssueKind::ImpureByRefAssignment { .. } => "MIR1707",
1117            IssueKind::ImpureStaticPropertyAccess { .. } => "MIR1708",
1118            IssueKind::ImpureFunctionCall { .. } => "MIR1704",
1119            IssueKind::ImmutablePropertyModification { .. } => "MIR1705",
1120            IssueKind::UnsupportedReferenceUsage => "MIR1506",
1121            IssueKind::NoInterfaceProperties { .. } => "MIR1504",
1122            IssueKind::UndefinedDocblockClass { .. } => "MIR1505",
1123            IssueKind::MissingConstructor { .. } => "MIR1507",
1124            IssueKind::PropertyPossiblyUninitialized { .. } => "MIR1510",
1125            IssueKind::MixedFunctionCall => "MIR1211",
1126            IssueKind::MixedReturnStatement { .. } => "MIR1212",
1127
1128            // Readonly (0600-0699)
1129            IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1130            IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1131
1132            // Inheritance (0700-0799)
1133            IssueKind::UnimplementedAbstractMethod { .. } => "MIR0700",
1134            IssueKind::UnimplementedInterfaceMethod { .. } => "MIR0701",
1135            IssueKind::MethodSignatureMismatch { .. } => "MIR0702",
1136            IssueKind::OverriddenMethodAccess { .. } => "MIR0703",
1137            IssueKind::OverriddenPropertyAccess { .. } => "MIR0710",
1138            IssueKind::PropertyTypeRedeclarationMismatch { .. } => "MIR0712",
1139            IssueKind::BackedEnumCaseTypeMismatch { .. } => "MIR0713",
1140            IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => "MIR0714",
1141            IssueKind::StaticPropertyRedeclarationMismatch { .. } => "MIR0715",
1142            IssueKind::ReadonlyClassExtendsMismatch { .. } => "MIR0716",
1143            IssueKind::InvalidReadonlyPropertyDeclaration { .. } => "MIR0717",
1144            IssueKind::InvalidExtendClass { .. } => "MIR0704",
1145            IssueKind::FinalMethodOverridden { .. } => "MIR0705",
1146            IssueKind::AbstractInstantiation { .. } => "MIR0706",
1147            IssueKind::AbstractMethodCall { .. } => "MIR0711",
1148            IssueKind::InterfaceInstantiation { .. } => "MIR0709",
1149            IssueKind::CircularInheritance { .. } => "MIR0707",
1150            IssueKind::InvalidOverride { .. } => "MIR0708",
1151
1152            // Security / taint (0800-0899)
1153            IssueKind::TaintedInput { .. } => "MIR0800",
1154            IssueKind::TaintedHtml => "MIR0801",
1155            IssueKind::TaintedSql => "MIR0802",
1156            IssueKind::TaintedShell => "MIR0803",
1157            IssueKind::TaintedLlmPrompt => "MIR0804",
1158
1159            // Generics (0900-0999)
1160            IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1161            IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1162            IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1163
1164            // Deprecation / internal (1000-1099)
1165            IssueKind::DeprecatedCall { .. } => "MIR1000",
1166            IssueKind::WrongCaseFunction { .. } => "MIR1009",
1167            IssueKind::WrongCaseMethod { .. } => "MIR1010",
1168            IssueKind::WrongCaseClass { .. } => "MIR1011",
1169            IssueKind::DeprecatedProperty { .. } => "MIR1005",
1170            IssueKind::DeprecatedInterface { .. } => "MIR1006",
1171            IssueKind::DeprecatedTrait { .. } => "MIR1007",
1172            IssueKind::DeprecatedConstant { .. } => "MIR1008",
1173            IssueKind::DeprecatedMethodCall { .. } => "MIR1001",
1174            IssueKind::DeprecatedMethod { .. } => "MIR1002",
1175            IssueKind::DeprecatedClass { .. } => "MIR1003",
1176            IssueKind::InternalMethod { .. } => "MIR1004",
1177
1178            // Missing types / docblocks (1100-1199)
1179            IssueKind::MissingReturnType { .. } => "MIR1100",
1180            IssueKind::MissingParamType { .. } => "MIR1101",
1181            IssueKind::MissingPropertyType { .. } => "MIR1104",
1182            IssueKind::MissingClosureReturnType => "MIR1105",
1183            IssueKind::MissingThrowsDocblock { .. } => "MIR1102",
1184            IssueKind::InvalidDocblock { .. } => "MIR1103",
1185
1186            // Mixed (1200-1299)
1187            IssueKind::MixedArgument { .. } => "MIR1200",
1188            IssueKind::MixedAssignment { .. } => "MIR1201",
1189            IssueKind::MixedMethodCall { .. } => "MIR1202",
1190            IssueKind::MixedPropertyFetch { .. } => "MIR1203",
1191            IssueKind::MixedPropertyAssignment { .. } => "MIR1208",
1192            IssueKind::MixedArrayAccess => "MIR1209",
1193            IssueKind::MixedArrayOffset => "MIR1210",
1194            IssueKind::MixedClone => "MIR1204",
1195            IssueKind::InvalidClone { .. } => "MIR1205",
1196            IssueKind::PossiblyInvalidClone { .. } => "MIR1206",
1197            IssueKind::InvalidToString { .. } => "MIR1207",
1198
1199            // Trait (1300-1399)
1200            IssueKind::InvalidTraitUse { .. } => "MIR1300",
1201            IssueKind::ForbiddenCode { .. } => "MIR1301",
1202
1203            // Parse (1400-1499)
1204            IssueKind::ParseError { .. } => "MIR1400",
1205
1206            // Attribute (1600-1699)
1207            IssueKind::InvalidAttribute { .. } => "MIR1600",
1208            IssueKind::UndefinedAttributeClass { .. } => "MIR1601",
1209            IssueKind::DuplicateClass { .. } => "MIR1602",
1210            IssueKind::DuplicateInterface { .. } => "MIR1603",
1211            IssueKind::DuplicateTrait { .. } => "MIR1604",
1212            IssueKind::DuplicateEnum { .. } => "MIR1605",
1213            IssueKind::DuplicateFunction { .. } => "MIR1606",
1214
1215            // Other (1500-1599)
1216            IssueKind::InvalidThrow { .. } => "MIR1500",
1217            IssueKind::InvalidCatch { .. } => "MIR1503",
1218            IssueKind::UnreachableCatch { .. } => "MIR1508",
1219            IssueKind::PluginIssue { .. } => "MIR1509",
1220            IssueKind::ImplicitToStringCast { .. } => "MIR1501",
1221            IssueKind::ImplicitFloatToIntCast { .. } => "MIR1502",
1222        }
1223    }
1224
1225    /// Returns the default [`Severity`] for a stable issue code (e.g. `"MIR0005"`).
1226    ///
1227    /// Useful when a caller holds a bare code string — from config, suppression
1228    /// annotations, or serialised diagnostics — and needs to recover the severity
1229    /// without constructing a full [`IssueKind`]. Returns `None` for unknown codes.
1230    pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1231        match code {
1232            // Errors
1233            "MIR0001" | "MIR0002" | "MIR0003" | "MIR0004" | "MIR0005" | "MIR0007" | "MIR0009"
1234            | "MIR0010" | "MIR0011" | "MIR0012" | "MIR0013" | "MIR0014" | "MIR0200" | "MIR0201"
1235            | "MIR0202" | "MIR0203" | "MIR0204" | "MIR0205" | "MIR0212" | "MIR0215" | "MIR0216"
1236            | "MIR0217" | "MIR0224" | "MIR0600" | "MIR0601" | "MIR0700" | "MIR0701" | "MIR0702"
1237            | "MIR0704" | "MIR0705" | "MIR0706" | "MIR0707" | "MIR0708" | "MIR0709" | "MIR0711"
1238            | "MIR0712" | "MIR0713" | "MIR0714" | "MIR0715" | "MIR0716" | "MIR0717" | "MIR0228"
1239            | "MIR0229" | "MIR0800" | "MIR0801" | "MIR0802" | "MIR0803" | "MIR0804" | "MIR0900"
1240            | "MIR1205" | "MIR1207" | "MIR1300" | "MIR1400" | "MIR1500" | "MIR1503" | "MIR1602"
1241            | "MIR1603" | "MIR1604" | "MIR1605" | "MIR1606" => Some(Severity::Error),
1242
1243            // Warnings
1244            "MIR0006" | "MIR0008" | "MIR0100" | "MIR0101" | "MIR0102" | "MIR0103" | "MIR0109"
1245            | "MIR0206" | "MIR0208" | "MIR0211" | "MIR0218" | "MIR0219" | "MIR0220" | "MIR0222"
1246            | "MIR0300" | "MIR0301" | "MIR0302" | "MIR0303" | "MIR0404" | "MIR0405" | "MIR0408"
1247            | "MIR0500" | "MIR0506" | "MIR0703" | "MIR0710" | "MIR1301" | "MIR1501" | "MIR1502"
1248            | "MIR1700" | "MIR1701" | "MIR1702" | "MIR1703" | "MIR1704" | "MIR1705" | "MIR1706"
1249            | "MIR1707" | "MIR1708" | "MIR1506" | "MIR1510" => Some(Severity::Warning),
1250
1251            // Info
1252            "MIR0104" | "MIR0105" | "MIR0106" | "MIR0107" | "MIR0108" | "MIR0207" | "MIR0209"
1253            | "MIR0210" | "MIR0213" | "MIR0214" | "MIR0221" | "MIR0223" | "MIR0400" | "MIR0401"
1254            | "MIR0402" | "MIR0403" | "MIR0501" | "MIR0502" | "MIR0503" | "MIR0504" | "MIR0505"
1255            | "MIR0507" | "MIR0508" | "MIR0901" | "MIR1000" | "MIR1001" | "MIR1002" | "MIR1003"
1256            | "MIR1004" | "MIR1005" | "MIR1006" | "MIR1007" | "MIR1008" | "MIR1009" | "MIR1010"
1257            | "MIR1011" | "MIR1100" | "MIR1101" | "MIR1102" | "MIR1103" | "MIR1104" | "MIR1105"
1258            | "MIR1200" | "MIR1201" | "MIR1202" | "MIR1203" | "MIR1204" | "MIR1206" | "MIR1208"
1259            | "MIR1209" | "MIR1210" | "MIR1211" | "MIR1212" | "MIR1504" | "MIR1505" | "MIR1507"
1260            | "MIR1508" | "MIR1600" | "MIR1601" | "MIR0225" | "MIR0226" | "MIR0227" | "MIR0406"
1261            | "MIR0407" | "MIR0902" => Some(Severity::Info),
1262
1263            _ => None,
1264        }
1265    }
1266
1267    /// Identifier name used in config and `@psalm-suppress` / `@suppress` annotations.
1268    pub fn name(&self) -> &'static str {
1269        match self {
1270            IssueKind::NonStaticSelfCall { .. } => "NonStaticSelfCall",
1271            IssueKind::DirectConstructorCall { .. } => "DirectConstructorCall",
1272            IssueKind::InvalidScope { .. } => "InvalidScope",
1273            IssueKind::UndefinedVariable { .. } => "UndefinedVariable",
1274            IssueKind::UndefinedFunction { .. } => "UndefinedFunction",
1275            IssueKind::UndefinedMethod { .. } => "UndefinedMethod",
1276            IssueKind::UndefinedClass { .. } => "UndefinedClass",
1277            IssueKind::UndefinedProperty { .. } => "UndefinedProperty",
1278            IssueKind::UndefinedConstant { .. } => "UndefinedConstant",
1279            IssueKind::InaccessibleClassConstant { .. } => "InaccessibleClassConstant",
1280            IssueKind::InaccessibleProperty { .. } => "InaccessibleProperty",
1281            IssueKind::TraitConstantAccessedDirectly { .. } => "TraitConstantAccessedDirectly",
1282            IssueKind::UndefinedTraitAliasMethod { .. } => "UndefinedTraitAliasMethod",
1283            IssueKind::PossiblyUndefinedVariable { .. } => "PossiblyUndefinedVariable",
1284            IssueKind::UndefinedTrait { .. } => "UndefinedTrait",
1285            IssueKind::ParentNotFound => "ParentNotFound",
1286            IssueKind::InvalidStringClass { .. } => "InvalidStringClass",
1287            IssueKind::NotAnInterface { .. } => "NotAnInterface",
1288            IssueKind::NullArgument { .. } => "NullArgument",
1289            IssueKind::NullPropertyFetch { .. } => "NullPropertyFetch",
1290            IssueKind::NullMethodCall { .. } => "NullMethodCall",
1291            IssueKind::NullArrayAccess => "NullArrayAccess",
1292            IssueKind::PossiblyNullArgument { .. } => "PossiblyNullArgument",
1293            IssueKind::PossiblyInvalidArgument { .. } => "PossiblyInvalidArgument",
1294            IssueKind::PossiblyNullPropertyFetch { .. } => "PossiblyNullPropertyFetch",
1295            IssueKind::PossiblyNullMethodCall { .. } => "PossiblyNullMethodCall",
1296            IssueKind::PossiblyNullArrayAccess => "PossiblyNullArrayAccess",
1297            IssueKind::NullableReturnStatement { .. } => "NullableReturnStatement",
1298            IssueKind::InvalidReturnType { .. } => "InvalidReturnType",
1299            IssueKind::InvalidArgument { .. } => "InvalidArgument",
1300            IssueKind::TooFewArguments { .. } => "TooFewArguments",
1301            IssueKind::TooManyArguments { .. } => "TooManyArguments",
1302            IssueKind::InvalidNamedArgument { .. } => "InvalidNamedArgument",
1303            IssueKind::InvalidNamedArguments { .. } => "InvalidNamedArguments",
1304            IssueKind::InvalidPassByReference { .. } => "InvalidPassByReference",
1305            IssueKind::InvalidPropertyFetch { .. } => "InvalidPropertyFetch",
1306            IssueKind::InvalidArrayAccess { .. } => "InvalidArrayAccess",
1307            IssueKind::PossiblyInvalidArrayAccess { .. } => "PossiblyInvalidArrayAccess",
1308            IssueKind::InvalidArrayAssignment { .. } => "InvalidArrayAssignment",
1309            IssueKind::InvalidPropertyAssignment { .. } => "InvalidPropertyAssignment",
1310            IssueKind::InvalidCast { .. } => "InvalidCast",
1311            IssueKind::InvalidStaticInvocation { .. } => "InvalidStaticInvocation",
1312            IssueKind::InvalidOperand { .. } => "InvalidOperand",
1313            IssueKind::PossiblyInvalidOperand { .. } => "PossiblyInvalidOperand",
1314            IssueKind::PossiblyNullOperand { .. } => "PossiblyNullOperand",
1315            IssueKind::DivisionByZero { .. } => "DivisionByZero",
1316            IssueKind::RawObjectIteration { .. } => "RawObjectIteration",
1317            IssueKind::PossiblyRawObjectIteration { .. } => "PossiblyRawObjectIteration",
1318            IssueKind::MismatchingDocblockReturnType { .. } => "MismatchingDocblockReturnType",
1319            IssueKind::MismatchingDocblockParamType { .. } => "MismatchingDocblockParamType",
1320            IssueKind::TypeCheckMismatch { .. } => "TypeCheckMismatch",
1321            IssueKind::DocblockTypeContradiction { .. } => "DocblockTypeContradiction",
1322            IssueKind::ImpossibleIdenticalComparison { .. } => "ImpossibleIdenticalComparison",
1323            IssueKind::ImpossibleLooseComparison { .. } => "ImpossibleLooseComparison",
1324            IssueKind::UnevaluatedCode { .. } => "UnevaluatedCode",
1325            IssueKind::IfThisIsMismatch { .. } => "IfThisIsMismatch",
1326            IssueKind::Trace { .. } => "Trace",
1327            IssueKind::InvalidArrayOffset { .. } => "InvalidArrayOffset",
1328            IssueKind::NonExistentArrayOffset { .. } => "NonExistentArrayOffset",
1329            IssueKind::PossiblyInvalidArrayOffset { .. } => "PossiblyInvalidArrayOffset",
1330            IssueKind::DuplicateArrayKey { .. } => "DuplicateArrayKey",
1331            IssueKind::RedundantCondition { .. } => "RedundantCondition",
1332            IssueKind::RedundantCast { .. } => "RedundantCast",
1333            IssueKind::UnnecessaryVarAnnotation { .. } => "UnnecessaryVarAnnotation",
1334            IssueKind::TypeDoesNotContainType { .. } => "TypeDoesNotContainType",
1335            IssueKind::ParadoxicalCondition { .. } => "ParadoxicalCondition",
1336            IssueKind::UnhandledMatchCondition { .. } => "UnhandledMatchCondition",
1337            IssueKind::UnusedVariable { .. } => "UnusedVariable",
1338            IssueKind::UnusedParam { .. } => "UnusedParam",
1339            IssueKind::UnreachableCode => "UnreachableCode",
1340            IssueKind::UnusedMethod { .. } => "UnusedMethod",
1341            IssueKind::UnusedProperty { .. } => "UnusedProperty",
1342            IssueKind::UnusedFunction { .. } => "UnusedFunction",
1343            IssueKind::UnusedForeachValue { .. } => "UnusedForeachValue",
1344            IssueKind::UnusedClass { .. } => "UnusedClass",
1345            IssueKind::UnusedSuppress { .. } => "UnusedSuppress",
1346            IssueKind::ArgumentTypeCoercion { .. } => "ArgumentTypeCoercion",
1347            IssueKind::PropertyTypeCoercion { .. } => "PropertyTypeCoercion",
1348            IssueKind::ImpurePropertyAssignment { .. } => "ImpurePropertyAssignment",
1349            IssueKind::ImpureMethodCall { .. } => "ImpureMethodCall",
1350            IssueKind::ImpureGlobalVariable { .. } => "ImpureGlobalVariable",
1351            IssueKind::ImpureStaticVariable { .. } => "ImpureStaticVariable",
1352            IssueKind::ImpureByRefAssignment { .. } => "ImpureByRefAssignment",
1353            IssueKind::ImpureStaticPropertyAssignment { .. } => "ImpureStaticPropertyAssignment",
1354            IssueKind::ImpureStaticPropertyAccess { .. } => "ImpureStaticPropertyAccess",
1355            IssueKind::ImpureFunctionCall { .. } => "ImpureFunctionCall",
1356            IssueKind::ImmutablePropertyModification { .. } => "ImmutablePropertyModification",
1357            IssueKind::UnsupportedReferenceUsage => "UnsupportedReferenceUsage",
1358            IssueKind::NoInterfaceProperties { .. } => "NoInterfaceProperties",
1359            IssueKind::UndefinedDocblockClass { .. } => "UndefinedDocblockClass",
1360            IssueKind::MissingConstructor { .. } => "MissingConstructor",
1361            IssueKind::PropertyPossiblyUninitialized { .. } => "PropertyPossiblyUninitialized",
1362            IssueKind::MixedFunctionCall => "MixedFunctionCall",
1363            IssueKind::MixedReturnStatement { .. } => "MixedReturnStatement",
1364            IssueKind::UnimplementedAbstractMethod { .. } => "UnimplementedAbstractMethod",
1365            IssueKind::UnimplementedInterfaceMethod { .. } => "UnimplementedInterfaceMethod",
1366            IssueKind::MethodSignatureMismatch { .. } => "MethodSignatureMismatch",
1367            IssueKind::OverriddenMethodAccess { .. } => "OverriddenMethodAccess",
1368            IssueKind::OverriddenPropertyAccess { .. } => "OverriddenPropertyAccess",
1369            IssueKind::PropertyTypeRedeclarationMismatch { .. } => {
1370                "PropertyTypeRedeclarationMismatch"
1371            }
1372            IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => {
1373                "ReadonlyPropertyRedeclarationMismatch"
1374            }
1375            IssueKind::StaticPropertyRedeclarationMismatch { .. } => {
1376                "StaticPropertyRedeclarationMismatch"
1377            }
1378            IssueKind::ReadonlyClassExtendsMismatch { .. } => "ReadonlyClassExtendsMismatch",
1379            IssueKind::InvalidReadonlyPropertyDeclaration { .. } => {
1380                "InvalidReadonlyPropertyDeclaration"
1381            }
1382            IssueKind::BackedEnumCaseTypeMismatch { .. } => "BackedEnumCaseTypeMismatch",
1383            IssueKind::InvalidExtendClass { .. } => "InvalidExtendClass",
1384            IssueKind::FinalMethodOverridden { .. } => "FinalMethodOverridden",
1385            IssueKind::AbstractInstantiation { .. } => "AbstractInstantiation",
1386            IssueKind::AbstractMethodCall { .. } => "AbstractMethodCall",
1387            IssueKind::InterfaceInstantiation { .. } => "InterfaceInstantiation",
1388            IssueKind::InvalidOverride { .. } => "InvalidOverride",
1389            IssueKind::ReadonlyPropertyAssignment { .. } => "ReadonlyPropertyAssignment",
1390            IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => {
1391                "ReadonlyPropertyAlreadyInitialized"
1392            }
1393            IssueKind::InvalidTemplateParam { .. } => "InvalidTemplateParam",
1394            IssueKind::ShadowedTemplateParam { .. } => "ShadowedTemplateParam",
1395            IssueKind::TaintedInput { .. } => "TaintedInput",
1396            IssueKind::TaintedHtml => "TaintedHtml",
1397            IssueKind::TaintedSql => "TaintedSql",
1398            IssueKind::TaintedShell => "TaintedShell",
1399            IssueKind::TaintedLlmPrompt => "TaintedLlmPrompt",
1400            IssueKind::DeprecatedCall { .. } => "DeprecatedCall",
1401            IssueKind::DeprecatedProperty { .. } => "DeprecatedProperty",
1402            IssueKind::DeprecatedConstant { .. } => "DeprecatedConstant",
1403            IssueKind::DeprecatedInterface { .. } => "DeprecatedInterface",
1404            IssueKind::DeprecatedTrait { .. } => "DeprecatedTrait",
1405            IssueKind::DeprecatedMethodCall { .. } => "DeprecatedMethodCall",
1406            IssueKind::DeprecatedMethod { .. } => "DeprecatedMethod",
1407            IssueKind::DeprecatedClass { .. } => "DeprecatedClass",
1408            IssueKind::InternalMethod { .. } => "InternalMethod",
1409            IssueKind::MissingReturnType { .. } => "MissingReturnType",
1410            IssueKind::MissingClosureReturnType => "MissingClosureReturnType",
1411            IssueKind::MissingParamType { .. } => "MissingParamType",
1412            IssueKind::MissingPropertyType { .. } => "MissingPropertyType",
1413            IssueKind::InvalidThrow { .. } => "InvalidThrow",
1414            IssueKind::InvalidCatch { .. } => "InvalidCatch",
1415            IssueKind::UnreachableCatch { .. } => "UnreachableCatch",
1416            IssueKind::MissingThrowsDocblock { .. } => "MissingThrowsDocblock",
1417            IssueKind::ImplicitToStringCast { .. } => "ImplicitToStringCast",
1418            IssueKind::ImplicitFloatToIntCast { .. } => "ImplicitFloatToIntCast",
1419            IssueKind::ParseError { .. } => "ParseError",
1420            IssueKind::InvalidDocblock { .. } => "InvalidDocblock",
1421            IssueKind::MixedArgument { .. } => "MixedArgument",
1422            IssueKind::MixedAssignment { .. } => "MixedAssignment",
1423            IssueKind::MixedMethodCall { .. } => "MixedMethodCall",
1424            IssueKind::MixedPropertyFetch { .. } => "MixedPropertyFetch",
1425            IssueKind::MixedPropertyAssignment { .. } => "MixedPropertyAssignment",
1426            IssueKind::MixedArrayAccess => "MixedArrayAccess",
1427            IssueKind::MixedArrayOffset => "MixedArrayOffset",
1428            IssueKind::MixedClone => "MixedClone",
1429            IssueKind::InvalidClone { .. } => "InvalidClone",
1430            IssueKind::PossiblyInvalidClone { .. } => "PossiblyInvalidClone",
1431            IssueKind::InvalidToString { .. } => "InvalidToString",
1432            IssueKind::CircularInheritance { .. } => "CircularInheritance",
1433            IssueKind::InvalidTraitUse { .. } => "InvalidTraitUse",
1434            IssueKind::ForbiddenCode { .. } => "ForbiddenCode",
1435            IssueKind::WrongCaseFunction { .. } => "WrongCaseFunction",
1436            IssueKind::WrongCaseMethod { .. } => "WrongCaseMethod",
1437            IssueKind::WrongCaseClass { .. } => "WrongCaseClass",
1438            IssueKind::InvalidAttribute { .. } => "InvalidAttribute",
1439            IssueKind::UndefinedAttributeClass { .. } => "UndefinedAttributeClass",
1440            IssueKind::DuplicateClass { .. } => "DuplicateClass",
1441            IssueKind::DuplicateInterface { .. } => "DuplicateInterface",
1442            IssueKind::DuplicateTrait { .. } => "DuplicateTrait",
1443            IssueKind::DuplicateEnum { .. } => "DuplicateEnum",
1444            IssueKind::DuplicateFunction { .. } => "DuplicateFunction",
1445            IssueKind::PluginIssue { .. } => "PluginIssue",
1446        }
1447    }
1448
1449    /// Like [`IssueKind::name`], but for plugin-raised issues returns the
1450    /// plugin's own issue name. Use this for suppression / issue-handler
1451    /// matching so `@mir-suppress MyPluginIssue` works.
1452    pub fn display_name(&self) -> &str {
1453        match self {
1454            IssueKind::PluginIssue { name, .. } => name,
1455            other => other.name(),
1456        }
1457    }
1458
1459    /// Human-readable message for this issue.
1460    pub fn message(&self) -> String {
1461        match self {
1462            IssueKind::NonStaticSelfCall { class, method } => {
1463                format!("Non-static method {class}::{method}() cannot be called statically")
1464            }
1465            IssueKind::DirectConstructorCall { class } => {
1466                format!("Cannot call constructor of {class} directly")
1467            }
1468            IssueKind::InvalidScope { in_class } => {
1469                if *in_class {
1470                    "$this cannot be used in a static method".to_string()
1471                } else {
1472                    "$this cannot be used outside of a class".to_string()
1473                }
1474            }
1475            IssueKind::UndefinedVariable { name } => format!("Variable ${name} is not defined"),
1476            IssueKind::UndefinedFunction { name } => format!("Function {name}() is not defined"),
1477            IssueKind::UndefinedMethod { class, method } => {
1478                format!("Method {class}::{method}() does not exist")
1479            }
1480            IssueKind::UndefinedClass { name } => format!("Class {name} does not exist"),
1481            IssueKind::UndefinedProperty { class, property } => {
1482                format!("Property {class}::${property} does not exist")
1483            }
1484            IssueKind::UndefinedConstant { name } => format!("Constant {name} is not defined"),
1485            IssueKind::InaccessibleClassConstant { class, constant } => {
1486                format!("Cannot access constant {class}::{constant}")
1487            }
1488            IssueKind::InaccessibleProperty { class, property } => {
1489                format!("Cannot access property {class}::${property}")
1490            }
1491            IssueKind::PossiblyUndefinedVariable { name } => {
1492                format!("Variable ${name} might not be defined")
1493            }
1494            IssueKind::UndefinedTrait { name } => format!("Trait {name} does not exist"),
1495            IssueKind::TraitConstantAccessedDirectly {
1496                trait_name,
1497                constant,
1498            } => {
1499                format!("Cannot access trait constant {trait_name}::{constant} directly")
1500            }
1501            IssueKind::UndefinedTraitAliasMethod { trait_name, method } => match trait_name {
1502                Some(t) => {
1503                    format!("An alias was defined for {t}::{method} but this method does not exist")
1504                }
1505                None => format!("An alias was defined for {method} but this method does not exist"),
1506            },
1507            IssueKind::ParentNotFound => {
1508                "Cannot use parent:: when current class has no parent".to_string()
1509            }
1510            IssueKind::InvalidStringClass { actual } => {
1511                format!("Dynamic class instantiation requires string or class-string type, got '{actual}'")
1512            }
1513            IssueKind::NotAnInterface { name } => {
1514                format!("{name} is not an interface")
1515            }
1516
1517            IssueKind::NullArgument { param, fn_name } => {
1518                format!("Argument ${param} of {fn_name}() cannot be null")
1519            }
1520            IssueKind::NullPropertyFetch { property } => {
1521                format!("Cannot access property ${property} on null")
1522            }
1523            IssueKind::NullMethodCall { method } => {
1524                format!("Cannot call method {method}() on null")
1525            }
1526            IssueKind::NullArrayAccess => "Cannot access array on null".to_string(),
1527            IssueKind::PossiblyNullArgument { param, fn_name } => {
1528                format!("Argument ${param} of {fn_name}() might be null")
1529            }
1530            IssueKind::PossiblyInvalidArgument {
1531                param,
1532                fn_name,
1533                expected,
1534                actual,
1535            } => {
1536                format!("Argument ${param} of {fn_name}() expects '{expected}', possibly different type '{actual}' provided")
1537            }
1538            IssueKind::PossiblyNullPropertyFetch { property } => {
1539                format!("Cannot access property ${property} on possibly null value")
1540            }
1541            IssueKind::PossiblyNullMethodCall { method } => {
1542                format!("Cannot call method {method}() on possibly null value")
1543            }
1544            IssueKind::PossiblyNullArrayAccess => {
1545                "Cannot access array on possibly null value".to_string()
1546            }
1547            IssueKind::NullableReturnStatement { expected, actual } => {
1548                format!("Return type '{actual}' is not compatible with declared '{expected}'")
1549            }
1550
1551            IssueKind::InvalidReturnType { expected, actual } => {
1552                format!("Return type '{actual}' is not compatible with declared '{expected}'")
1553            }
1554            IssueKind::InvalidArgument {
1555                param,
1556                fn_name,
1557                expected,
1558                actual,
1559            } => {
1560                format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}'")
1561            }
1562            IssueKind::TooFewArguments {
1563                fn_name,
1564                expected,
1565                actual,
1566            } => {
1567                format!(
1568                    "Too few arguments for {}(): expected {}, got {}",
1569                    fn_name, expected, actual
1570                )
1571            }
1572            IssueKind::TooManyArguments {
1573                fn_name,
1574                expected,
1575                actual,
1576            } => {
1577                format!(
1578                    "Too many arguments for {}(): expected {}, got {}",
1579                    fn_name, expected, actual
1580                )
1581            }
1582            IssueKind::InvalidNamedArgument { fn_name, name } => {
1583                format!("{}() has no parameter named ${}", fn_name, name)
1584            }
1585            IssueKind::InvalidNamedArguments { fn_name } => {
1586                format!("{}() does not accept named arguments", fn_name)
1587            }
1588            IssueKind::InvalidPassByReference { fn_name, param } => {
1589                format!(
1590                    "Argument ${} of {}() must be passed by reference",
1591                    param, fn_name
1592                )
1593            }
1594            IssueKind::InvalidPropertyFetch { ty } => {
1595                format!("Cannot fetch property on non-object type '{ty}'")
1596            }
1597            IssueKind::InvalidArrayAccess { ty } => {
1598                format!("Cannot use [] operator on non-array type '{ty}'")
1599            }
1600            IssueKind::PossiblyInvalidArrayAccess { ty } => {
1601                format!("Possibly invalid array access: '{ty}' might not support []")
1602            }
1603            IssueKind::InvalidArrayAssignment { ty } => {
1604                format!("Cannot use [] assignment on non-array type '{ty}'")
1605            }
1606            IssueKind::InvalidPropertyAssignment {
1607                property,
1608                expected,
1609                actual,
1610            } => {
1611                format!("Property ${property} expects '{expected}', cannot assign '{actual}'")
1612            }
1613            IssueKind::InvalidCast { from, to } => {
1614                format!("Cannot cast '{from}' to '{to}'")
1615            }
1616            IssueKind::InvalidStaticInvocation { class, method } => {
1617                format!("Non-static method {class}::{method}() cannot be called statically")
1618            }
1619            IssueKind::InvalidOperand { op, left, right } => {
1620                if right.is_empty() {
1621                    format!("Operator '{op}' not supported for operand of type '{left}'")
1622                } else {
1623                    format!("Operator '{op}' not supported between '{left}' and '{right}'")
1624                }
1625            }
1626            IssueKind::PossiblyInvalidOperand { op, left, right } => {
1627                format!("Operator '{op}' might not be supported between '{left}' and '{right}'")
1628            }
1629            IssueKind::PossiblyNullOperand { op, ty } => {
1630                format!("Operator '{op}' operand '{ty}' might be null")
1631            }
1632            IssueKind::DivisionByZero { op } => {
1633                format!("Division by zero: right operand of '{op}' is always 0")
1634            }
1635            IssueKind::RawObjectIteration { ty } => {
1636                format!("Cannot iterate over non-iterable object '{ty}'")
1637            }
1638            IssueKind::PossiblyRawObjectIteration { ty } => {
1639                format!("Cannot iterate over possibly non-iterable object '{ty}'")
1640            }
1641            IssueKind::MismatchingDocblockReturnType { declared, inferred } => {
1642                format!("Docblock return type '{declared}' does not match inferred '{inferred}'")
1643            }
1644            IssueKind::MismatchingDocblockParamType {
1645                param,
1646                declared,
1647                inferred,
1648            } => {
1649                format!(
1650                    "Docblock type '{declared}' for ${param} does not match inferred '{inferred}'"
1651                )
1652            }
1653            IssueKind::TypeCheckMismatch {
1654                var,
1655                expected,
1656                actual,
1657            } => {
1658                format!("Type of {var} is expected to be {expected}, got {actual}")
1659            }
1660            IssueKind::Trace {
1661                variable,
1662                type_info,
1663            } => {
1664                format!("Type of ${variable} is {type_info}")
1665            }
1666
1667            IssueKind::InvalidArrayOffset { expected, actual } => {
1668                format!("Array offset expects '{expected}', got '{actual}'")
1669            }
1670            IssueKind::NonExistentArrayOffset { key } => {
1671                format!("Array offset '{key}' does not exist")
1672            }
1673            IssueKind::PossiblyInvalidArrayOffset { expected, actual } => {
1674                format!("Array offset might be invalid: expects '{expected}', got '{actual}'")
1675            }
1676            IssueKind::DuplicateArrayKey { key } => {
1677                format!("Array key {key} is duplicated — the earlier entry is silently overwritten")
1678            }
1679
1680            IssueKind::RedundantCondition { ty } => {
1681                format!("Condition is always true/false for type '{ty}'")
1682            }
1683            IssueKind::RedundantCast { from, to } => {
1684                format!("Casting '{from}' to '{to}' is redundant")
1685            }
1686            IssueKind::UnnecessaryVarAnnotation { var } => {
1687                format!("@var annotation for ${var} is unnecessary")
1688            }
1689            IssueKind::TypeDoesNotContainType { left, right } => {
1690                format!("Type '{left}' can never contain type '{right}'")
1691            }
1692            IssueKind::ParadoxicalCondition { value } => {
1693                format!("Value {value} is duplicated; this branch can never be reached")
1694            }
1695            IssueKind::UnhandledMatchCondition { detail } => {
1696                format!("Unhandled match condition: {detail}")
1697            }
1698            IssueKind::DocblockTypeContradiction { expr, declared } => {
1699                format!("Type '{declared}' makes '{expr}' impossible — this can never hold")
1700            }
1701            IssueKind::ImpossibleIdenticalComparison { op, left, right } => {
1702                let result = if op == "===" { "false" } else { "true" };
1703                format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be identical")
1704            }
1705            IssueKind::ImpossibleLooseComparison { op, left, right } => {
1706                let result = if op == "==" { "false" } else { "true" };
1707                format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be loosely equal")
1708            }
1709            IssueKind::UnevaluatedCode { reason } => {
1710                format!("Unevaluated code: {reason}")
1711            }
1712            IssueKind::IfThisIsMismatch {
1713                class,
1714                method,
1715                expected,
1716                actual,
1717            } => {
1718                format!(
1719                    "Cannot call {class}::{method}() — @if-this-is requires $this to be '{expected}', but it is '{actual}'"
1720                )
1721            }
1722
1723            IssueKind::UnusedVariable { name } => format!("Variable ${name} is never read"),
1724            IssueKind::UnusedParam { name } => format!("Parameter ${name} is never used"),
1725            IssueKind::UnreachableCode => "Unreachable code detected".to_string(),
1726            IssueKind::UnusedMethod { class, method } => {
1727                format!("Private method {class}::{method}() is never called")
1728            }
1729            IssueKind::UnusedProperty { class, property } => {
1730                format!("Private property {class}::${property} is never read")
1731            }
1732            IssueKind::UnusedFunction { name } => {
1733                format!("Function {name}() is never called")
1734            }
1735            IssueKind::UnusedForeachValue { name } => {
1736                format!("Foreach value ${name} is never read")
1737            }
1738            IssueKind::UnusedClass { class } => {
1739                format!("Class {class} is never referenced")
1740            }
1741            IssueKind::UnusedSuppress { kind } => {
1742                format!("Suppress annotation for '{kind}' is never used")
1743            }
1744            IssueKind::ArgumentTypeCoercion {
1745                param,
1746                fn_name,
1747                expected,
1748                actual,
1749            } => {
1750                format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}' — coercion may fail at runtime")
1751            }
1752            IssueKind::PropertyTypeCoercion {
1753                property,
1754                expected,
1755                actual,
1756            } => {
1757                format!("Property ${property} expects '{expected}', cannot assign '{actual}' — coercion may fail at runtime")
1758            }
1759            IssueKind::ImpurePropertyAssignment { property } => {
1760                format!("Assigning to property {property} of a parameter in a pure or external-mutation-free context")
1761            }
1762            IssueKind::ImpureMethodCall { method } => {
1763                format!("Calling impure method {method}() in a pure or immutable context")
1764            }
1765            IssueKind::ImpureGlobalVariable { variable } => {
1766                format!("Using global variable ${variable} in a @pure function")
1767            }
1768            IssueKind::ImpureStaticVariable { variable } => {
1769                format!("Using static variable ${variable} in a @pure function")
1770            }
1771            IssueKind::ImpureByRefAssignment { variable } => {
1772                format!("Assigning to by-reference parameter ${variable} in a @pure function")
1773            }
1774            IssueKind::ImpureStaticPropertyAssignment { class, property } => {
1775                format!("Assigning to static property {class}::${property} in a @pure function")
1776            }
1777            IssueKind::ImpureStaticPropertyAccess { class, property } => {
1778                format!("Reading static property {class}::${property} in a @pure function")
1779            }
1780            IssueKind::ImpureFunctionCall { fn_name } => {
1781                format!("Calling impure function {fn_name}() in a @pure function")
1782            }
1783            IssueKind::ImmutablePropertyModification { receiver, property } => {
1784                format!("Assigning to property {property} of {receiver} in an immutable context (@psalm-immutable class or @psalm-mutation-free method)")
1785            }
1786
1787            IssueKind::UnimplementedAbstractMethod { class, method } => {
1788                format!("Class {class} must implement abstract method {method}()")
1789            }
1790            IssueKind::UnimplementedInterfaceMethod {
1791                class,
1792                interface,
1793                method,
1794            } => {
1795                format!("Class {class} must implement {interface}::{method}() from interface")
1796            }
1797            IssueKind::MethodSignatureMismatch {
1798                class,
1799                method,
1800                detail,
1801            } => {
1802                format!("Method {class}::{method}() signature mismatch: {detail}")
1803            }
1804            IssueKind::OverriddenMethodAccess { class, method } => {
1805                format!("Method {class}::{method}() overrides with less visibility")
1806            }
1807            IssueKind::OverriddenPropertyAccess { class, property } => {
1808                format!("Property {class}::${property} overrides with less visibility")
1809            }
1810            IssueKind::PropertyTypeRedeclarationMismatch {
1811                class,
1812                property,
1813                expected,
1814                actual,
1815            } => {
1816                format!(
1817                    "Type of {class}::${property} must be {expected} (as in parent class), {actual} given"
1818                )
1819            }
1820            IssueKind::ReadonlyPropertyRedeclarationMismatch {
1821                parent_class,
1822                class,
1823                property,
1824                parent_readonly,
1825            } => {
1826                if *parent_readonly {
1827                    format!(
1828                        "Cannot redeclare readonly property {parent_class}::${property} as non-readonly {class}::${property}"
1829                    )
1830                } else {
1831                    format!(
1832                        "Cannot redeclare non-readonly property {parent_class}::${property} as readonly {class}::${property}"
1833                    )
1834                }
1835            }
1836            IssueKind::StaticPropertyRedeclarationMismatch {
1837                parent_class,
1838                class,
1839                property,
1840                parent_static,
1841            } => {
1842                if *parent_static {
1843                    format!(
1844                        "Cannot redeclare static property {parent_class}::${property} as non-static {class}::${property}"
1845                    )
1846                } else {
1847                    format!(
1848                        "Cannot redeclare non-static property {parent_class}::${property} as static {class}::${property}"
1849                    )
1850                }
1851            }
1852            IssueKind::BackedEnumCaseTypeMismatch {
1853                enum_name,
1854                case_name,
1855                expected,
1856                actual,
1857            } => {
1858                format!(
1859                    "Backed enum case {enum_name}::{case_name} has value of type {actual}, but backing type is {expected}"
1860                )
1861            }
1862            IssueKind::ReadonlyClassExtendsMismatch {
1863                parent,
1864                child,
1865                parent_readonly,
1866            } => {
1867                if *parent_readonly {
1868                    format!("Non-readonly class {child} cannot extend readonly class {parent}")
1869                } else {
1870                    format!("Readonly class {child} cannot extend non-readonly class {parent}")
1871                }
1872            }
1873            IssueKind::InvalidReadonlyPropertyDeclaration { class, property } => {
1874                format!("Readonly property {class}::${property} cannot have a default value")
1875            }
1876            IssueKind::ReadonlyPropertyAssignment { class, property } => {
1877                format!(
1878                    "Cannot assign to readonly property {class}::${property} outside of constructor"
1879                )
1880            }
1881            IssueKind::ReadonlyPropertyAlreadyInitialized { class, property } => {
1882                format!(
1883                    "Cannot modify readonly property {class}::${property} — already initialized"
1884                )
1885            }
1886            IssueKind::InvalidExtendClass { parent, child } => {
1887                format!("Class {child} cannot extend final class {parent}")
1888            }
1889            IssueKind::InvalidTemplateParam {
1890                name,
1891                expected_bound,
1892                actual,
1893            } => {
1894                format!(
1895                    "Template type '{name}' inferred as '{actual}' does not satisfy bound '{expected_bound}'"
1896                )
1897            }
1898            IssueKind::ShadowedTemplateParam { name } => {
1899                format!(
1900                    "Method template parameter '{name}' shadows class-level template parameter with the same name"
1901                )
1902            }
1903            IssueKind::FinalMethodOverridden {
1904                class,
1905                method,
1906                parent,
1907            } => {
1908                format!("Method {class}::{method}() cannot override final method from {parent}")
1909            }
1910            IssueKind::AbstractInstantiation { class } => {
1911                format!("Cannot instantiate abstract class {class}")
1912            }
1913            IssueKind::AbstractMethodCall { class, method } => {
1914                format!("Cannot call abstract method {class}::{method}()")
1915            }
1916            IssueKind::InterfaceInstantiation { class } => {
1917                format!("Cannot instantiate interface {class}")
1918            }
1919            IssueKind::InvalidOverride {
1920                class,
1921                method,
1922                detail,
1923            } => {
1924                format!("Method {class}::{method}() has #[Override] but {detail}")
1925            }
1926
1927            IssueKind::TaintedInput { sink } => format!("Tainted input reaching sink '{sink}'"),
1928            IssueKind::TaintedHtml => "Tainted HTML output — possible XSS".to_string(),
1929            IssueKind::TaintedSql => "Tainted SQL query — possible SQL injection".to_string(),
1930            IssueKind::TaintedShell => {
1931                "Tainted shell command — possible command injection".to_string()
1932            }
1933            IssueKind::TaintedLlmPrompt => {
1934                "Tainted LLM prompt — possible prompt injection".to_string()
1935            }
1936
1937            IssueKind::DeprecatedCall { name, message } => {
1938                let base = format!("Call to deprecated function {name}");
1939                append_deprecation_message(base, message)
1940            }
1941            IssueKind::DeprecatedProperty {
1942                class,
1943                property,
1944                message,
1945            } => {
1946                let base = format!("Property {class}::${property} is deprecated");
1947                append_deprecation_message(base, message)
1948            }
1949            IssueKind::DeprecatedConstant {
1950                class,
1951                constant,
1952                message,
1953            } => {
1954                let base = format!("Constant {class}::{constant} is deprecated");
1955                append_deprecation_message(base, message)
1956            }
1957            IssueKind::DeprecatedInterface { name, message } => {
1958                let base = format!("Interface {name} is deprecated");
1959                append_deprecation_message(base, message)
1960            }
1961            IssueKind::DeprecatedTrait { name, message } => {
1962                let base = format!("Trait {name} is deprecated");
1963                append_deprecation_message(base, message)
1964            }
1965            IssueKind::DeprecatedMethodCall {
1966                class,
1967                method,
1968                message,
1969            } => {
1970                let base = format!("Call to deprecated method {class}::{method}");
1971                append_deprecation_message(base, message)
1972            }
1973            IssueKind::DeprecatedMethod {
1974                class,
1975                method,
1976                message,
1977            } => {
1978                let base = format!("Method {class}::{method}() is deprecated");
1979                append_deprecation_message(base, message)
1980            }
1981            IssueKind::DeprecatedClass { name, message } => {
1982                let base = format!("Class {name} is deprecated");
1983                append_deprecation_message(base, message)
1984            }
1985            IssueKind::InternalMethod { class, method } => {
1986                format!("Method {class}::{method}() is marked @internal")
1987            }
1988            IssueKind::MissingReturnType { fn_name } => {
1989                format!("Function {fn_name}() has no return type annotation")
1990            }
1991            IssueKind::MissingClosureReturnType => {
1992                "Closure has no return type annotation".to_string()
1993            }
1994            IssueKind::MissingParamType { fn_name, param } => {
1995                format!("Parameter ${param} of {fn_name}() has no type annotation")
1996            }
1997            IssueKind::MissingPropertyType { class, property } => {
1998                format!("Property {class}::${property} has no type annotation")
1999            }
2000            IssueKind::InvalidThrow { ty } => {
2001                format!("Thrown type '{ty}' does not extend Throwable")
2002            }
2003            IssueKind::InvalidCatch { ty } => {
2004                format!("Caught type '{ty}' does not extend Throwable")
2005            }
2006            IssueKind::UnreachableCatch { ty, shadowed_by } => {
2007                format!("Catch block for '{ty}' is unreachable — already caught by '{shadowed_by}'")
2008            }
2009            IssueKind::MissingThrowsDocblock { class } => {
2010                format!("Exception {class} is thrown but not declared in @throws")
2011            }
2012            IssueKind::ImplicitToStringCast { class } => {
2013                format!("Class {class} is implicitly cast to string")
2014            }
2015            IssueKind::ImplicitFloatToIntCast { from } => {
2016                format!("Implicit cast from {from} to int truncates the fractional part")
2017            }
2018            IssueKind::ParseError { message } => format!("Parse error: {message}"),
2019            IssueKind::InvalidDocblock { message } => format!("Invalid docblock: {message}"),
2020            IssueKind::MixedArgument { param, fn_name } => {
2021                format!("Argument ${param} of {fn_name}() is mixed")
2022            }
2023            IssueKind::MixedAssignment { var } => {
2024                format!("Variable ${var} is assigned a mixed type")
2025            }
2026            IssueKind::MixedMethodCall { method } => {
2027                format!("Method {method}() called on mixed type")
2028            }
2029            IssueKind::UnsupportedReferenceUsage => {
2030                "Reference assignment is not supported".to_string()
2031            }
2032            IssueKind::NoInterfaceProperties { property } => {
2033                format!("Property ${property} is not defined on this interface")
2034            }
2035            IssueKind::UndefinedDocblockClass { name } => {
2036                format!("Docblock type '{name}' does not exist")
2037            }
2038            IssueKind::MissingConstructor { class } => {
2039                format!("Class {class} has uninitialized properties but no constructor")
2040            }
2041            IssueKind::PropertyPossiblyUninitialized { class, property } => {
2042                format!(
2043                    "Property {class}::${property} may be left uninitialized by the constructor"
2044                )
2045            }
2046            IssueKind::MixedFunctionCall => "Cannot call mixed type as a function".to_string(),
2047            IssueKind::MixedReturnStatement { declared } => {
2048                format!("Cannot return a mixed type from function with declared return type '{declared}'")
2049            }
2050            IssueKind::MixedPropertyFetch { property } => {
2051                format!("Property ${property} fetched on mixed type")
2052            }
2053            IssueKind::MixedPropertyAssignment { property } => {
2054                format!("Property ${property} assigned on mixed type")
2055            }
2056            IssueKind::MixedArrayAccess => "Array access on mixed type".to_string(),
2057            IssueKind::MixedArrayOffset => "Mixed type used as array offset".to_string(),
2058            IssueKind::MixedClone => "cannot clone mixed".to_string(),
2059            IssueKind::InvalidClone { ty } => format!("cannot clone non-object {ty}"),
2060            IssueKind::PossiblyInvalidClone { ty } => {
2061                format!("cannot clone possibly non-object {ty}")
2062            }
2063            IssueKind::InvalidToString { class } => {
2064                format!("Method {class}::__toString() must return a string")
2065            }
2066            IssueKind::CircularInheritance { class } => {
2067                format!("Class {class} has a circular inheritance chain")
2068            }
2069            IssueKind::InvalidTraitUse { trait_name, reason } => {
2070                format!("Trait {trait_name} used incorrectly: {reason}")
2071            }
2072            IssueKind::WrongCaseFunction { used, canonical } => {
2073                format!("Function name '{used}' has incorrect casing; use '{canonical}'")
2074            }
2075            IssueKind::WrongCaseMethod {
2076                class,
2077                used,
2078                canonical,
2079            } => {
2080                format!("Method name '{class}::{used}' has incorrect casing; use '{canonical}'")
2081            }
2082            IssueKind::WrongCaseClass { used, canonical } => {
2083                format!("Class name '{used}' has incorrect casing; use '{canonical}'")
2084            }
2085            IssueKind::InvalidAttribute { message } => message.clone(),
2086            IssueKind::UndefinedAttributeClass { name } => {
2087                format!("Attribute class {name} does not exist")
2088            }
2089            IssueKind::ForbiddenCode { message } => message.clone(),
2090            IssueKind::DuplicateClass { name } => {
2091                format!("Class {name} has already been defined")
2092            }
2093            IssueKind::DuplicateInterface { name } => {
2094                format!("Interface {name} has already been defined")
2095            }
2096            IssueKind::DuplicateTrait { name } => {
2097                format!("Trait {name} has already been defined")
2098            }
2099            IssueKind::DuplicateEnum { name } => {
2100                format!("Enum {name} has already been defined")
2101            }
2102            IssueKind::DuplicateFunction { name } => {
2103                format!("Function {name}() has already been defined")
2104            }
2105            IssueKind::PluginIssue { message, .. } => message.clone(),
2106        }
2107    }
2108}
2109
2110// ---------------------------------------------------------------------------
2111// Issue
2112// ---------------------------------------------------------------------------
2113
2114#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2115pub struct Issue {
2116    pub kind: IssueKind,
2117    pub severity: Severity,
2118    pub location: Location,
2119    pub snippet: Option<String>,
2120    pub suppressed: bool,
2121}
2122
2123impl Issue {
2124    pub fn new(kind: IssueKind, location: Location) -> Self {
2125        let severity = kind.default_severity();
2126        Self {
2127            severity,
2128            kind,
2129            location,
2130            snippet: None,
2131            suppressed: false,
2132        }
2133    }
2134
2135    pub fn with_snippet(mut self, snippet: impl Into<String>) -> Self {
2136        self.snippet = Some(snippet.into());
2137        self
2138    }
2139
2140    pub fn suppress(mut self) -> Self {
2141        self.suppressed = true;
2142        self
2143    }
2144}
2145
2146// ---------------------------------------------------------------------------
2147// IssueBuffer — collects issues for a single file pass
2148// ---------------------------------------------------------------------------
2149
2150#[derive(Debug, Default)]
2151pub struct IssueBuffer {
2152    issues: Vec<Issue>,
2153    seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
2154    /// Issue names suppressed at the file level (from `@psalm-suppress` / `@suppress` on the file docblock)
2155    file_suppressions: Vec<String>,
2156}
2157
2158impl IssueBuffer {
2159    pub fn new() -> Self {
2160        Self::default()
2161    }
2162
2163    pub fn add(&mut self, issue: Issue) {
2164        let key = (
2165            issue.kind.name(),
2166            issue.location.file.clone(),
2167            issue.location.line,
2168            issue.location.col_start,
2169        );
2170        if self.seen.insert(key) {
2171            self.issues.push(issue);
2172        }
2173    }
2174
2175    pub fn add_suppression(&mut self, name: impl Into<String>) {
2176        self.file_suppressions.push(name.into());
2177    }
2178
2179    /// Consume the buffer and return unsuppressed issues.
2180    pub fn into_issues(self) -> Vec<Issue> {
2181        self.issues
2182            .into_iter()
2183            .filter(|i| !i.suppressed)
2184            .filter(|i| {
2185                !self
2186                    .file_suppressions
2187                    .iter()
2188                    .any(|s| s == i.kind.display_name())
2189            })
2190            .collect()
2191    }
2192
2193    /// Like `into_issues` but keeps suppressed issues (with `suppressed = true`)
2194    /// so callers that need to detect unused suppressions can see which issues
2195    /// were silenced. File-level suppressions are also marked `suppressed = true`
2196    /// rather than dropped.
2197    pub fn into_all_issues(self) -> Vec<Issue> {
2198        self.issues
2199            .into_iter()
2200            .map(|mut i| {
2201                if self
2202                    .file_suppressions
2203                    .iter()
2204                    .any(|s| s == i.kind.display_name())
2205                {
2206                    i.suppressed = true;
2207                }
2208                i
2209            })
2210            .collect()
2211    }
2212
2213    /// Mark all issues added since index `from` as suppressed if their issue
2214    /// name appears in `suppressions`. Used for `@psalm-suppress` / `@suppress` on statements.
2215    pub fn suppress_range(&mut self, from: usize, suppressions: &[String]) {
2216        if suppressions.is_empty() {
2217            return;
2218        }
2219        for issue in self.issues[from..].iter_mut() {
2220            if suppressions.iter().any(|s| s == issue.kind.display_name()) {
2221                issue.suppressed = true;
2222            }
2223        }
2224    }
2225
2226    /// Current number of buffered issues. Use before analyzing a statement to
2227    /// get the `from` index for `suppress_range`.
2228    pub fn issue_count(&self) -> usize {
2229        self.issues.len()
2230    }
2231
2232    /// Discard every issue added since index `mark`, un-marking their
2233    /// locations as `seen` so a later `add()` at the same spot isn't silently
2234    /// deduplicated away. Used to roll back a speculative analysis pass (e.g.
2235    /// an unstabilized loop fixed-point iteration) whose diagnostics were
2236    /// provisional and must not leak into the final result.
2237    pub fn truncate_to(&mut self, mark: usize) {
2238        for issue in self.issues.drain(mark..) {
2239            let key = (
2240                issue.kind.name(),
2241                issue.location.file.clone(),
2242                issue.location.line,
2243                issue.location.col_start,
2244            );
2245            self.seen.remove(&key);
2246        }
2247    }
2248
2249    pub fn is_empty(&self) -> bool {
2250        self.issues.is_empty()
2251    }
2252
2253    pub fn len(&self) -> usize {
2254        self.issues.len()
2255    }
2256
2257    pub fn error_count(&self) -> usize {
2258        self.issues
2259            .iter()
2260            .filter(|i| !i.suppressed && i.severity == Severity::Error)
2261            .count()
2262    }
2263
2264    pub fn warning_count(&self) -> usize {
2265        self.issues
2266            .iter()
2267            .filter(|i| !i.suppressed && i.severity == Severity::Warning)
2268            .count()
2269    }
2270}
2271
2272#[cfg(test)]
2273mod code_tests {
2274    use super::*;
2275    use std::collections::HashSet;
2276
2277    /// Returns one instance of every `IssueKind` variant.
2278    ///
2279    /// Updating `IssueKind` without updating this list will compile (it's a
2280    /// regular `Vec`), but `codes_cover_every_variant` will catch the omission
2281    /// — the test below asserts the count matches the exhaustive `code()` arm.
2282    fn one_of_each() -> Vec<IssueKind> {
2283        let s = || String::new();
2284        vec![
2285            IssueKind::InvalidScope { in_class: false },
2286            IssueKind::NonStaticSelfCall {
2287                class: s(),
2288                method: s(),
2289            },
2290            IssueKind::DirectConstructorCall { class: s() },
2291            IssueKind::UndefinedVariable { name: s() },
2292            IssueKind::UndefinedFunction { name: s() },
2293            IssueKind::UndefinedMethod {
2294                class: s(),
2295                method: s(),
2296            },
2297            IssueKind::UndefinedClass { name: s() },
2298            IssueKind::NotAnInterface { name: s() },
2299            IssueKind::UndefinedProperty {
2300                class: s(),
2301                property: s(),
2302            },
2303            IssueKind::UndefinedConstant { name: s() },
2304            IssueKind::InaccessibleClassConstant {
2305                class: s(),
2306                constant: s(),
2307            },
2308            IssueKind::InaccessibleProperty {
2309                class: s(),
2310                property: s(),
2311            },
2312            IssueKind::PossiblyUndefinedVariable { name: s() },
2313            IssueKind::UndefinedTrait { name: s() },
2314            IssueKind::TraitConstantAccessedDirectly {
2315                trait_name: s(),
2316                constant: s(),
2317            },
2318            IssueKind::UndefinedTraitAliasMethod {
2319                trait_name: Some(s()),
2320                method: s(),
2321            },
2322            IssueKind::ParentNotFound,
2323            IssueKind::NullArgument {
2324                param: s(),
2325                fn_name: s(),
2326            },
2327            IssueKind::NullPropertyFetch { property: s() },
2328            IssueKind::NullMethodCall { method: s() },
2329            IssueKind::NullArrayAccess,
2330            IssueKind::PossiblyNullArgument {
2331                param: s(),
2332                fn_name: s(),
2333            },
2334            IssueKind::PossiblyInvalidArgument {
2335                param: s(),
2336                fn_name: s(),
2337                expected: s(),
2338                actual: s(),
2339            },
2340            IssueKind::PossiblyNullPropertyFetch { property: s() },
2341            IssueKind::PossiblyNullMethodCall { method: s() },
2342            IssueKind::PossiblyNullArrayAccess,
2343            IssueKind::NullableReturnStatement {
2344                expected: s(),
2345                actual: s(),
2346            },
2347            IssueKind::InvalidReturnType {
2348                expected: s(),
2349                actual: s(),
2350            },
2351            IssueKind::InvalidArgument {
2352                param: s(),
2353                fn_name: s(),
2354                expected: s(),
2355                actual: s(),
2356            },
2357            IssueKind::TooFewArguments {
2358                fn_name: s(),
2359                expected: 0,
2360                actual: 0,
2361            },
2362            IssueKind::TooManyArguments {
2363                fn_name: s(),
2364                expected: 0,
2365                actual: 0,
2366            },
2367            IssueKind::InvalidNamedArgument {
2368                fn_name: s(),
2369                name: s(),
2370            },
2371            IssueKind::InvalidNamedArguments { fn_name: s() },
2372            IssueKind::InvalidPassByReference {
2373                fn_name: s(),
2374                param: s(),
2375            },
2376            IssueKind::InvalidPropertyFetch { ty: s() },
2377            IssueKind::InvalidArrayAccess { ty: s() },
2378            IssueKind::PossiblyInvalidArrayAccess { ty: s() },
2379            IssueKind::InvalidArrayAssignment { ty: s() },
2380            IssueKind::InvalidPropertyAssignment {
2381                property: s(),
2382                expected: s(),
2383                actual: s(),
2384            },
2385            IssueKind::InvalidCast { from: s(), to: s() },
2386            IssueKind::InvalidStaticInvocation {
2387                class: s(),
2388                method: s(),
2389            },
2390            IssueKind::InvalidOperand {
2391                op: s(),
2392                left: s(),
2393                right: s(),
2394            },
2395            IssueKind::PossiblyInvalidOperand {
2396                op: s(),
2397                left: s(),
2398                right: s(),
2399            },
2400            IssueKind::PossiblyNullOperand { op: s(), ty: s() },
2401            IssueKind::DivisionByZero { op: s() },
2402            IssueKind::RawObjectIteration { ty: s() },
2403            IssueKind::PossiblyRawObjectIteration { ty: s() },
2404            IssueKind::MismatchingDocblockReturnType {
2405                declared: s(),
2406                inferred: s(),
2407            },
2408            IssueKind::MismatchingDocblockParamType {
2409                param: s(),
2410                declared: s(),
2411                inferred: s(),
2412            },
2413            IssueKind::TypeCheckMismatch {
2414                var: s(),
2415                expected: s(),
2416                actual: s(),
2417            },
2418            IssueKind::Trace {
2419                variable: s(),
2420                type_info: s(),
2421            },
2422            IssueKind::InvalidArrayOffset {
2423                expected: s(),
2424                actual: s(),
2425            },
2426            IssueKind::NonExistentArrayOffset { key: s() },
2427            IssueKind::PossiblyInvalidArrayOffset {
2428                expected: s(),
2429                actual: s(),
2430            },
2431            IssueKind::DuplicateArrayKey { key: s() },
2432            IssueKind::RedundantCondition { ty: s() },
2433            IssueKind::RedundantCast { from: s(), to: s() },
2434            IssueKind::UnnecessaryVarAnnotation { var: s() },
2435            IssueKind::TypeDoesNotContainType {
2436                left: s(),
2437                right: s(),
2438            },
2439            IssueKind::UnusedVariable { name: s() },
2440            IssueKind::UnusedParam { name: s() },
2441            IssueKind::UnreachableCode,
2442            IssueKind::UnhandledMatchCondition { detail: s() },
2443            IssueKind::UnusedMethod {
2444                class: s(),
2445                method: s(),
2446            },
2447            IssueKind::UnusedProperty {
2448                class: s(),
2449                property: s(),
2450            },
2451            IssueKind::UnusedFunction { name: s() },
2452            IssueKind::UnusedForeachValue { name: s() },
2453            IssueKind::UnusedClass { class: s() },
2454            IssueKind::UnusedSuppress { kind: s() },
2455            IssueKind::ArgumentTypeCoercion {
2456                param: s(),
2457                fn_name: s(),
2458                expected: s(),
2459                actual: s(),
2460            },
2461            IssueKind::PropertyTypeCoercion {
2462                property: s(),
2463                expected: s(),
2464                actual: s(),
2465            },
2466            IssueKind::ImpurePropertyAssignment { property: s() },
2467            IssueKind::ImpureMethodCall { method: s() },
2468            IssueKind::ImpureGlobalVariable { variable: s() },
2469            IssueKind::ImpureStaticVariable { variable: s() },
2470            IssueKind::ImpureByRefAssignment { variable: s() },
2471            IssueKind::ImpureStaticPropertyAssignment {
2472                class: s(),
2473                property: s(),
2474            },
2475            IssueKind::ImpureStaticPropertyAccess {
2476                class: s(),
2477                property: s(),
2478            },
2479            IssueKind::ImpureFunctionCall { fn_name: s() },
2480            IssueKind::ImmutablePropertyModification {
2481                receiver: s(),
2482                property: s(),
2483            },
2484            IssueKind::ReadonlyPropertyAssignment {
2485                class: s(),
2486                property: s(),
2487            },
2488            IssueKind::ReadonlyPropertyAlreadyInitialized {
2489                class: s(),
2490                property: s(),
2491            },
2492            IssueKind::UnimplementedAbstractMethod {
2493                class: s(),
2494                method: s(),
2495            },
2496            IssueKind::UnimplementedInterfaceMethod {
2497                class: s(),
2498                interface: s(),
2499                method: s(),
2500            },
2501            IssueKind::MethodSignatureMismatch {
2502                class: s(),
2503                method: s(),
2504                detail: s(),
2505            },
2506            IssueKind::OverriddenMethodAccess {
2507                class: s(),
2508                method: s(),
2509            },
2510            IssueKind::OverriddenPropertyAccess {
2511                class: s(),
2512                property: s(),
2513            },
2514            IssueKind::PropertyTypeRedeclarationMismatch {
2515                class: s(),
2516                property: s(),
2517                expected: s(),
2518                actual: s(),
2519            },
2520            IssueKind::ReadonlyPropertyRedeclarationMismatch {
2521                parent_class: s(),
2522                class: s(),
2523                property: s(),
2524                parent_readonly: true,
2525            },
2526            IssueKind::StaticPropertyRedeclarationMismatch {
2527                parent_class: s(),
2528                class: s(),
2529                property: s(),
2530                parent_static: true,
2531            },
2532            IssueKind::ReadonlyClassExtendsMismatch {
2533                parent: s(),
2534                child: s(),
2535                parent_readonly: true,
2536            },
2537            IssueKind::InvalidReadonlyPropertyDeclaration {
2538                class: s(),
2539                property: s(),
2540            },
2541            IssueKind::BackedEnumCaseTypeMismatch {
2542                enum_name: s(),
2543                case_name: s(),
2544                expected: s(),
2545                actual: s(),
2546            },
2547            IssueKind::InvalidExtendClass {
2548                parent: s(),
2549                child: s(),
2550            },
2551            IssueKind::FinalMethodOverridden {
2552                class: s(),
2553                method: s(),
2554                parent: s(),
2555            },
2556            IssueKind::AbstractInstantiation { class: s() },
2557            IssueKind::AbstractMethodCall {
2558                class: s(),
2559                method: s(),
2560            },
2561            IssueKind::InterfaceInstantiation { class: s() },
2562            IssueKind::InvalidOverride {
2563                class: s(),
2564                method: s(),
2565                detail: s(),
2566            },
2567            IssueKind::CircularInheritance { class: s() },
2568            IssueKind::TaintedInput { sink: s() },
2569            IssueKind::TaintedHtml,
2570            IssueKind::TaintedSql,
2571            IssueKind::TaintedShell,
2572            IssueKind::TaintedLlmPrompt,
2573            IssueKind::InvalidTemplateParam {
2574                name: s(),
2575                expected_bound: s(),
2576                actual: s(),
2577            },
2578            IssueKind::ShadowedTemplateParam { name: s() },
2579            IssueKind::DeprecatedCall {
2580                name: s(),
2581                message: None,
2582            },
2583            IssueKind::DeprecatedProperty {
2584                class: s(),
2585                property: s(),
2586                message: None,
2587            },
2588            IssueKind::DeprecatedConstant {
2589                class: s(),
2590                constant: s(),
2591                message: None,
2592            },
2593            IssueKind::DeprecatedInterface {
2594                name: s(),
2595                message: None,
2596            },
2597            IssueKind::DeprecatedTrait {
2598                name: s(),
2599                message: None,
2600            },
2601            IssueKind::DeprecatedMethodCall {
2602                class: s(),
2603                method: s(),
2604                message: None,
2605            },
2606            IssueKind::DeprecatedMethod {
2607                class: s(),
2608                method: s(),
2609                message: None,
2610            },
2611            IssueKind::DeprecatedClass {
2612                name: s(),
2613                message: None,
2614            },
2615            IssueKind::InternalMethod {
2616                class: s(),
2617                method: s(),
2618            },
2619            IssueKind::MissingReturnType { fn_name: s() },
2620            IssueKind::MissingClosureReturnType,
2621            IssueKind::MissingParamType {
2622                fn_name: s(),
2623                param: s(),
2624            },
2625            IssueKind::MissingPropertyType {
2626                class: s(),
2627                property: s(),
2628            },
2629            IssueKind::MissingThrowsDocblock { class: s() },
2630            IssueKind::InvalidDocblock { message: s() },
2631            IssueKind::MixedArgument {
2632                param: s(),
2633                fn_name: s(),
2634            },
2635            IssueKind::MixedAssignment { var: s() },
2636            IssueKind::MixedMethodCall { method: s() },
2637            IssueKind::UnsupportedReferenceUsage,
2638            IssueKind::NoInterfaceProperties { property: s() },
2639            IssueKind::UndefinedDocblockClass { name: s() },
2640            IssueKind::MissingConstructor { class: s() },
2641            IssueKind::PropertyPossiblyUninitialized {
2642                class: s(),
2643                property: s(),
2644            },
2645            IssueKind::MixedFunctionCall,
2646            IssueKind::MixedReturnStatement { declared: s() },
2647            IssueKind::MixedPropertyFetch { property: s() },
2648            IssueKind::MixedPropertyAssignment { property: s() },
2649            IssueKind::MixedArrayAccess,
2650            IssueKind::MixedArrayOffset,
2651            IssueKind::MixedClone,
2652            IssueKind::InvalidClone { ty: s() },
2653            IssueKind::PossiblyInvalidClone { ty: s() },
2654            IssueKind::InvalidToString { class: s() },
2655            IssueKind::InvalidTraitUse {
2656                trait_name: s(),
2657                reason: s(),
2658            },
2659            IssueKind::ParseError { message: s() },
2660            IssueKind::InvalidThrow { ty: s() },
2661            IssueKind::InvalidCatch { ty: s() },
2662            IssueKind::UnreachableCatch {
2663                ty: s(),
2664                shadowed_by: s(),
2665            },
2666            IssueKind::ImplicitToStringCast { class: s() },
2667            IssueKind::ImplicitFloatToIntCast { from: s() },
2668            IssueKind::WrongCaseFunction {
2669                used: s(),
2670                canonical: s(),
2671            },
2672            IssueKind::WrongCaseMethod {
2673                class: s(),
2674                used: s(),
2675                canonical: s(),
2676            },
2677            IssueKind::WrongCaseClass {
2678                used: s(),
2679                canonical: s(),
2680            },
2681            IssueKind::InvalidAttribute { message: s() },
2682            IssueKind::UndefinedAttributeClass { name: s() },
2683            IssueKind::ForbiddenCode { message: s() },
2684            IssueKind::DuplicateClass { name: s() },
2685            IssueKind::DuplicateInterface { name: s() },
2686            IssueKind::DuplicateTrait { name: s() },
2687            IssueKind::DuplicateEnum { name: s() },
2688            IssueKind::DuplicateFunction { name: s() },
2689        ]
2690    }
2691
2692    #[test]
2693    fn codes_have_expected_shape() {
2694        for kind in one_of_each() {
2695            let code = kind.code();
2696            assert!(
2697                code.len() == 7
2698                    && code.starts_with("MIR")
2699                    && code[3..].chars().all(|c| c.is_ascii_digit()),
2700                "code {code:?} for {} does not match MIR####",
2701                kind.name(),
2702            );
2703        }
2704    }
2705
2706    #[test]
2707    fn codes_are_unique() {
2708        let kinds = one_of_each();
2709        let mut seen: HashSet<&'static str> = HashSet::new();
2710        for kind in &kinds {
2711            assert!(
2712                seen.insert(kind.code()),
2713                "duplicate code {} (variant {})",
2714                kind.code(),
2715                kind.name(),
2716            );
2717        }
2718    }
2719
2720    #[test]
2721    fn default_severity_for_code_round_trips() {
2722        for kind in one_of_each() {
2723            let code = kind.code();
2724            assert_eq!(
2725                IssueKind::default_severity_for_code(code),
2726                Some(kind.default_severity()),
2727                "severity mismatch for {code} (variant {})",
2728                kind.name(),
2729            );
2730        }
2731    }
2732
2733    #[test]
2734    fn default_severity_for_code_unknown_returns_none() {
2735        assert_eq!(IssueKind::default_severity_for_code("MIR9999"), None);
2736        assert_eq!(IssueKind::default_severity_for_code(""), None);
2737        assert_eq!(IssueKind::default_severity_for_code("mir0001"), None);
2738    }
2739
2740    /// Guards against forgetting to add a new variant to `one_of_each()`.
2741    /// If you add a variant, add it to `one_of_each()` *and* bump this count.
2742    #[test]
2743    fn one_of_each_has_every_variant() {
2744        // If this assertion fires after you added a new variant, also add it
2745        // to `one_of_each()` so the uniqueness and shape tests cover it.
2746        assert_eq!(one_of_each().len(), 158);
2747    }
2748}