Skip to main content

mir_issues/
lib.rs

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