Skip to main content

mir_issues/
lib.rs

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