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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
15pub enum Severity {
16 Info,
18 Warning,
20 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
34pub use mir_types::Location;
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub enum CloneFailure {
47 NonObject,
48 Enum,
49 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 NonStaticSelfCall { class: String, method: String },
65 InvalidScope {
66 in_class: bool,
68 },
69 UndefinedVariable { name: String },
72 UndefinedFunction { name: String },
75 UndefinedMethod { class: String, method: String },
78 PossiblyUndefinedMethod { class: String, method: String },
81 UndefinedClass { name: String },
84 UndefinedProperty { class: String, property: String },
87 InaccessibleProperty { class: String, property: String },
92 UndefinedConstant { name: String },
95 InaccessibleClassConstant { class: String, constant: String },
98 PossiblyUndefinedVariable { name: String },
101 UndefinedTrait { name: String },
104 TraitConstantAccessedDirectly {
111 trait_name: String,
112 constant: String,
113 },
114 UndefinedTraitAliasMethod {
122 trait_name: Option<String>,
123 method: String,
124 },
125 ParentNotFound,
128 InvalidStringClass { actual: String },
131 NotAnInterface { name: String },
135
136 NullArgument { param: String, fn_name: String },
140 NullPropertyFetch { property: String },
143 NullMethodCall { method: String },
146 NullArrayAccess,
149 PossiblyNullArgument { param: String, fn_name: String },
152 PossiblyInvalidArgument {
155 param: String,
156 fn_name: String,
157 expected: String,
158 actual: String,
159 },
160 PossiblyNullPropertyFetch { property: String },
163 PossiblyNullMethodCall { method: String },
166 PossiblyNullArrayAccess,
169 NullableReturnStatement { expected: String, actual: String },
172
173 InvalidReturnType { expected: String, actual: String },
177 InvalidArgument {
180 param: String,
181 fn_name: String,
182 expected: String,
183 actual: String,
184 },
185 TooFewArguments {
188 fn_name: String,
189 expected: usize,
190 actual: usize,
191 },
192 TooManyArguments {
195 fn_name: String,
196 expected: usize,
197 actual: usize,
198 },
199 InvalidNamedArgument {
202 fn_name: String,
203 name: String,
204 overwrites: bool,
205 },
206 InvalidNamedArguments { fn_name: String },
209 InvalidPassByReference { fn_name: String, param: String },
212 InvalidPropertyFetch { ty: String },
215 InvalidMethodCall { method: String, ty: String },
218 InvalidMemberName { member: String, ty: String },
221 NativeResourceType { class: String },
224 InvalidUnpack {
227 ty: String,
229 },
230 InvalidArrayAccess { ty: String },
233 PossiblyInvalidArrayAccess { ty: String },
236 InvalidArrayAssignment { ty: String },
239 InvalidPropertyAssignment {
242 property: String,
243 expected: String,
244 actual: String,
245 },
246 PossiblyNullPropertyAssignmentValue {
249 property: String,
250 expected: String,
251 actual: String,
252 },
253 PossiblyFalsePropertyAssignmentValue {
256 property: String,
257 expected: String,
258 actual: String,
259 },
260 PossiblyInvalidPropertyAssignmentValue {
263 property: String,
264 expected: String,
265 actual: String,
266 },
267 InvalidCast { from: String, to: String },
270 InvalidStaticInvocation { class: String, method: String },
273 InvalidOperand {
277 op: String,
278 left: String,
279 right: String,
280 },
281 PossiblyInvalidOperand {
284 op: String,
285 left: String,
286 right: String,
287 },
288 PossiblyNullOperand { op: String, ty: String },
291 DivisionByZero { op: String },
295 RawObjectIteration { ty: String },
298 PossiblyRawObjectIteration { ty: String },
301 InvalidGeneratorIteration { ty: String, send: String },
305 MismatchingDocblockReturnType { declared: String, inferred: String },
308 MismatchingDocblockParamType {
311 param: String,
312 declared: String,
313 inferred: String,
314 },
315 TypeCheckMismatch {
321 var: String,
322 expected: String,
323 actual: String,
324 },
325
326 Trace { variable: String, type_info: String },
329
330 InvalidArrayOffset { expected: String, actual: String },
334 NonExistentArrayOffset { key: String },
338 PossiblyInvalidArrayOffset { expected: String, actual: String },
341 DuplicateArrayKey { key: String },
346
347 RedundantCondition {
351 always_true: bool,
352 unreachable: Option<String>,
354 },
355 RedundantCast { from: String, to: String },
358 UnnecessaryVarAnnotation { var: String },
361 TypeDoesNotContainType { left: String, right: String },
364 ParadoxicalCondition { value: String },
367 DocblockTypeContradiction { expr: String, declared: String },
372 ImpossibleIdenticalComparison {
378 op: String,
379 left: String,
380 right: String,
381 },
382 ImpossibleLooseComparison {
389 op: String,
390 left: String,
391 right: String,
392 },
393 UnevaluatedCode { reason: String },
400
401 UnusedVariable { name: String },
405 UnusedParam { name: String },
408 UnreachableCode,
411 UnhandledMatchCondition { detail: String },
414 UnusedMethod { class: String, method: String },
417 UnusedProperty { class: String, property: String },
420 UnusedFunction { name: String },
423 UnusedForeachValue { name: String },
426 UnusedClass { class: String },
429 UnusedConstant { class: String, constant: String },
432 UnusedSuppress { kind: String },
436
437 ArgumentTypeCoercion {
440 param: String,
441 fn_name: String,
442 expected: String,
443 actual: String,
444 },
445
446 PropertyTypeCoercion {
449 property: String,
450 expected: String,
451 actual: String,
452 },
453
454 ImpurePropertyAssignment { property: String },
457 ImpureMethodCall { method: String },
459 ImpureGlobalVariable { variable: String },
461 ImpureStaticVariable { variable: String },
463 ImpureStaticPropertyAssignment { class: String, property: String },
467 ImpureStaticPropertyAccess { class: String, property: String },
472 ImpureByRefAssignment { variable: String },
477 ImpureFunctionCall { fn_name: String },
481 ImmutablePropertyModification { receiver: String, property: String },
487
488 ReadonlyPropertyAssignment {
492 class: String,
493 property: String,
494 unset: bool,
495 },
496 ReadonlyPropertyAlreadyInitialized { class: String, property: String },
503
504 UnimplementedAbstractMethod { class: String, method: String },
508 UnimplementedInterfaceMethod {
511 class: String,
512 interface: String,
513 method: String,
514 },
515 MethodSignatureMismatch {
518 class: String,
519 method: String,
520 detail: String,
521 },
522 OverriddenMethodAccess {
525 class: String,
526 method: String,
527 parent: String,
528 visibility: String,
529 },
530 OverriddenPropertyAccess {
533 class: String,
534 property: String,
535 parent: String,
536 visibility: String,
537 },
538 PropertyTypeRedeclarationMismatch {
541 class: String,
542 property: String,
543 parent: String,
544 expected: String,
545 covariant: bool,
547 before_php85: bool,
549 },
550 NonInvariantDocblockPropertyType {
553 class: String,
554 property: String,
555 parent: String,
556 expected: String,
557 actual: String,
558 },
559 ReadonlyPropertyRedeclarationMismatch {
562 parent_class: String,
563 class: String,
564 property: String,
565 parent_readonly: bool,
568 },
569 StaticPropertyRedeclarationMismatch {
572 parent_class: String,
573 class: String,
574 property: String,
575 parent_static: bool,
578 },
579 ReadonlyClassExtendsMismatch {
585 parent: String,
586 child: String,
587 parent_readonly: bool,
590 },
591 InvalidReadonlyPropertyDeclaration { class: String, property: String },
597 BackedEnumCaseTypeMismatch {
600 enum_name: String,
601 case_name: String,
602 expected: String,
603 actual: String,
604 },
605 DuplicateEnumCaseValue {
609 enum_name: String,
610 first_case: String,
611 case_name: String,
612 },
613 DirectConstructorCall { class: String },
616 InvalidExtendClass {
619 parent: String,
620 child: String,
621 #[serde(default)]
623 reason: Option<String>,
624 },
625 FinalMethodOverridden {
628 class: String,
629 method: String,
630 parent: String,
631 },
632 AbstractInstantiation { class: String },
635 AbstractMethodCall { class: String, method: String },
638 InterfaceInstantiation { class: String },
641 EnumInstantiation { class: String },
644 TraitInstantiation { class: String },
647 InvalidDynamicProperty { class: String, property: String },
651 InvalidOverride { class: String, member: String },
656
657 TaintedInput { sink: String },
661 TaintedHtml,
664 TaintedSql,
667 TaintedShell,
670 TaintedLlmPrompt,
674 TaintedHeader,
677 TaintedCookie,
680 TaintedSsrf,
683 TaintedLdap,
686 TaintedXpath,
689 TaintedCallable,
692 TaintedFile,
695 TaintedInclude,
698 TaintedEval,
701 TaintedUnserialize,
704
705 InvalidTemplateParam {
709 name: String,
710 expected_bound: String,
711 actual: String,
712 },
713 ShadowedTemplateParam { name: String },
716 IfThisIsMismatch {
721 class: String,
722 method: String,
723 expected: String,
724 actual: String,
725 },
726
727 DeprecatedCall {
731 name: String,
732 message: Option<Arc<str>>,
733 },
734 DeprecatedProperty {
737 class: String,
738 property: String,
739 message: Option<Arc<str>>,
740 },
741 DeprecatedConstant {
744 class: String,
745 constant: String,
746 message: Option<Arc<str>>,
747 },
748 OptionalParameterBeforeRequired { message: String },
753 ImplicitlyNullableParameter { message: String },
758 DynamicPropertyCreation { class: String, property: String },
762 DeprecatedInterface {
765 name: String,
766 message: Option<Arc<str>>,
767 },
768 DeprecatedTrait {
771 name: String,
772 message: Option<Arc<str>>,
773 },
774 DeprecatedMethodCall {
777 class: String,
778 method: String,
779 message: Option<Arc<str>>,
780 },
781 DeprecatedMethod {
784 class: String,
785 method: String,
786 message: Option<Arc<str>>,
787 },
788 DeprecatedClass {
791 name: String,
792 message: Option<Arc<str>>,
793 },
794 InternalMethod { class: String, method: String },
797 MissingReturnType { fn_name: String },
800 MissingClosureReturnType,
803 MissingParamType { fn_name: String, param: String },
806 MissingPropertyType { class: String, property: String },
809 InvalidThrow { ty: String },
812 InvalidCatch { ty: String },
815 UnreachableCatch { ty: String, shadowed_by: String },
820 MissingThrowsDocblock { class: String },
823 UndefinedThrowsDocblock { name: String },
828 ImplicitToStringCast { class: String },
831 ImplicitFloatToIntCast { from: String },
834 ParseError {
837 message: String,
838 code: String,
840 },
841 CompileError {
844 message: String,
845 code: String,
847 },
848 InvalidDocblock { message: String },
851 InvalidDocblockType { message: String },
858 MixedArgument { param: String, fn_name: String },
861 MixedAssignment { var: String },
864 MixedMethodCall { method: String },
867 UnsupportedReferenceUsage,
870 NoInterfaceProperties { property: String },
874 UndefinedDocblockClass { name: String },
878 MissingConstructor { class: String },
881 PropertyPossiblyUninitialized { class: String, property: String },
893 MixedFunctionCall,
896 MixedReturnStatement { declared: String },
899 MixedPropertyFetch { property: String },
902 MixedPropertyAssignment { property: String },
905 MixedArrayAccess,
908 MixedArrayOffset,
911 MixedClone,
914 InvalidClone { ty: String, reason: CloneFailure },
919 PossiblyInvalidClone { ty: String },
923 InvalidToString { class: String },
927 CircularInheritance { class: String },
930
931 InvalidTraitUse { trait_name: String, reason: String },
935 ForbiddenCode { message: String },
938
939 InvalidAttribute { message: String },
943 UndefinedAttributeClass { name: String },
946
947 WrongCaseFunction { used: String, canonical: String },
951 WrongCaseMethod {
954 class: String,
955 used: String,
956 canonical: String,
957 },
958 WrongCaseClass { used: String, canonical: String },
961 DuplicateClass { name: String },
964 DuplicateInterface { name: String },
967 DuplicateTrait { name: String },
970 DuplicateEnum { name: String },
973 DuplicateFunction { name: String },
976
977 UseStatementHasNoEffect { name: String },
983 PrivateFinalMethod { class: String, method: String },
988 NonPublicMagicMethod { class: String, method: String },
993 NoDiscardReturnIgnored {
997 callee: String,
999 message: Option<String>,
1000 },
1001
1002 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 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 pub fn default_severity(&self) -> Severity {
1031 match self {
1032 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 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 IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
1156
1157 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 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 IssueKind::PluginIssue { .. } => Severity::Error,
1245 }
1246 }
1247
1248 pub fn code(&self) -> &'static str {
1278 match self {
1279 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 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 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 IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1351 IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1352 IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1353 IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1354
1355 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 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 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 IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1399 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1400
1401 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 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 IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1444 IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1445 IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1446
1447 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 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 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 IssueKind::InvalidTraitUse { .. } => "MIR1300",
1489 IssueKind::ForbiddenCode { .. } => "MIR1301",
1490
1491 IssueKind::ParseError { .. } => "MIR1400",
1493 IssueKind::CompileError { .. } => "MIR1401",
1494
1495 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 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 pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1524 match code {
1525 "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 "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 "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 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 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 pub fn display_name(&self) -> &str {
1834 match self {
1835 IssueKind::PluginIssue { name, .. } => name,
1836 other => other.name(),
1837 }
1838 }
1839
1840 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#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2685pub struct TaintStep {
2686 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 #[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#[derive(Debug, Default)]
2732pub struct IssueBuffer {
2733 issues: Vec<Issue>,
2734 seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
2735 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 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 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 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 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 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 pub fn issue_count(&self) -> usize {
2846 self.issues.len()
2847 }
2848
2849 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 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 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 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 #[test]
3496 fn one_of_each_has_every_variant() {
3497 assert_eq!(one_of_each().len(), 193);
3500 }
3501}