Skip to main content

mir_issues/
lib.rs

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