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