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 LessSpecificReturnStatement { expected: String, actual: String },
180 InvalidArgument {
183 param: String,
184 fn_name: String,
185 expected: String,
186 actual: String,
187 },
188 InvalidScalarArgument {
191 param: String,
192 fn_name: String,
193 expected: String,
194 actual: String,
195 },
196 TooFewArguments {
199 fn_name: String,
200 expected: usize,
201 actual: usize,
202 },
203 TooManyArguments {
206 fn_name: String,
207 expected: usize,
208 actual: usize,
209 },
210 InvalidNamedArgument {
213 fn_name: String,
214 name: String,
215 overwrites: bool,
216 },
217 InvalidNamedArguments { fn_name: String },
220 InvalidPassByReference { fn_name: String, param: String },
223 InvalidPropertyFetch { ty: String },
226 InvalidMethodCall { method: String, ty: String },
229 InvalidMemberName { member: String, ty: String },
232 NativeResourceType { class: String },
235 InvalidUnpack {
238 ty: String,
240 },
241 InvalidArrayAccess { ty: String },
244 PossiblyInvalidArrayAccess { ty: String },
247 InvalidArrayAssignment { ty: String },
250 InvalidPropertyAssignment {
253 property: String,
254 expected: String,
255 actual: String,
256 },
257 PossiblyNullPropertyAssignmentValue {
260 property: String,
261 expected: String,
262 actual: String,
263 },
264 PossiblyFalsePropertyAssignmentValue {
267 property: String,
268 expected: String,
269 actual: String,
270 },
271 PossiblyInvalidPropertyAssignmentValue {
274 property: String,
275 expected: String,
276 actual: String,
277 },
278 InvalidCast { from: String, to: String },
281 InvalidStaticInvocation { class: String, method: String },
284 InvalidOperand {
288 op: String,
289 left: String,
290 right: String,
291 },
292 PossiblyInvalidOperand {
295 op: String,
296 left: String,
297 right: String,
298 },
299 PossiblyNullOperand { op: String, ty: String },
302 DivisionByZero { op: String },
306 RawObjectIteration { ty: String },
309 PossiblyRawObjectIteration { ty: String },
312 InvalidGeneratorIteration { ty: String, send: String },
316 MismatchingDocblockReturnType { declared: String, inferred: String },
319 MismatchingDocblockParamType {
322 param: String,
323 declared: String,
324 inferred: String,
325 },
326 TypeCheckMismatch {
332 var: String,
333 expected: String,
334 actual: String,
335 },
336
337 Trace { variable: String, type_info: String },
340
341 InvalidArrayOffset { expected: String, actual: String },
345 NonExistentArrayOffset { key: String },
349 PossiblyInvalidArrayOffset { expected: String, actual: String },
352 DuplicateArrayKey { key: String },
357
358 RedundantCondition {
362 always_true: bool,
363 unreachable: Option<String>,
365 },
366 RedundantCast { from: String, to: String },
369 UnnecessaryVarAnnotation { var: String },
372 TypeDoesNotContainType { left: String, right: String },
375 ParadoxicalCondition { value: String },
378 DocblockTypeContradiction { expr: String, declared: String },
383 ImpossibleIdenticalComparison {
389 op: String,
390 left: String,
391 right: String,
392 },
393 ImpossibleLooseComparison {
400 op: String,
401 left: String,
402 right: String,
403 },
404 UnevaluatedCode { reason: String },
411
412 UnusedVariable { name: String },
416 UnusedParam { name: String },
419 UnreachableCode,
422 UnhandledMatchCondition { detail: String },
425 UnusedMethod { class: String, method: String },
428 UnusedProperty { class: String, property: String },
431 UnusedFunction { name: String },
434 UnusedForeachValue { name: String },
437 UnusedClass { class: String },
440 UnusedConstant { class: String, constant: String },
443 UnusedSuppress { kind: String },
447
448 ArgumentTypeCoercion {
451 param: String,
452 fn_name: String,
453 expected: String,
454 actual: String,
455 },
456
457 PropertyTypeCoercion {
460 property: String,
461 expected: String,
462 actual: String,
463 },
464
465 ImpurePropertyAssignment { property: String },
468 ImpureMethodCall { method: String },
470 ImpureGlobalVariable { variable: String },
472 ImpureStaticVariable { variable: String },
474 ImpureStaticPropertyAssignment { class: String, property: String },
478 ImpureStaticPropertyAccess { class: String, property: String },
483 ImpureByRefAssignment { variable: String },
488 ImpureFunctionCall { fn_name: String },
492 ImmutablePropertyModification { receiver: String, property: String },
498
499 ReadonlyPropertyAssignment {
503 class: String,
504 property: String,
505 unset: bool,
506 },
507 ReadonlyPropertyAlreadyInitialized { class: String, property: String },
514
515 UnimplementedAbstractMethod { class: String, method: String },
519 UnimplementedInterfaceMethod {
522 class: String,
523 interface: String,
524 method: String,
525 },
526 MethodSignatureMismatch {
529 class: String,
530 method: String,
531 detail: String,
532 },
533 OverriddenMethodAccess {
536 class: String,
537 method: String,
538 parent: String,
539 visibility: String,
540 },
541 OverriddenPropertyAccess {
544 class: String,
545 property: String,
546 parent: String,
547 visibility: String,
548 },
549 PropertyTypeRedeclarationMismatch {
552 class: String,
553 property: String,
554 parent: String,
555 expected: String,
556 covariant: bool,
558 before_php85: bool,
560 },
561 NonInvariantDocblockPropertyType {
564 class: String,
565 property: String,
566 parent: String,
567 expected: String,
568 actual: String,
569 },
570 ReadonlyPropertyRedeclarationMismatch {
573 parent_class: String,
574 class: String,
575 property: String,
576 parent_readonly: bool,
579 },
580 StaticPropertyRedeclarationMismatch {
583 parent_class: String,
584 class: String,
585 property: String,
586 parent_static: bool,
589 },
590 ReadonlyClassExtendsMismatch {
596 parent: String,
597 child: String,
598 parent_readonly: bool,
601 },
602 InvalidReadonlyPropertyDeclaration { class: String, property: String },
608 BackedEnumCaseTypeMismatch {
611 enum_name: String,
612 case_name: String,
613 expected: String,
614 actual: String,
615 },
616 DuplicateEnumCaseValue {
620 enum_name: String,
621 first_case: String,
622 case_name: String,
623 },
624 DirectConstructorCall { class: String },
627 InvalidExtendClass {
630 parent: String,
631 child: String,
632 #[serde(default)]
634 reason: Option<String>,
635 },
636 FinalMethodOverridden {
639 class: String,
640 method: String,
641 parent: String,
642 },
643 AbstractInstantiation { class: String },
646 AbstractMethodCall { class: String, method: String },
649 InterfaceInstantiation { class: String },
652 EnumInstantiation { class: String },
655 TraitInstantiation { class: String },
658 InvalidDynamicProperty { class: String, property: String },
662 InvalidOverride { class: String, member: String },
667
668 TaintedInput { sink: String },
672 TaintedHtml,
675 TaintedSql,
678 TaintedShell,
681 TaintedLlmPrompt,
685 TaintedHeader,
688 TaintedCookie,
691 TaintedSsrf,
694 TaintedLdap,
697 TaintedXpath,
700 TaintedCallable,
703 TaintedFile,
706 TaintedInclude,
709 TaintedEval,
712 TaintedUnserialize,
715
716 InvalidTemplateParam {
720 name: String,
721 expected_bound: String,
722 actual: String,
723 },
724 ShadowedTemplateParam { name: String },
727 IfThisIsMismatch {
732 class: String,
733 method: String,
734 expected: String,
735 actual: String,
736 },
737
738 DeprecatedCall {
742 name: String,
743 message: Option<Arc<str>>,
744 },
745 DeprecatedProperty {
748 class: String,
749 property: String,
750 message: Option<Arc<str>>,
751 },
752 DeprecatedConstant {
755 class: String,
756 constant: String,
757 message: Option<Arc<str>>,
758 },
759 OptionalParameterBeforeRequired { message: String },
764 ImplicitlyNullableParameter { message: String },
769 DynamicPropertyCreation { class: String, property: String },
773 DeprecatedInterface {
776 name: String,
777 message: Option<Arc<str>>,
778 },
779 DeprecatedTrait {
782 name: String,
783 message: Option<Arc<str>>,
784 },
785 DeprecatedMethodCall {
788 class: String,
789 method: String,
790 message: Option<Arc<str>>,
791 },
792 DeprecatedMethod {
795 class: String,
796 method: String,
797 message: Option<Arc<str>>,
798 },
799 DeprecatedClass {
802 name: String,
803 message: Option<Arc<str>>,
804 },
805 InternalMethod { class: String, method: String },
808 MissingReturnType { fn_name: String },
811 MissingClosureReturnType,
814 MissingParamType { fn_name: String, param: String },
817 MissingPropertyType { class: String, property: String },
820 InvalidThrow { ty: String },
823 InvalidCatch { ty: String },
826 UnreachableCatch { ty: String, shadowed_by: String },
831 MissingThrowsDocblock { class: String },
834 UndefinedThrowsDocblock { name: String },
839 ImplicitToStringCast { class: String },
842 ImplicitFloatToIntCast { from: String },
845 ParseError {
848 message: String,
849 code: String,
851 },
852 CompileError {
855 message: String,
856 code: String,
858 },
859 InvalidDocblock { message: String },
862 InvalidDocblockType { message: String },
869 MixedArgument { param: String, fn_name: String },
872 MixedAssignment { var: String },
875 MixedMethodCall { method: String },
878 UnsupportedReferenceUsage,
881 NoInterfaceProperties { property: String },
885 UndefinedDocblockClass { name: String },
889 MissingConstructor { class: String },
892 PropertyPossiblyUninitialized { class: String, property: String },
904 MixedFunctionCall,
907 MixedReturnStatement { declared: String },
910 MixedPropertyFetch { property: String },
913 MixedPropertyAssignment { property: String },
916 MixedArrayAccess,
919 MixedArrayOffset,
922 MixedClone,
925 InvalidClone { ty: String, reason: CloneFailure },
930 PossiblyInvalidClone { ty: String },
934 InvalidToString { class: String },
938 CircularInheritance { class: String },
941
942 InvalidTraitUse { trait_name: String, reason: String },
946 ForbiddenCode { message: String },
949
950 InvalidAttribute { message: String },
954 UndefinedAttributeClass { name: String },
957
958 WrongCaseFunction { used: String, canonical: String },
962 WrongCaseMethod {
965 class: String,
966 used: String,
967 canonical: String,
968 },
969 WrongCaseClass { used: String, canonical: String },
972 DuplicateClass { name: String },
975 DuplicateInterface { name: String },
978 DuplicateTrait { name: String },
981 DuplicateEnum { name: String },
984 DuplicateFunction { name: String },
987
988 UseStatementHasNoEffect { name: String },
994 PrivateFinalMethod { class: String, method: String },
999 NonPublicMagicMethod { class: String, method: String },
1004 NoDiscardReturnIgnored {
1008 callee: String,
1010 message: Option<String>,
1011 },
1012
1013 PluginIssue { name: String, message: String },
1017}
1018
1019fn append_deprecation_message(base: String, message: &Option<Arc<str>>) -> String {
1020 match message.as_deref().filter(|m| !m.is_empty()) {
1021 Some(msg) => format!("{base}: {msg}"),
1022 None => base,
1023 }
1024}
1025
1026impl IssueKind {
1027 pub fn is_constant_condition(&self) -> bool {
1029 matches!(
1030 self,
1031 IssueKind::RedundantCondition { .. }
1032 | IssueKind::ImpossibleIdenticalComparison { .. }
1033 | IssueKind::ImpossibleLooseComparison { .. }
1034 | IssueKind::TypeDoesNotContainType { .. }
1035 | IssueKind::DocblockTypeContradiction { .. }
1036 | IssueKind::ParadoxicalCondition { .. }
1037 )
1038 }
1039
1040 pub fn default_severity(&self) -> Severity {
1042 match self {
1043 IssueKind::NonStaticSelfCall { .. }
1045 | IssueKind::DirectConstructorCall { .. }
1046 | IssueKind::InvalidScope { .. }
1047 | IssueKind::UndefinedVariable { .. }
1048 | IssueKind::UndefinedFunction { .. }
1049 | IssueKind::UndefinedMethod { .. }
1050 | IssueKind::UndefinedClass { .. }
1051 | IssueKind::NotAnInterface { .. }
1052 | IssueKind::UndefinedConstant { .. }
1053 | IssueKind::InaccessibleClassConstant { .. }
1054 | IssueKind::InaccessibleProperty { .. }
1055 | IssueKind::InvalidReturnType { .. }
1056 | IssueKind::InvalidArgument { .. }
1057 | IssueKind::InvalidUnpack { .. }
1058 | IssueKind::TooFewArguments { .. }
1059 | IssueKind::TooManyArguments { .. }
1060 | IssueKind::InvalidNamedArgument { .. }
1061 | IssueKind::InvalidNamedArguments { .. }
1062 | IssueKind::InvalidPassByReference { .. }
1063 | IssueKind::InvalidThrow { .. }
1064 | IssueKind::InvalidCatch { .. }
1065 | IssueKind::InvalidStaticInvocation { .. }
1066 | IssueKind::UnimplementedAbstractMethod { .. }
1067 | IssueKind::UnimplementedInterfaceMethod { .. }
1068 | IssueKind::MethodSignatureMismatch { .. }
1069 | IssueKind::InvalidExtendClass { .. }
1070 | IssueKind::FinalMethodOverridden { .. }
1071 | IssueKind::OverriddenMethodAccess { .. }
1072 | IssueKind::OverriddenPropertyAccess { .. }
1073 | IssueKind::AbstractInstantiation { .. }
1074 | IssueKind::AbstractMethodCall { .. }
1075 | IssueKind::InterfaceInstantiation { .. }
1076 | IssueKind::EnumInstantiation { .. }
1077 | IssueKind::TraitInstantiation { .. }
1078 | IssueKind::InvalidDynamicProperty { .. }
1079 | IssueKind::InvalidOverride { .. }
1080 | IssueKind::InvalidTemplateParam { .. }
1081 | IssueKind::ReadonlyPropertyAssignment { .. }
1082 | IssueKind::ReadonlyPropertyAlreadyInitialized { .. }
1083 | IssueKind::ParseError { .. }
1084 | IssueKind::CompileError { .. }
1085 | IssueKind::TaintedInput { .. }
1086 | IssueKind::TaintedHtml
1087 | IssueKind::TaintedSql
1088 | IssueKind::TaintedShell
1089 | IssueKind::TaintedLlmPrompt
1090 | IssueKind::TaintedHeader
1091 | IssueKind::TaintedCookie
1092 | IssueKind::TaintedSsrf
1093 | IssueKind::TaintedLdap
1094 | IssueKind::TaintedXpath
1095 | IssueKind::TaintedCallable
1096 | IssueKind::TaintedFile
1097 | IssueKind::TaintedInclude
1098 | IssueKind::TaintedEval
1099 | IssueKind::TaintedUnserialize
1100 | IssueKind::CircularInheritance { .. }
1101 | IssueKind::InvalidTraitUse { .. }
1102 | IssueKind::UndefinedTrait { .. }
1103 | IssueKind::TraitConstantAccessedDirectly { .. }
1104 | IssueKind::UndefinedTraitAliasMethod { .. }
1105 | IssueKind::InvalidClone { .. }
1106 | IssueKind::InvalidToString { .. }
1107 | IssueKind::TypeCheckMismatch { .. }
1108 | IssueKind::PropertyTypeRedeclarationMismatch { .. }
1109 | IssueKind::ReadonlyPropertyRedeclarationMismatch { .. }
1110 | IssueKind::StaticPropertyRedeclarationMismatch { .. }
1111 | IssueKind::ReadonlyClassExtendsMismatch { .. }
1112 | IssueKind::InvalidReadonlyPropertyDeclaration { .. }
1113 | IssueKind::BackedEnumCaseTypeMismatch { .. }
1114 | IssueKind::DuplicateEnumCaseValue { .. }
1115 | IssueKind::DivisionByZero { .. }
1116 | IssueKind::InvalidMemberName { .. }
1117 | IssueKind::NativeResourceType { .. }
1118 | IssueKind::ParentNotFound => Severity::Error,
1119 IssueKind::Trace { .. } => Severity::Info,
1120
1121 IssueKind::NullArgument { .. }
1123 | IssueKind::NullPropertyFetch { .. }
1124 | IssueKind::NullMethodCall { .. }
1125 | IssueKind::NullArrayAccess
1126 | IssueKind::NullableReturnStatement { .. }
1127 | IssueKind::InvalidPropertyFetch { .. }
1128 | IssueKind::InvalidMethodCall { .. }
1129 | IssueKind::InvalidArrayAccess { .. }
1130 | IssueKind::InvalidArrayAssignment { .. }
1131 | IssueKind::InvalidPropertyAssignment { .. }
1132 | IssueKind::InvalidArrayOffset { .. }
1133 | IssueKind::NonExistentArrayOffset { .. }
1134 | IssueKind::PossiblyInvalidArrayOffset { .. }
1135 | IssueKind::UndefinedProperty { .. }
1136 | IssueKind::InvalidOperand { .. }
1137 | IssueKind::InvalidScalarArgument { .. }
1138 | IssueKind::ImplicitToStringCast { .. }
1139 | IssueKind::ImplicitFloatToIntCast { .. }
1140 | IssueKind::UnusedVariable { .. }
1141 | IssueKind::UnusedForeachValue { .. }
1142 | IssueKind::ImpurePropertyAssignment { .. }
1143 | IssueKind::ImpureMethodCall { .. }
1144 | IssueKind::ImpureGlobalVariable { .. }
1145 | IssueKind::ImpureStaticVariable { .. }
1146 | IssueKind::ImpureStaticPropertyAssignment { .. }
1147 | IssueKind::ImpureStaticPropertyAccess { .. }
1148 | IssueKind::ImpureFunctionCall { .. }
1149 | IssueKind::ImpureByRefAssignment { .. }
1150 | IssueKind::ImmutablePropertyModification { .. }
1151 | IssueKind::UnsupportedReferenceUsage
1152 | IssueKind::ParadoxicalCondition { .. }
1153 | IssueKind::UnhandledMatchCondition { .. }
1154 | IssueKind::InvalidStringClass { .. }
1155 | IssueKind::ImpossibleIdenticalComparison { .. }
1156 | IssueKind::ImpossibleLooseComparison { .. }
1157 | IssueKind::DuplicateArrayKey { .. }
1158 | IssueKind::ForbiddenCode { .. }
1159 | IssueKind::UndefinedThrowsDocblock { .. }
1160 | IssueKind::InvalidDocblockType { .. }
1161 | IssueKind::UseStatementHasNoEffect { .. }
1162 | IssueKind::PrivateFinalMethod { .. }
1163 | IssueKind::NonPublicMagicMethod { .. }
1164 | IssueKind::NoDiscardReturnIgnored { .. } => Severity::Warning,
1165
1166 IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
1168
1169 IssueKind::PossiblyNullArgument { .. }
1171 | IssueKind::PossiblyInvalidArgument { .. }
1172 | IssueKind::PossiblyNullPropertyFetch { .. }
1173 | IssueKind::PossiblyNullMethodCall { .. }
1174 | IssueKind::PossiblyUndefinedMethod { .. }
1175 | IssueKind::PossiblyNullArrayAccess
1176 | IssueKind::PossiblyInvalidArrayAccess { .. }
1177 | IssueKind::PossiblyInvalidClone { .. }
1178 | IssueKind::PossiblyInvalidOperand { .. }
1179 | IssueKind::PossiblyNullOperand { .. }
1180 | IssueKind::PossiblyRawObjectIteration { .. }
1181 | IssueKind::InvalidGeneratorIteration { .. }
1182 | IssueKind::PossiblyNullPropertyAssignmentValue { .. }
1183 | IssueKind::PossiblyFalsePropertyAssignmentValue { .. }
1184 | IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => Severity::Info,
1185
1186 IssueKind::RawObjectIteration { .. } => Severity::Warning,
1187
1188 IssueKind::RedundantCondition { .. }
1190 | IssueKind::RedundantCast { .. }
1191 | IssueKind::UnnecessaryVarAnnotation { .. }
1192 | IssueKind::TypeDoesNotContainType { .. }
1193 | IssueKind::DocblockTypeContradiction { .. }
1194 | IssueKind::UnevaluatedCode { .. }
1195 | IssueKind::IfThisIsMismatch { .. }
1196 | IssueKind::UnusedParam { .. }
1197 | IssueKind::UnreachableCode
1198 | IssueKind::UnreachableCatch { .. }
1199 | IssueKind::UnusedMethod { .. }
1200 | IssueKind::UnusedProperty { .. }
1201 | IssueKind::UnusedFunction { .. }
1202 | IssueKind::UnusedClass { .. }
1203 | IssueKind::UnusedConstant { .. }
1204 | IssueKind::UnusedSuppress { .. }
1205 | IssueKind::ArgumentTypeCoercion { .. }
1206 | IssueKind::PropertyTypeCoercion { .. }
1207 | IssueKind::LessSpecificReturnStatement { .. }
1208 | IssueKind::DeprecatedCall { .. }
1209 | IssueKind::DeprecatedProperty { .. }
1210 | IssueKind::DeprecatedConstant { .. }
1211 | IssueKind::OptionalParameterBeforeRequired { .. }
1212 | IssueKind::ImplicitlyNullableParameter { .. }
1213 | IssueKind::DynamicPropertyCreation { .. }
1214 | IssueKind::DeprecatedInterface { .. }
1215 | IssueKind::DeprecatedTrait { .. }
1216 | IssueKind::DeprecatedMethodCall { .. }
1217 | IssueKind::DeprecatedMethod { .. }
1218 | IssueKind::DeprecatedClass { .. }
1219 | IssueKind::InternalMethod { .. }
1220 | IssueKind::MissingReturnType { .. }
1221 | IssueKind::MissingClosureReturnType
1222 | IssueKind::MissingParamType { .. }
1223 | IssueKind::MissingPropertyType { .. }
1224 | IssueKind::MismatchingDocblockReturnType { .. }
1225 | IssueKind::MismatchingDocblockParamType { .. }
1226 | IssueKind::InvalidDocblock { .. }
1227 | IssueKind::InvalidCast { .. }
1228 | IssueKind::MixedArgument { .. }
1229 | IssueKind::MixedAssignment { .. }
1230 | IssueKind::MixedMethodCall { .. }
1231 | IssueKind::NoInterfaceProperties { .. }
1232 | IssueKind::UndefinedDocblockClass { .. }
1233 | IssueKind::MissingConstructor { .. }
1234 | IssueKind::PropertyPossiblyUninitialized { .. }
1235 | IssueKind::MixedFunctionCall
1236 | IssueKind::MixedReturnStatement { .. }
1237 | IssueKind::MixedPropertyFetch { .. }
1238 | IssueKind::MixedPropertyAssignment { .. }
1239 | IssueKind::MixedArrayAccess
1240 | IssueKind::MixedArrayOffset
1241 | IssueKind::MixedClone
1242 | IssueKind::ShadowedTemplateParam { .. }
1243 | IssueKind::MissingThrowsDocblock { .. }
1244 | IssueKind::WrongCaseFunction { .. }
1245 | IssueKind::WrongCaseMethod { .. }
1246 | IssueKind::WrongCaseClass { .. }
1247 | IssueKind::InvalidAttribute { .. }
1248 | IssueKind::UndefinedAttributeClass { .. }
1249 | IssueKind::NonInvariantDocblockPropertyType { .. } => Severity::Info,
1250 IssueKind::DuplicateClass { .. }
1251 | IssueKind::DuplicateInterface { .. }
1252 | IssueKind::DuplicateTrait { .. }
1253 | IssueKind::DuplicateEnum { .. }
1254 | IssueKind::DuplicateFunction { .. } => Severity::Error,
1255 IssueKind::PluginIssue { .. } => Severity::Error,
1258 }
1259 }
1260
1261 pub fn code(&self) -> &'static str {
1291 match self {
1292 IssueKind::NonStaticSelfCall { .. } => "MIR0216",
1294 IssueKind::DirectConstructorCall { .. } => "MIR0217",
1295 IssueKind::InvalidScope { .. } => "MIR0001",
1296 IssueKind::UndefinedVariable { .. } => "MIR0002",
1297 IssueKind::UndefinedFunction { .. } => "MIR0003",
1298 IssueKind::UndefinedMethod { .. } => "MIR0004",
1299 IssueKind::PossiblyUndefinedMethod { .. } => "MIR0015",
1300 IssueKind::InvalidDynamicProperty { .. } => "MIR0016",
1301 IssueKind::UndefinedClass { .. } => "MIR0005",
1302 IssueKind::UndefinedProperty { .. } => "MIR0006",
1303 IssueKind::UndefinedConstant { .. } => "MIR0007",
1304 IssueKind::InaccessibleClassConstant { .. } => "MIR0011",
1305 IssueKind::InaccessibleProperty { .. } => "MIR0014",
1306 IssueKind::TraitConstantAccessedDirectly { .. } => "MIR0012",
1307 IssueKind::UndefinedTraitAliasMethod { .. } => "MIR0013",
1308 IssueKind::PossiblyUndefinedVariable { .. } => "MIR0008",
1309 IssueKind::UndefinedTrait { .. } => "MIR0009",
1310 IssueKind::ParentNotFound => "MIR0010",
1311
1312 IssueKind::NullArgument { .. } => "MIR0100",
1314 IssueKind::NullPropertyFetch { .. } => "MIR0101",
1315 IssueKind::NullMethodCall { .. } => "MIR0102",
1316 IssueKind::NullArrayAccess => "MIR0103",
1317 IssueKind::PossiblyNullArgument { .. } => "MIR0104",
1318 IssueKind::PossiblyInvalidArgument { .. } => "MIR0105",
1319 IssueKind::PossiblyNullPropertyFetch { .. } => "MIR0106",
1320 IssueKind::PossiblyNullMethodCall { .. } => "MIR0107",
1321 IssueKind::PossiblyNullArrayAccess => "MIR0108",
1322 IssueKind::NullableReturnStatement { .. } => "MIR0109",
1323 IssueKind::LessSpecificReturnStatement { .. } => "MIR0110",
1324
1325 IssueKind::InvalidReturnType { .. } => "MIR0200",
1327 IssueKind::InvalidArgument { .. } => "MIR0201",
1328 IssueKind::InvalidScalarArgument { .. } => "MIR0238",
1329 IssueKind::TooFewArguments { .. } => "MIR0202",
1330 IssueKind::TooManyArguments { .. } => "MIR0203",
1331 IssueKind::InvalidNamedArgument { .. } => "MIR0204",
1332 IssueKind::InvalidNamedArguments { .. } => "MIR0224",
1333 IssueKind::InvalidPassByReference { .. } => "MIR0205",
1334 IssueKind::InvalidPropertyFetch { .. } => "MIR0218",
1335 IssueKind::InvalidArrayAccess { .. } => "MIR0219",
1336 IssueKind::PossiblyInvalidArrayAccess { .. } => "MIR0227",
1337 IssueKind::InvalidArrayAssignment { .. } => "MIR0220",
1338 IssueKind::InvalidPropertyAssignment { .. } => "MIR0206",
1339 IssueKind::PossiblyNullPropertyAssignmentValue { .. } => "MIR0232",
1340 IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => "MIR0233",
1341 IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => "MIR0234",
1342 IssueKind::InvalidCast { .. } => "MIR0207",
1343 IssueKind::InvalidStaticInvocation { .. } => "MIR0215",
1344 IssueKind::InvalidOperand { .. } => "MIR0208",
1345 IssueKind::PossiblyInvalidOperand { .. } => "MIR0213",
1346 IssueKind::PossiblyNullOperand { .. } => "MIR0214",
1347 IssueKind::DivisionByZero { .. } => "MIR0229",
1348 IssueKind::InvalidMethodCall { .. } => "MIR0230",
1349 IssueKind::InvalidMemberName { .. } => "MIR0235",
1350 IssueKind::NativeResourceType { .. } => "MIR0236",
1351 IssueKind::InvalidUnpack { .. } => "MIR0231",
1352 IssueKind::RawObjectIteration { .. } => "MIR0222",
1353 IssueKind::PossiblyRawObjectIteration { .. } => "MIR0223",
1354 IssueKind::InvalidGeneratorIteration { .. } => "MIR0237",
1355 IssueKind::MismatchingDocblockReturnType { .. } => "MIR0209",
1356 IssueKind::MismatchingDocblockParamType { .. } => "MIR0210",
1357 IssueKind::InvalidStringClass { .. } => "MIR0211",
1358 IssueKind::NotAnInterface { .. } => "MIR0228",
1359 IssueKind::TypeCheckMismatch { .. } => "MIR0212",
1360 IssueKind::Trace { .. } => "MIR0221",
1361 IssueKind::ArgumentTypeCoercion { .. } => "MIR0225",
1362 IssueKind::PropertyTypeCoercion { .. } => "MIR0226",
1363
1364 IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1366 IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1367 IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1368 IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1369
1370 IssueKind::RedundantCondition { .. } => "MIR0400",
1372 IssueKind::RedundantCast { .. } => "MIR0401",
1373 IssueKind::UnnecessaryVarAnnotation { .. } => "MIR0402",
1374 IssueKind::TypeDoesNotContainType { .. } => "MIR0403",
1375 IssueKind::ParadoxicalCondition { .. } => "MIR0404",
1376 IssueKind::UnhandledMatchCondition { .. } => "MIR0405",
1377 IssueKind::DocblockTypeContradiction { .. } => "MIR0406",
1378 IssueKind::UnevaluatedCode { .. } => "MIR0407",
1379 IssueKind::ImpossibleIdenticalComparison { .. } => "MIR0408",
1380 IssueKind::ImpossibleLooseComparison { .. } => "MIR0409",
1381
1382 IssueKind::UnusedVariable { .. } => "MIR0500",
1384 IssueKind::UnusedParam { .. } => "MIR0501",
1385 IssueKind::UnreachableCode => "MIR0502",
1386 IssueKind::UnusedMethod { .. } => "MIR0503",
1387 IssueKind::UnusedProperty { .. } => "MIR0504",
1388 IssueKind::UnusedFunction { .. } => "MIR0505",
1389 IssueKind::UnusedForeachValue { .. } => "MIR0506",
1390 IssueKind::UnusedClass { .. } => "MIR0507",
1391 IssueKind::UnusedSuppress { .. } => "MIR0508",
1392 IssueKind::UnusedConstant { .. } => "MIR0509",
1393
1394 IssueKind::ImpurePropertyAssignment { .. } => "MIR1700",
1396 IssueKind::ImpureMethodCall { .. } => "MIR1701",
1397 IssueKind::ImpureGlobalVariable { .. } => "MIR1702",
1398 IssueKind::ImpureStaticVariable { .. } => "MIR1703",
1399 IssueKind::ImpureStaticPropertyAssignment { .. } => "MIR1706",
1400 IssueKind::ImpureByRefAssignment { .. } => "MIR1707",
1401 IssueKind::ImpureStaticPropertyAccess { .. } => "MIR1708",
1402 IssueKind::ImpureFunctionCall { .. } => "MIR1704",
1403 IssueKind::ImmutablePropertyModification { .. } => "MIR1705",
1404 IssueKind::UnsupportedReferenceUsage => "MIR1506",
1405 IssueKind::NoInterfaceProperties { .. } => "MIR1504",
1406 IssueKind::UndefinedDocblockClass { .. } => "MIR1505",
1407 IssueKind::MissingConstructor { .. } => "MIR1507",
1408 IssueKind::PropertyPossiblyUninitialized { .. } => "MIR1510",
1409 IssueKind::MixedFunctionCall => "MIR1211",
1410 IssueKind::MixedReturnStatement { .. } => "MIR1212",
1411
1412 IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1414 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1415
1416 IssueKind::UnimplementedAbstractMethod { .. } => "MIR0700",
1418 IssueKind::UnimplementedInterfaceMethod { .. } => "MIR0701",
1419 IssueKind::MethodSignatureMismatch { .. } => "MIR0702",
1420 IssueKind::OverriddenMethodAccess { .. } => "MIR0703",
1421 IssueKind::OverriddenPropertyAccess { .. } => "MIR0710",
1422 IssueKind::PropertyTypeRedeclarationMismatch { .. } => "MIR0712",
1423 IssueKind::BackedEnumCaseTypeMismatch { .. } => "MIR0713",
1424 IssueKind::DuplicateEnumCaseValue { .. } => "MIR0718",
1425 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => "MIR0714",
1426 IssueKind::StaticPropertyRedeclarationMismatch { .. } => "MIR0715",
1427 IssueKind::ReadonlyClassExtendsMismatch { .. } => "MIR0716",
1428 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => "MIR0717",
1429 IssueKind::InvalidExtendClass { .. } => "MIR0704",
1430 IssueKind::FinalMethodOverridden { .. } => "MIR0705",
1431 IssueKind::AbstractInstantiation { .. } => "MIR0706",
1432 IssueKind::AbstractMethodCall { .. } => "MIR0711",
1433 IssueKind::InterfaceInstantiation { .. } => "MIR0709",
1434 IssueKind::EnumInstantiation { .. } => "MIR0719",
1435 IssueKind::TraitInstantiation { .. } => "MIR0720",
1436 IssueKind::NonInvariantDocblockPropertyType { .. } => "MIR0721",
1437 IssueKind::CircularInheritance { .. } => "MIR0707",
1438 IssueKind::InvalidOverride { .. } => "MIR0708",
1439
1440 IssueKind::TaintedInput { .. } => "MIR0800",
1442 IssueKind::TaintedHtml => "MIR0801",
1443 IssueKind::TaintedSql => "MIR0802",
1444 IssueKind::TaintedShell => "MIR0803",
1445 IssueKind::TaintedLlmPrompt => "MIR0804",
1446 IssueKind::TaintedHeader => "MIR0805",
1447 IssueKind::TaintedCookie => "MIR0806",
1448 IssueKind::TaintedSsrf => "MIR0807",
1449 IssueKind::TaintedLdap => "MIR0808",
1450 IssueKind::TaintedXpath => "MIR0809",
1451 IssueKind::TaintedCallable => "MIR0810",
1452 IssueKind::TaintedFile => "MIR0811",
1453 IssueKind::TaintedInclude => "MIR0812",
1454 IssueKind::TaintedEval => "MIR0813",
1455 IssueKind::TaintedUnserialize => "MIR0814",
1456
1457 IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1459 IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1460 IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1461
1462 IssueKind::DeprecatedCall { .. } => "MIR1000",
1464 IssueKind::WrongCaseFunction { .. } => "MIR1009",
1465 IssueKind::WrongCaseMethod { .. } => "MIR1010",
1466 IssueKind::WrongCaseClass { .. } => "MIR1011",
1467 IssueKind::DeprecatedProperty { .. } => "MIR1005",
1468 IssueKind::DeprecatedInterface { .. } => "MIR1006",
1469 IssueKind::DeprecatedTrait { .. } => "MIR1007",
1470 IssueKind::DeprecatedConstant { .. } => "MIR1008",
1471 IssueKind::DeprecatedMethodCall { .. } => "MIR1001",
1472 IssueKind::DeprecatedMethod { .. } => "MIR1002",
1473 IssueKind::DeprecatedClass { .. } => "MIR1003",
1474 IssueKind::InternalMethod { .. } => "MIR1004",
1475 IssueKind::OptionalParameterBeforeRequired { .. } => "MIR1012",
1476 IssueKind::ImplicitlyNullableParameter { .. } => "MIR1013",
1477 IssueKind::DynamicPropertyCreation { .. } => "MIR1014",
1478
1479 IssueKind::MissingReturnType { .. } => "MIR1100",
1481 IssueKind::MissingParamType { .. } => "MIR1101",
1482 IssueKind::MissingPropertyType { .. } => "MIR1104",
1483 IssueKind::MissingClosureReturnType => "MIR1105",
1484 IssueKind::MissingThrowsDocblock { .. } => "MIR1102",
1485 IssueKind::InvalidDocblock { .. } => "MIR1103",
1486 IssueKind::UndefinedThrowsDocblock { .. } => "MIR1106",
1487 IssueKind::InvalidDocblockType { .. } => "MIR1107",
1488
1489 IssueKind::MixedArgument { .. } => "MIR1200",
1491 IssueKind::MixedAssignment { .. } => "MIR1201",
1492 IssueKind::MixedMethodCall { .. } => "MIR1202",
1493 IssueKind::MixedPropertyFetch { .. } => "MIR1203",
1494 IssueKind::MixedPropertyAssignment { .. } => "MIR1208",
1495 IssueKind::MixedArrayAccess => "MIR1209",
1496 IssueKind::MixedArrayOffset => "MIR1210",
1497 IssueKind::MixedClone => "MIR1204",
1498 IssueKind::InvalidClone { .. } => "MIR1205",
1499 IssueKind::PossiblyInvalidClone { .. } => "MIR1206",
1500 IssueKind::InvalidToString { .. } => "MIR1207",
1501
1502 IssueKind::InvalidTraitUse { .. } => "MIR1300",
1504 IssueKind::ForbiddenCode { .. } => "MIR1301",
1505
1506 IssueKind::ParseError { .. } => "MIR1400",
1508 IssueKind::CompileError { .. } => "MIR1401",
1509
1510 IssueKind::InvalidAttribute { .. } => "MIR1600",
1512 IssueKind::UndefinedAttributeClass { .. } => "MIR1601",
1513 IssueKind::DuplicateClass { .. } => "MIR1602",
1514 IssueKind::DuplicateInterface { .. } => "MIR1603",
1515 IssueKind::DuplicateTrait { .. } => "MIR1604",
1516 IssueKind::DuplicateEnum { .. } => "MIR1605",
1517 IssueKind::DuplicateFunction { .. } => "MIR1606",
1518
1519 IssueKind::InvalidThrow { .. } => "MIR1500",
1521 IssueKind::InvalidCatch { .. } => "MIR1503",
1522 IssueKind::UnreachableCatch { .. } => "MIR1508",
1523 IssueKind::PluginIssue { .. } => "MIR1509",
1524 IssueKind::ImplicitToStringCast { .. } => "MIR1501",
1525 IssueKind::ImplicitFloatToIntCast { .. } => "MIR1502",
1526 IssueKind::UseStatementHasNoEffect { .. } => "MIR1511",
1527 IssueKind::PrivateFinalMethod { .. } => "MIR1512",
1528 IssueKind::NonPublicMagicMethod { .. } => "MIR1513",
1529 IssueKind::NoDiscardReturnIgnored { .. } => "MIR1514",
1530 }
1531 }
1532
1533 pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1539 match code {
1540 "MIR0001" | "MIR0002" | "MIR0003" | "MIR0004" | "MIR0005" | "MIR0007" | "MIR0009"
1542 | "MIR0010" | "MIR0011" | "MIR0012" | "MIR0013" | "MIR0014" | "MIR0016" | "MIR0200"
1543 | "MIR0201" | "MIR0202" | "MIR0203" | "MIR0204" | "MIR0205" | "MIR0212" | "MIR0215"
1544 | "MIR0216" | "MIR0217" | "MIR0224" | "MIR0231" | "MIR0235" | "MIR0236" | "MIR0600"
1545 | "MIR0601" | "MIR0700" | "MIR0701" | "MIR0702" | "MIR0703" | "MIR0704" | "MIR0705"
1546 | "MIR0706" | "MIR0707" | "MIR0708" | "MIR0709" | "MIR0710" | "MIR0711" | "MIR0712"
1547 | "MIR0713" | "MIR0714" | "MIR0715" | "MIR0716" | "MIR0717" | "MIR0718" | "MIR0719"
1548 | "MIR0720" | "MIR0228" | "MIR0229" | "MIR0800" | "MIR0801" | "MIR0802" | "MIR0803"
1549 | "MIR0804" | "MIR0805" | "MIR0806" | "MIR0807" | "MIR0808" | "MIR0809" | "MIR0810"
1550 | "MIR0811" | "MIR0812" | "MIR0813" | "MIR0814" | "MIR0900" | "MIR1205" | "MIR1207"
1551 | "MIR1300" | "MIR1400" | "MIR1401" | "MIR1500" | "MIR1503" | "MIR1602" | "MIR1603"
1552 | "MIR1604" | "MIR1605" | "MIR1606" => Some(Severity::Error),
1553
1554 "MIR0006" | "MIR0008" | "MIR0100" | "MIR0101" | "MIR0102" | "MIR0103" | "MIR0109"
1556 | "MIR0206" | "MIR0208" | "MIR0211" | "MIR0218" | "MIR0230" | "MIR0219" | "MIR0220"
1557 | "MIR0222" | "MIR0300" | "MIR0301" | "MIR0302" | "MIR0303" | "MIR0404" | "MIR0405"
1558 | "MIR0408" | "MIR0500" | "MIR0506" | "MIR1301" | "MIR1501" | "MIR1502" | "MIR1700"
1559 | "MIR1701" | "MIR1702" | "MIR1703" | "MIR1704" | "MIR1705" | "MIR1706" | "MIR1707"
1560 | "MIR1708" | "MIR1506" | "MIR1106" | "MIR1107" | "MIR1511" | "MIR1512" | "MIR1513"
1561 | "MIR1514" | "MIR0238" => Some(Severity::Warning),
1562
1563 "MIR0015" | "MIR0104" | "MIR0105" | "MIR0106" | "MIR0107" | "MIR0108" | "MIR0207"
1565 | "MIR0232" | "MIR0233" | "MIR0234" | "MIR0209" | "MIR0210" | "MIR0213" | "MIR0214"
1566 | "MIR0221" | "MIR0223" | "MIR0400" | "MIR0401" | "MIR0402" | "MIR0403" | "MIR0501"
1567 | "MIR0502" | "MIR0503" | "MIR0504" | "MIR0505" | "MIR0507" | "MIR0508" | "MIR0509"
1568 | "MIR0901" | "MIR1000" | "MIR1001" | "MIR1002" | "MIR1003" | "MIR1004" | "MIR1005"
1569 | "MIR1006" | "MIR1007" | "MIR1008" | "MIR1009" | "MIR1010" | "MIR1011" | "MIR1012"
1570 | "MIR1013" | "MIR1014" | "MIR1100" | "MIR1101" | "MIR1102" | "MIR1103" | "MIR1104"
1571 | "MIR1105" | "MIR1200" | "MIR1201" | "MIR1202" | "MIR1203" | "MIR1204" | "MIR1206"
1572 | "MIR1208" | "MIR1209" | "MIR1210" | "MIR1211" | "MIR1212" | "MIR1504" | "MIR1505"
1573 | "MIR1507" | "MIR1508" | "MIR1600" | "MIR1601" | "MIR0225" | "MIR0226" | "MIR0227"
1574 | "MIR0406" | "MIR0407" | "MIR0902" | "MIR1510" | "MIR0721" | "MIR0237" | "MIR0110" => {
1575 Some(Severity::Info)
1576 }
1577
1578 _ => None,
1579 }
1580 }
1581
1582 pub fn name(&self) -> &'static str {
1584 match self {
1585 IssueKind::NonStaticSelfCall { .. } => "NonStaticSelfCall",
1586 IssueKind::DirectConstructorCall { .. } => "DirectConstructorCall",
1587 IssueKind::InvalidScope { .. } => "InvalidScope",
1588 IssueKind::UndefinedVariable { .. } => "UndefinedVariable",
1589 IssueKind::UndefinedFunction { .. } => "UndefinedFunction",
1590 IssueKind::UndefinedMethod { .. } => "UndefinedMethod",
1591 IssueKind::PossiblyUndefinedMethod { .. } => "PossiblyUndefinedMethod",
1592 IssueKind::UndefinedClass { .. } => "UndefinedClass",
1593 IssueKind::UndefinedProperty { .. } => "UndefinedProperty",
1594 IssueKind::UndefinedConstant { .. } => "UndefinedConstant",
1595 IssueKind::InaccessibleClassConstant { .. } => "InaccessibleClassConstant",
1596 IssueKind::InaccessibleProperty { .. } => "InaccessibleProperty",
1597 IssueKind::TraitConstantAccessedDirectly { .. } => "TraitConstantAccessedDirectly",
1598 IssueKind::UndefinedTraitAliasMethod { .. } => "UndefinedTraitAliasMethod",
1599 IssueKind::PossiblyUndefinedVariable { .. } => "PossiblyUndefinedVariable",
1600 IssueKind::UndefinedTrait { .. } => "UndefinedTrait",
1601 IssueKind::ParentNotFound => "ParentNotFound",
1602 IssueKind::InvalidStringClass { .. } => "InvalidStringClass",
1603 IssueKind::NotAnInterface { .. } => "NotAnInterface",
1604 IssueKind::NullArgument { .. } => "NullArgument",
1605 IssueKind::NullPropertyFetch { .. } => "NullPropertyFetch",
1606 IssueKind::NullMethodCall { .. } => "NullMethodCall",
1607 IssueKind::NullArrayAccess => "NullArrayAccess",
1608 IssueKind::PossiblyNullArgument { .. } => "PossiblyNullArgument",
1609 IssueKind::PossiblyInvalidArgument { .. } => "PossiblyInvalidArgument",
1610 IssueKind::PossiblyNullPropertyFetch { .. } => "PossiblyNullPropertyFetch",
1611 IssueKind::PossiblyNullMethodCall { .. } => "PossiblyNullMethodCall",
1612 IssueKind::PossiblyNullArrayAccess => "PossiblyNullArrayAccess",
1613 IssueKind::NullableReturnStatement { .. } => "NullableReturnStatement",
1614 IssueKind::InvalidReturnType { .. } => "InvalidReturnType",
1615 IssueKind::InvalidArgument { .. } => "InvalidArgument",
1616 IssueKind::InvalidScalarArgument { .. } => "InvalidScalarArgument",
1617 IssueKind::LessSpecificReturnStatement { .. } => "LessSpecificReturnStatement",
1618 IssueKind::TooFewArguments { .. } => "TooFewArguments",
1619 IssueKind::TooManyArguments { .. } => "TooManyArguments",
1620 IssueKind::InvalidNamedArgument { .. } => "InvalidNamedArgument",
1621 IssueKind::InvalidNamedArguments { .. } => "InvalidNamedArguments",
1622 IssueKind::InvalidPassByReference { .. } => "InvalidPassByReference",
1623 IssueKind::InvalidPropertyFetch { .. } => "InvalidPropertyFetch",
1624 IssueKind::InvalidMethodCall { .. } => "InvalidMethodCall",
1625 IssueKind::InvalidMemberName { .. } => "InvalidMemberName",
1626 IssueKind::NativeResourceType { .. } => "NativeResourceType",
1627 IssueKind::InvalidUnpack { .. } => "InvalidUnpack",
1628 IssueKind::InvalidArrayAccess { .. } => "InvalidArrayAccess",
1629 IssueKind::PossiblyInvalidArrayAccess { .. } => "PossiblyInvalidArrayAccess",
1630 IssueKind::InvalidArrayAssignment { .. } => "InvalidArrayAssignment",
1631 IssueKind::InvalidPropertyAssignment { .. } => "InvalidPropertyAssignment",
1632 IssueKind::PossiblyNullPropertyAssignmentValue { .. } => {
1633 "PossiblyNullPropertyAssignmentValue"
1634 }
1635 IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => {
1636 "PossiblyFalsePropertyAssignmentValue"
1637 }
1638 IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => {
1639 "PossiblyInvalidPropertyAssignmentValue"
1640 }
1641 IssueKind::InvalidCast { .. } => "InvalidCast",
1642 IssueKind::InvalidStaticInvocation { .. } => "InvalidStaticInvocation",
1643 IssueKind::InvalidOperand { .. } => "InvalidOperand",
1644 IssueKind::PossiblyInvalidOperand { .. } => "PossiblyInvalidOperand",
1645 IssueKind::PossiblyNullOperand { .. } => "PossiblyNullOperand",
1646 IssueKind::DivisionByZero { .. } => "DivisionByZero",
1647 IssueKind::RawObjectIteration { .. } => "RawObjectIteration",
1648 IssueKind::PossiblyRawObjectIteration { .. } => "PossiblyRawObjectIteration",
1649 IssueKind::InvalidGeneratorIteration { .. } => "InvalidGeneratorIteration",
1650 IssueKind::MismatchingDocblockReturnType { .. } => "MismatchingDocblockReturnType",
1651 IssueKind::MismatchingDocblockParamType { .. } => "MismatchingDocblockParamType",
1652 IssueKind::TypeCheckMismatch { .. } => "TypeCheckMismatch",
1653 IssueKind::DocblockTypeContradiction { .. } => "DocblockTypeContradiction",
1654 IssueKind::ImpossibleIdenticalComparison { .. } => "ImpossibleIdenticalComparison",
1655 IssueKind::ImpossibleLooseComparison { .. } => "ImpossibleLooseComparison",
1656 IssueKind::UnevaluatedCode { .. } => "UnevaluatedCode",
1657 IssueKind::IfThisIsMismatch { .. } => "IfThisIsMismatch",
1658 IssueKind::Trace { .. } => "Trace",
1659 IssueKind::InvalidArrayOffset { .. } => "InvalidArrayOffset",
1660 IssueKind::NonExistentArrayOffset { .. } => "NonExistentArrayOffset",
1661 IssueKind::PossiblyInvalidArrayOffset { .. } => "PossiblyInvalidArrayOffset",
1662 IssueKind::DuplicateArrayKey { .. } => "DuplicateArrayKey",
1663 IssueKind::RedundantCondition { .. } => "RedundantCondition",
1664 IssueKind::RedundantCast { .. } => "RedundantCast",
1665 IssueKind::UnnecessaryVarAnnotation { .. } => "UnnecessaryVarAnnotation",
1666 IssueKind::TypeDoesNotContainType { .. } => "TypeDoesNotContainType",
1667 IssueKind::ParadoxicalCondition { .. } => "ParadoxicalCondition",
1668 IssueKind::UnhandledMatchCondition { .. } => "UnhandledMatchCondition",
1669 IssueKind::UnusedVariable { .. } => "UnusedVariable",
1670 IssueKind::UnusedParam { .. } => "UnusedParam",
1671 IssueKind::UnreachableCode => "UnreachableCode",
1672 IssueKind::UnusedMethod { .. } => "UnusedMethod",
1673 IssueKind::UnusedProperty { .. } => "UnusedProperty",
1674 IssueKind::UnusedFunction { .. } => "UnusedFunction",
1675 IssueKind::UnusedForeachValue { .. } => "UnusedForeachValue",
1676 IssueKind::UnusedClass { .. } => "UnusedClass",
1677 IssueKind::UnusedConstant { .. } => "UnusedConstant",
1678 IssueKind::UnusedSuppress { .. } => "UnusedSuppress",
1679 IssueKind::ArgumentTypeCoercion { .. } => "ArgumentTypeCoercion",
1680 IssueKind::PropertyTypeCoercion { .. } => "PropertyTypeCoercion",
1681 IssueKind::ImpurePropertyAssignment { .. } => "ImpurePropertyAssignment",
1682 IssueKind::ImpureMethodCall { .. } => "ImpureMethodCall",
1683 IssueKind::ImpureGlobalVariable { .. } => "ImpureGlobalVariable",
1684 IssueKind::ImpureStaticVariable { .. } => "ImpureStaticVariable",
1685 IssueKind::ImpureByRefAssignment { .. } => "ImpureByRefAssignment",
1686 IssueKind::ImpureStaticPropertyAssignment { .. } => "ImpureStaticPropertyAssignment",
1687 IssueKind::ImpureStaticPropertyAccess { .. } => "ImpureStaticPropertyAccess",
1688 IssueKind::ImpureFunctionCall { .. } => "ImpureFunctionCall",
1689 IssueKind::ImmutablePropertyModification { .. } => "ImmutablePropertyModification",
1690 IssueKind::UnsupportedReferenceUsage => "UnsupportedReferenceUsage",
1691 IssueKind::NoInterfaceProperties { .. } => "NoInterfaceProperties",
1692 IssueKind::UndefinedDocblockClass { .. } => "UndefinedDocblockClass",
1693 IssueKind::MissingConstructor { .. } => "MissingConstructor",
1694 IssueKind::PropertyPossiblyUninitialized { .. } => "PropertyPossiblyUninitialized",
1695 IssueKind::MixedFunctionCall => "MixedFunctionCall",
1696 IssueKind::MixedReturnStatement { .. } => "MixedReturnStatement",
1697 IssueKind::UnimplementedAbstractMethod { .. } => "UnimplementedAbstractMethod",
1698 IssueKind::UnimplementedInterfaceMethod { .. } => "UnimplementedInterfaceMethod",
1699 IssueKind::MethodSignatureMismatch { .. } => "MethodSignatureMismatch",
1700 IssueKind::OverriddenMethodAccess { .. } => "OverriddenMethodAccess",
1701 IssueKind::OverriddenPropertyAccess { .. } => "OverriddenPropertyAccess",
1702 IssueKind::PropertyTypeRedeclarationMismatch { .. } => {
1703 "PropertyTypeRedeclarationMismatch"
1704 }
1705 IssueKind::NonInvariantDocblockPropertyType { .. } => {
1706 "NonInvariantDocblockPropertyType"
1707 }
1708 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => {
1709 "ReadonlyPropertyRedeclarationMismatch"
1710 }
1711 IssueKind::StaticPropertyRedeclarationMismatch { .. } => {
1712 "StaticPropertyRedeclarationMismatch"
1713 }
1714 IssueKind::ReadonlyClassExtendsMismatch { .. } => "ReadonlyClassExtendsMismatch",
1715 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => {
1716 "InvalidReadonlyPropertyDeclaration"
1717 }
1718 IssueKind::BackedEnumCaseTypeMismatch { .. } => "BackedEnumCaseTypeMismatch",
1719 IssueKind::DuplicateEnumCaseValue { .. } => "DuplicateEnumCaseValue",
1720 IssueKind::InvalidExtendClass { .. } => "InvalidExtendClass",
1721 IssueKind::FinalMethodOverridden { .. } => "FinalMethodOverridden",
1722 IssueKind::AbstractInstantiation { .. } => "AbstractInstantiation",
1723 IssueKind::AbstractMethodCall { .. } => "AbstractMethodCall",
1724 IssueKind::InterfaceInstantiation { .. } => "InterfaceInstantiation",
1725 IssueKind::EnumInstantiation { .. } => "EnumInstantiation",
1726 IssueKind::TraitInstantiation { .. } => "TraitInstantiation",
1727 IssueKind::InvalidDynamicProperty { .. } => "InvalidDynamicProperty",
1728 IssueKind::InvalidOverride { .. } => "InvalidOverride",
1729 IssueKind::ReadonlyPropertyAssignment { .. } => "ReadonlyPropertyAssignment",
1730 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => {
1731 "ReadonlyPropertyAlreadyInitialized"
1732 }
1733 IssueKind::InvalidTemplateParam { .. } => "InvalidTemplateParam",
1734 IssueKind::ShadowedTemplateParam { .. } => "ShadowedTemplateParam",
1735 IssueKind::TaintedInput { .. } => "TaintedInput",
1736 IssueKind::TaintedHtml => "TaintedHtml",
1737 IssueKind::TaintedSql => "TaintedSql",
1738 IssueKind::TaintedShell => "TaintedShell",
1739 IssueKind::TaintedLlmPrompt => "TaintedLlmPrompt",
1740 IssueKind::TaintedHeader => "TaintedHeader",
1741 IssueKind::TaintedCookie => "TaintedCookie",
1742 IssueKind::TaintedSsrf => "TaintedSsrf",
1743 IssueKind::TaintedLdap => "TaintedLdap",
1744 IssueKind::TaintedXpath => "TaintedXpath",
1745 IssueKind::TaintedCallable => "TaintedCallable",
1746 IssueKind::TaintedFile => "TaintedFile",
1747 IssueKind::TaintedInclude => "TaintedInclude",
1748 IssueKind::TaintedEval => "TaintedEval",
1749 IssueKind::TaintedUnserialize => "TaintedUnserialize",
1750 IssueKind::DeprecatedCall { .. } => "DeprecatedCall",
1751 IssueKind::DeprecatedProperty { .. } => "DeprecatedProperty",
1752 IssueKind::DeprecatedConstant { .. } => "DeprecatedConstant",
1753 IssueKind::DeprecatedInterface { .. } => "DeprecatedInterface",
1754 IssueKind::DeprecatedTrait { .. } => "DeprecatedTrait",
1755 IssueKind::DeprecatedMethodCall { .. } => "DeprecatedMethodCall",
1756 IssueKind::DeprecatedMethod { .. } => "DeprecatedMethod",
1757 IssueKind::DeprecatedClass { .. } => "DeprecatedClass",
1758 IssueKind::InternalMethod { .. } => "InternalMethod",
1759 IssueKind::OptionalParameterBeforeRequired { .. } => "OptionalParameterBeforeRequired",
1760 IssueKind::ImplicitlyNullableParameter { .. } => "ImplicitlyNullableParameter",
1761 IssueKind::DynamicPropertyCreation { .. } => "DynamicPropertyCreation",
1762 IssueKind::MissingReturnType { .. } => "MissingReturnType",
1763 IssueKind::MissingClosureReturnType => "MissingClosureReturnType",
1764 IssueKind::MissingParamType { .. } => "MissingParamType",
1765 IssueKind::MissingPropertyType { .. } => "MissingPropertyType",
1766 IssueKind::InvalidThrow { .. } => "InvalidThrow",
1767 IssueKind::InvalidCatch { .. } => "InvalidCatch",
1768 IssueKind::UnreachableCatch { .. } => "UnreachableCatch",
1769 IssueKind::MissingThrowsDocblock { .. } => "MissingThrowsDocblock",
1770 IssueKind::ImplicitToStringCast { .. } => "ImplicitToStringCast",
1771 IssueKind::ImplicitFloatToIntCast { .. } => "ImplicitFloatToIntCast",
1772 IssueKind::ParseError { .. } => "ParseError",
1773 IssueKind::CompileError { .. } => "CompileError",
1774 IssueKind::InvalidDocblock { .. } => "InvalidDocblock",
1775 IssueKind::UndefinedThrowsDocblock { .. } => "UndefinedThrowsDocblock",
1776 IssueKind::InvalidDocblockType { .. } => "InvalidDocblockType",
1777 IssueKind::MixedArgument { .. } => "MixedArgument",
1778 IssueKind::MixedAssignment { .. } => "MixedAssignment",
1779 IssueKind::MixedMethodCall { .. } => "MixedMethodCall",
1780 IssueKind::MixedPropertyFetch { .. } => "MixedPropertyFetch",
1781 IssueKind::MixedPropertyAssignment { .. } => "MixedPropertyAssignment",
1782 IssueKind::MixedArrayAccess => "MixedArrayAccess",
1783 IssueKind::MixedArrayOffset => "MixedArrayOffset",
1784 IssueKind::MixedClone => "MixedClone",
1785 IssueKind::InvalidClone { .. } => "InvalidClone",
1786 IssueKind::PossiblyInvalidClone { .. } => "PossiblyInvalidClone",
1787 IssueKind::InvalidToString { .. } => "InvalidToString",
1788 IssueKind::CircularInheritance { .. } => "CircularInheritance",
1789 IssueKind::InvalidTraitUse { .. } => "InvalidTraitUse",
1790 IssueKind::ForbiddenCode { .. } => "ForbiddenCode",
1791 IssueKind::WrongCaseFunction { .. } => "WrongCaseFunction",
1792 IssueKind::WrongCaseMethod { .. } => "WrongCaseMethod",
1793 IssueKind::WrongCaseClass { .. } => "WrongCaseClass",
1794 IssueKind::InvalidAttribute { .. } => "InvalidAttribute",
1795 IssueKind::UndefinedAttributeClass { .. } => "UndefinedAttributeClass",
1796 IssueKind::DuplicateClass { .. } => "DuplicateClass",
1797 IssueKind::DuplicateInterface { .. } => "DuplicateInterface",
1798 IssueKind::DuplicateTrait { .. } => "DuplicateTrait",
1799 IssueKind::DuplicateEnum { .. } => "DuplicateEnum",
1800 IssueKind::DuplicateFunction { .. } => "DuplicateFunction",
1801 IssueKind::UseStatementHasNoEffect { .. } => "UseStatementHasNoEffect",
1802 IssueKind::PrivateFinalMethod { .. } => "PrivateFinalMethod",
1803 IssueKind::NonPublicMagicMethod { .. } => "NonPublicMagicMethod",
1804 IssueKind::NoDiscardReturnIgnored { .. } => "NoDiscardReturnIgnored",
1805 IssueKind::PluginIssue { .. } => "PluginIssue",
1806 }
1807 }
1808
1809 pub fn referenced_symbol(&self) -> Option<String> {
1811 use IssueKind::*;
1812 Some(match self {
1813 UndefinedClass { name }
1814 | UndefinedFunction { name }
1815 | UndefinedConstant { name }
1816 | UndefinedTrait { name }
1817 | UnusedFunction { name }
1818 | DeprecatedCall { name, .. }
1819 | DeprecatedClass { name, .. }
1820 | DeprecatedInterface { name, .. }
1821 | DeprecatedTrait { name, .. } => name.clone(),
1822 UnusedClass { class } => class.clone(),
1823 UndefinedMethod { class, method }
1824 | PossiblyUndefinedMethod { class, method }
1825 | UnusedMethod { class, method }
1826 | InternalMethod { class, method }
1827 | DeprecatedMethod { class, method, .. }
1828 | DeprecatedMethodCall { class, method, .. } => format!("{class}::{method}"),
1829 UndefinedProperty { class, property }
1830 | InaccessibleProperty { class, property }
1831 | UnusedProperty { class, property }
1832 | DeprecatedProperty {
1833 class, property, ..
1834 } => format!("{class}::${property}"),
1835 InaccessibleClassConstant { class, constant }
1836 | UnusedConstant { class, constant }
1837 | DeprecatedConstant {
1838 class, constant, ..
1839 } => format!("{class}::{constant}"),
1840 UndefinedVariable { name }
1841 | PossiblyUndefinedVariable { name }
1842 | UnusedVariable { name } => format!("${name}"),
1843 _ => return None,
1844 })
1845 }
1846
1847 pub fn display_name(&self) -> &str {
1851 match self {
1852 IssueKind::PluginIssue { name, .. } => name,
1853 other => other.name(),
1854 }
1855 }
1856
1857 pub fn message(&self) -> String {
1859 match self {
1860 IssueKind::NonStaticSelfCall { class, method } => {
1861 format!("Non-static method {class}::{method}() cannot be called statically")
1862 }
1863 IssueKind::DirectConstructorCall { class } => {
1864 format!("Cannot call constructor of {class} directly")
1865 }
1866 IssueKind::InvalidScope { in_class } => {
1867 if *in_class {
1868 "$this cannot be used in a static method".to_string()
1869 } else {
1870 "$this cannot be used outside of a class".to_string()
1871 }
1872 }
1873 IssueKind::UndefinedVariable { name } => format!("Variable ${name} is not defined"),
1874 IssueKind::UndefinedFunction { name } => format!("Function {name}() is not defined"),
1875 IssueKind::UndefinedMethod { class, method } => {
1876 format!("Method {class}::{method}() does not exist")
1877 }
1878 IssueKind::PossiblyUndefinedMethod { class, method } => {
1879 format!("Method {class}::{method}() might not exist")
1880 }
1881 IssueKind::UndefinedClass { name } => format!("Class {name} does not exist"),
1882 IssueKind::UndefinedProperty { class, property } => {
1883 format!("Property {class}::${property} does not exist")
1884 }
1885 IssueKind::UndefinedConstant { name } => format!("Constant {name} is not defined"),
1886 IssueKind::InaccessibleClassConstant { class, constant } => {
1887 format!("Cannot access constant {class}::{constant}")
1888 }
1889 IssueKind::InaccessibleProperty { class, property } => {
1890 format!("Cannot access property {class}::${property}")
1891 }
1892 IssueKind::PossiblyUndefinedVariable { name } => {
1893 format!("Variable ${name} might not be defined")
1894 }
1895 IssueKind::UndefinedTrait { name } => format!("Trait {name} does not exist"),
1896 IssueKind::TraitConstantAccessedDirectly {
1897 trait_name,
1898 constant,
1899 } => {
1900 format!("Cannot access trait constant {trait_name}::{constant} directly")
1901 }
1902 IssueKind::UndefinedTraitAliasMethod { trait_name, method } => match trait_name {
1903 Some(t) => {
1904 format!("An alias was defined for {t}::{method} but this method does not exist")
1905 }
1906 None => format!("An alias was defined for {method} but this method does not exist"),
1907 },
1908 IssueKind::ParentNotFound => {
1909 "Cannot use parent:: when current class has no parent".to_string()
1910 }
1911 IssueKind::InvalidStringClass { actual } => {
1912 format!("Dynamic class instantiation requires string or class-string type, got '{actual}'")
1913 }
1914 IssueKind::NotAnInterface { name } => {
1915 format!("{name} is not an interface")
1916 }
1917
1918 IssueKind::NullArgument { param, fn_name } => {
1919 format!("Argument ${param} of {fn_name}() cannot be null")
1920 }
1921 IssueKind::NullPropertyFetch { property } => {
1922 format!("Cannot access property ${property} on null")
1923 }
1924 IssueKind::NullMethodCall { method } => {
1925 format!("Cannot call method {method}() on null")
1926 }
1927 IssueKind::NullArrayAccess => "Cannot access array on null".to_string(),
1928 IssueKind::PossiblyNullArgument { param, fn_name } => {
1929 format!("Argument ${param} of {fn_name}() might be null")
1930 }
1931 IssueKind::PossiblyInvalidArgument {
1932 param,
1933 fn_name,
1934 expected,
1935 actual,
1936 } => {
1937 format!("Argument ${param} of {fn_name}() expects '{expected}', possibly different type '{actual}' provided")
1938 }
1939 IssueKind::PossiblyNullPropertyFetch { property } => {
1940 format!("Cannot access property ${property} on possibly null value")
1941 }
1942 IssueKind::PossiblyNullMethodCall { method } => {
1943 format!("Cannot call method {method}() on possibly null value")
1944 }
1945 IssueKind::PossiblyNullArrayAccess => {
1946 "Cannot access array on possibly null value".to_string()
1947 }
1948 IssueKind::NullableReturnStatement { expected, actual } => {
1949 format!("Return type '{actual}' is not compatible with declared '{expected}'")
1950 }
1951
1952 IssueKind::InvalidReturnType { expected, actual } => {
1953 format!("Return type '{actual}' is not compatible with declared '{expected}'")
1954 }
1955 IssueKind::LessSpecificReturnStatement { expected, actual } => {
1956 format!("Return type '{actual}' is less specific than declared '{expected}'")
1957 }
1958 IssueKind::InvalidScalarArgument {
1959 param,
1960 fn_name,
1961 expected,
1962 actual,
1963 } => {
1964 format!("Argument ${param} of {fn_name}() expects '{expected}', got scalar '{actual}'")
1965 }
1966 IssueKind::InvalidArgument {
1967 param,
1968 fn_name,
1969 expected,
1970 actual,
1971 } => {
1972 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}'")
1973 }
1974 IssueKind::TooFewArguments {
1975 fn_name,
1976 expected,
1977 actual,
1978 } => {
1979 format!(
1980 "Too few arguments for {}(): expected {}, got {}",
1981 fn_name, expected, actual
1982 )
1983 }
1984 IssueKind::TooManyArguments {
1985 fn_name,
1986 expected,
1987 actual,
1988 } => {
1989 format!(
1990 "Too many arguments for {}(): expected {}, got {}",
1991 fn_name, expected, actual
1992 )
1993 }
1994 IssueKind::InvalidNamedArgument {
1995 fn_name,
1996 name,
1997 overwrites: true,
1998 } => {
1999 format!(
2000 "{}() argument ${} overwrites a previous argument",
2001 fn_name, name
2002 )
2003 }
2004 IssueKind::InvalidNamedArgument { fn_name, name, .. } => {
2005 format!("{}() has no parameter named ${}", fn_name, name)
2006 }
2007 IssueKind::InvalidNamedArguments { fn_name } => {
2008 format!("{}() does not accept named arguments", fn_name)
2009 }
2010 IssueKind::InvalidPassByReference { fn_name, param } => {
2011 format!(
2012 "Argument ${} of {}() must be passed by reference",
2013 param, fn_name
2014 )
2015 }
2016 IssueKind::InvalidPropertyFetch { ty } => {
2017 format!("Cannot fetch property on non-object type '{ty}'")
2018 }
2019 IssueKind::InvalidMethodCall { method, ty } => {
2020 format!("Cannot call method {method}() on non-object type '{ty}'")
2021 }
2022 IssueKind::InvalidMemberName { member, ty } if member == "method" => {
2023 format!("Method name must be a string, '{ty}' given")
2024 }
2025 IssueKind::InvalidMemberName { member, ty } => {
2026 format!("Object of type '{ty}' cannot be converted to a {member} name")
2027 }
2028 IssueKind::NativeResourceType { class } => {
2029 format!("'resource' is not a native type; PHP reads it as class '{class}', which no resource satisfies")
2030 }
2031 IssueKind::InvalidUnpack { ty } if ty.is_empty() => {
2032 "Only arrays and Traversables can be unpacked".to_string()
2033 }
2034 IssueKind::InvalidUnpack { ty } => {
2035 format!("Only arrays and Traversables can be unpacked, {ty} given")
2036 }
2037 IssueKind::InvalidArrayAccess { ty } => {
2038 format!("Cannot use [] operator on non-array type '{ty}'")
2039 }
2040 IssueKind::PossiblyInvalidArrayAccess { ty } => {
2041 format!("Possibly invalid array access: '{ty}' might not support []")
2042 }
2043 IssueKind::InvalidArrayAssignment { ty } => {
2044 format!("Cannot use [] assignment on non-array type '{ty}'")
2045 }
2046 IssueKind::InvalidPropertyAssignment {
2047 property,
2048 expected,
2049 actual,
2050 } => {
2051 format!("Property ${property} expects '{expected}', cannot assign '{actual}'")
2052 }
2053 IssueKind::PossiblyNullPropertyAssignmentValue {
2054 property,
2055 expected,
2056 actual,
2057 } => {
2058 format!("Property ${property} expects '{expected}', the assigned '{actual}' might be null")
2059 }
2060 IssueKind::PossiblyFalsePropertyAssignmentValue {
2061 property,
2062 expected,
2063 actual,
2064 } => {
2065 format!("Property ${property} expects '{expected}', the assigned '{actual}' might be false")
2066 }
2067 IssueKind::PossiblyInvalidPropertyAssignmentValue {
2068 property,
2069 expected,
2070 actual,
2071 } => {
2072 format!("Property ${property} expects '{expected}', the assigned '{actual}' might not match")
2073 }
2074 IssueKind::InvalidCast { from, to } => {
2075 format!("Cannot cast '{from}' to '{to}'")
2076 }
2077 IssueKind::InvalidStaticInvocation { class, method } => {
2078 format!("Non-static method {class}::{method}() cannot be called statically")
2079 }
2080 IssueKind::InvalidOperand { op, left, right } => {
2081 if right.is_empty() {
2082 format!("Operator '{op}' not supported for operand of type '{left}'")
2083 } else {
2084 format!("Operator '{op}' not supported between '{left}' and '{right}'")
2085 }
2086 }
2087 IssueKind::PossiblyInvalidOperand { op, left, right } => {
2088 format!("Operator '{op}' might not be supported between '{left}' and '{right}'")
2089 }
2090 IssueKind::PossiblyNullOperand { op, ty } => {
2091 format!("Operator '{op}' operand '{ty}' might be null")
2092 }
2093 IssueKind::DivisionByZero { op } => {
2094 format!("Division by zero: right operand of '{op}' is always 0")
2095 }
2096 IssueKind::RawObjectIteration { ty } => {
2097 format!("Cannot iterate over non-iterable object '{ty}'")
2098 }
2099 IssueKind::PossiblyRawObjectIteration { ty } => {
2100 format!("Cannot iterate over possibly non-iterable object '{ty}'")
2101 }
2102 IssueKind::InvalidGeneratorIteration { ty, send } => {
2103 format!("foreach sends null to '{ty}', but its send type is '{send}'")
2104 }
2105 IssueKind::MismatchingDocblockReturnType { declared, inferred } => {
2106 format!("Docblock return type '{declared}' does not match inferred '{inferred}'")
2107 }
2108 IssueKind::MismatchingDocblockParamType {
2109 param,
2110 declared,
2111 inferred,
2112 } => {
2113 format!(
2114 "Docblock type '{declared}' for ${param} does not match inferred '{inferred}'"
2115 )
2116 }
2117 IssueKind::TypeCheckMismatch {
2118 var,
2119 expected,
2120 actual,
2121 } => {
2122 format!("Type of {var} is expected to be {expected}, got {actual}")
2123 }
2124 IssueKind::Trace {
2125 variable,
2126 type_info,
2127 } => {
2128 format!("Type of ${variable} is {type_info}")
2129 }
2130
2131 IssueKind::InvalidArrayOffset { expected, actual } => {
2132 format!("Array offset expects '{expected}', got '{actual}'")
2133 }
2134 IssueKind::NonExistentArrayOffset { key } => {
2135 format!("Array offset '{key}' does not exist")
2136 }
2137 IssueKind::PossiblyInvalidArrayOffset { expected, actual } => {
2138 format!("Array offset might be invalid: expects '{expected}', got '{actual}'")
2139 }
2140 IssueKind::DuplicateArrayKey { key } => {
2141 format!("Array key {key} is duplicated — the earlier entry is silently overwritten")
2142 }
2143
2144 IssueKind::RedundantCondition {
2145 always_true,
2146 unreachable,
2147 } => match unreachable {
2148 Some(branch) => {
2149 format!("Condition is always {always_true}, so the {branch} is never reached")
2150 }
2151 None => format!("Condition is always {always_true}, so the check is redundant"),
2152 },
2153 IssueKind::RedundantCast { from, to } => {
2154 format!("Casting '{from}' to '{to}' is redundant")
2155 }
2156 IssueKind::UnnecessaryVarAnnotation { var } => {
2157 format!("@var annotation for ${var} is unnecessary")
2158 }
2159 IssueKind::TypeDoesNotContainType { left, right } => {
2160 format!("Type '{left}' can never contain type '{right}'")
2161 }
2162 IssueKind::ParadoxicalCondition { value } => {
2163 format!("Value {value} is duplicated; this branch can never be reached")
2164 }
2165 IssueKind::UnhandledMatchCondition { detail } => {
2166 format!("Unhandled match condition: {detail}")
2167 }
2168 IssueKind::DocblockTypeContradiction { expr, declared } => {
2169 format!("Type '{declared}' makes '{expr}' impossible — this can never hold")
2170 }
2171 IssueKind::ImpossibleIdenticalComparison { op, left, right } => {
2172 let result = if op == "===" { "false" } else { "true" };
2173 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be identical")
2174 }
2175 IssueKind::ImpossibleLooseComparison { op, left, right } => {
2176 let result = if op == "==" { "false" } else { "true" };
2177 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be loosely equal")
2178 }
2179 IssueKind::UnevaluatedCode { reason } => reason.clone(),
2180 IssueKind::IfThisIsMismatch {
2181 class,
2182 method,
2183 expected,
2184 actual,
2185 } => {
2186 format!(
2187 "Cannot call {class}::{method}() — @if-this-is requires $this to be '{expected}', but it is '{actual}'"
2188 )
2189 }
2190
2191 IssueKind::UnusedVariable { name } => format!("Variable ${name} is never read"),
2192 IssueKind::UnusedParam { name } => format!("Parameter ${name} is never used"),
2193 IssueKind::UnreachableCode => "Unreachable code detected".to_string(),
2194 IssueKind::UnusedMethod { class, method } => {
2195 format!("Private method {class}::{method}() is never called")
2196 }
2197 IssueKind::UnusedProperty { class, property } => {
2198 format!("Private property {class}::${property} is never read")
2199 }
2200 IssueKind::UnusedFunction { name } => {
2201 format!("Function {name}() is never called")
2202 }
2203 IssueKind::UnusedForeachValue { name } => {
2204 format!("Foreach value ${name} is never read")
2205 }
2206 IssueKind::UnusedClass { class } => {
2207 format!("Class {class} is never referenced")
2208 }
2209 IssueKind::UnusedConstant { class, constant } => {
2210 format!("Private constant {class}::{constant} is never used")
2211 }
2212 IssueKind::UnusedSuppress { kind } => {
2213 format!("Suppress annotation for '{kind}' is never used")
2214 }
2215 IssueKind::ArgumentTypeCoercion {
2216 param,
2217 fn_name,
2218 expected,
2219 actual,
2220 } => {
2221 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}' — coercion may fail at runtime")
2222 }
2223 IssueKind::PropertyTypeCoercion {
2224 property,
2225 expected,
2226 actual,
2227 } => {
2228 format!("Property ${property} expects '{expected}', cannot assign '{actual}' — coercion may fail at runtime")
2229 }
2230 IssueKind::ImpurePropertyAssignment { property } => {
2231 format!("Assigning to property {property} of a parameter in a pure or external-mutation-free context")
2232 }
2233 IssueKind::ImpureMethodCall { method } => {
2234 format!("Calling impure method {method}() in a pure or immutable context")
2235 }
2236 IssueKind::ImpureGlobalVariable { variable } => {
2237 format!("Using global variable ${variable} in a @pure function")
2238 }
2239 IssueKind::ImpureStaticVariable { variable } => {
2240 format!("Using static variable ${variable} in a @pure function")
2241 }
2242 IssueKind::ImpureByRefAssignment { variable } => {
2243 format!("Assigning to by-reference parameter ${variable} in a @pure function")
2244 }
2245 IssueKind::ImpureStaticPropertyAssignment { class, property } => {
2246 format!("Assigning to static property {class}::${property} in a @pure function")
2247 }
2248 IssueKind::ImpureStaticPropertyAccess { class, property } => {
2249 format!("Reading static property {class}::${property} in a @pure function")
2250 }
2251 IssueKind::ImpureFunctionCall { fn_name } => {
2252 format!("Calling impure function {fn_name}() in a @pure function")
2253 }
2254 IssueKind::ImmutablePropertyModification { receiver, property } => {
2255 format!("Assigning to property {property} of {receiver} in an immutable context (@psalm-immutable class or @psalm-mutation-free method)")
2256 }
2257
2258 IssueKind::UnimplementedAbstractMethod { class, method } => {
2259 format!("Class {class} must implement abstract method {method}()")
2260 }
2261 IssueKind::UnimplementedInterfaceMethod {
2262 class,
2263 interface,
2264 method,
2265 } => {
2266 format!("Class {class} must implement {interface}::{method}() from interface")
2267 }
2268 IssueKind::MethodSignatureMismatch {
2269 class,
2270 method,
2271 detail,
2272 } => {
2273 format!("Method {class}::{method}() signature mismatch: {detail}")
2274 }
2275 IssueKind::OverriddenMethodAccess {
2276 class,
2277 method,
2278 parent,
2279 visibility,
2280 } => {
2281 let weaker = if visibility == "public" {
2282 ""
2283 } else {
2284 " or weaker"
2285 };
2286 format!("Access level to {class}::{method}() must be {visibility} (as in class {parent}){weaker}")
2287 }
2288 IssueKind::OverriddenPropertyAccess {
2289 class,
2290 property,
2291 parent,
2292 visibility,
2293 } => {
2294 let weaker = if visibility == "public" {
2295 ""
2296 } else {
2297 " or weaker"
2298 };
2299 format!("Access level to {class}::${property} must be {visibility} (as in class {parent}){weaker}")
2300 }
2301 IssueKind::PropertyTypeRedeclarationMismatch {
2302 class,
2303 property,
2304 parent,
2305 expected,
2306 covariant,
2307 before_php85,
2308 } => {
2309 if expected.is_empty() && *before_php85 {
2310 format!(
2311 "Type of {class}::${property} must not be defined (as in class {parent})"
2312 )
2313 } else if expected.is_empty() {
2314 format!(
2315 "Type of {class}::${property} must be omitted to match the parent definition in class {parent}"
2316 )
2317 } else {
2318 let subtype = if *covariant { "subtype of " } else { "" };
2319 format!(
2320 "Type of {class}::${property} must be {subtype}{expected} (as in class {parent})"
2321 )
2322 }
2323 }
2324 IssueKind::NonInvariantDocblockPropertyType {
2325 class,
2326 property,
2327 parent,
2328 expected,
2329 actual,
2330 } => format!(
2331 "Docblock type '{actual}' of {class}::${property} is not invariant with '{expected}' in class {parent}"
2332 ),
2333 IssueKind::ReadonlyPropertyRedeclarationMismatch {
2334 parent_class,
2335 class,
2336 property,
2337 parent_readonly,
2338 } => {
2339 if *parent_readonly {
2340 format!(
2341 "Cannot redeclare readonly property {parent_class}::${property} as non-readonly {class}::${property}"
2342 )
2343 } else {
2344 format!(
2345 "Cannot redeclare non-readonly property {parent_class}::${property} as readonly {class}::${property}"
2346 )
2347 }
2348 }
2349 IssueKind::StaticPropertyRedeclarationMismatch {
2350 parent_class,
2351 class,
2352 property,
2353 parent_static,
2354 } => {
2355 if *parent_static {
2356 format!(
2357 "Cannot redeclare static property {parent_class}::${property} as non-static {class}::${property}"
2358 )
2359 } else {
2360 format!(
2361 "Cannot redeclare non-static property {parent_class}::${property} as static {class}::${property}"
2362 )
2363 }
2364 }
2365 IssueKind::BackedEnumCaseTypeMismatch {
2366 expected, actual, ..
2367 } => format!("Enum case type {actual} does not match enum backing type {expected}"),
2368 IssueKind::DuplicateEnumCaseValue {
2369 enum_name,
2370 first_case,
2371 case_name,
2372 } => {
2373 format!(
2374 "Duplicate value in enum {enum_name} for cases {first_case} and {case_name}"
2375 )
2376 }
2377 IssueKind::ReadonlyClassExtendsMismatch {
2378 parent,
2379 child,
2380 parent_readonly,
2381 } => {
2382 if *parent_readonly {
2383 format!("Non-readonly class {child} cannot extend readonly class {parent}")
2384 } else {
2385 format!("Readonly class {child} cannot extend non-readonly class {parent}")
2386 }
2387 }
2388 IssueKind::InvalidReadonlyPropertyDeclaration { class, property } => {
2389 format!("Readonly property {class}::${property} cannot have default value")
2390 }
2391 IssueKind::ReadonlyPropertyAssignment {
2392 class,
2393 property,
2394 unset: true,
2395 } => format!("Cannot unset readonly property {class}::${property}"),
2396 IssueKind::ReadonlyPropertyAssignment {
2397 class, property, ..
2398 } => {
2399 format!(
2400 "Cannot assign to readonly property {class}::${property} outside of constructor"
2401 )
2402 }
2403 IssueKind::ReadonlyPropertyAlreadyInitialized { class, property } => {
2404 format!(
2405 "Cannot modify readonly property {class}::${property} — already initialized"
2406 )
2407 }
2408 IssueKind::InvalidExtendClass {
2409 parent,
2410 child,
2411 reason,
2412 } => match reason {
2413 Some(reason) => reason.clone(),
2414 None => format!("Class {child} cannot extend final class {parent}"),
2415 },
2416 IssueKind::InvalidTemplateParam {
2417 name,
2418 expected_bound,
2419 actual,
2420 } => {
2421 if actual.split('|').any(|part| part == "false") {
2422 format!(
2423 "Template type '{name}' inferred as '{actual}' can be false and therefore does not satisfy bound '{expected_bound}'"
2424 )
2425 } else {
2426 format!(
2427 "Template type '{name}' inferred as '{actual}' does not satisfy bound '{expected_bound}'"
2428 )
2429 }
2430 }
2431 IssueKind::ShadowedTemplateParam { name } => {
2432 format!(
2433 "Method template parameter '{name}' shadows class-level template parameter with the same name"
2434 )
2435 }
2436 IssueKind::FinalMethodOverridden {
2437 class,
2438 method,
2439 parent,
2440 } => {
2441 format!("Method {class}::{method}() cannot override final method from {parent}")
2442 }
2443 IssueKind::AbstractInstantiation { class } => {
2444 format!("Cannot instantiate abstract class {class}")
2445 }
2446 IssueKind::AbstractMethodCall { class, method } => {
2447 format!("Cannot call abstract method {class}::{method}()")
2448 }
2449 IssueKind::InterfaceInstantiation { class } => {
2450 format!("Cannot instantiate interface {class}")
2451 }
2452 IssueKind::EnumInstantiation { class } => format!("Cannot instantiate enum {class}"),
2453 IssueKind::TraitInstantiation { class } => format!("Cannot instantiate trait {class}"),
2454 IssueKind::InvalidDynamicProperty { class, property } => {
2455 format!("Cannot create dynamic property {class}::${property}")
2456 }
2457 IssueKind::DynamicPropertyCreation { class, property } => {
2458 format!("Creation of dynamic property {class}::${property} is deprecated")
2459 }
2460 IssueKind::InvalidOverride { class, member } => {
2461 let kind = if member.starts_with('$') {
2462 "property"
2463 } else {
2464 "method"
2465 };
2466 format!(
2467 "{class}::{member} has #[\\Override] attribute, but no matching parent {kind} exists"
2468 )
2469 }
2470
2471 IssueKind::TaintedInput { sink } => format!("Tainted input reaching sink '{sink}'"),
2472 IssueKind::TaintedHtml => "Tainted HTML output — possible XSS".to_string(),
2473 IssueKind::TaintedSql => "Tainted SQL query — possible SQL injection".to_string(),
2474 IssueKind::TaintedShell => {
2475 "Tainted shell command — possible command injection".to_string()
2476 }
2477 IssueKind::TaintedLlmPrompt => {
2478 "Tainted LLM prompt — possible prompt injection".to_string()
2479 }
2480 IssueKind::TaintedHeader => {
2481 "Tainted HTTP header — possible header injection or open redirect".to_string()
2482 }
2483 IssueKind::TaintedCookie => "Tainted cookie — possible cookie injection".to_string(),
2484 IssueKind::TaintedSsrf => {
2485 "Tainted URL — possible server-side request forgery".to_string()
2486 }
2487 IssueKind::TaintedLdap => "Tainted LDAP query — possible LDAP injection".to_string(),
2488 IssueKind::TaintedXpath => "Tainted XPath query — possible XPath injection".to_string(),
2489 IssueKind::TaintedCallable => {
2490 "Tainted callable — user input chooses the code that runs".to_string()
2491 }
2492 IssueKind::TaintedFile => "Tainted file path — possible path traversal".to_string(),
2493 IssueKind::TaintedInclude => {
2494 "Tainted include path — possible file inclusion".to_string()
2495 }
2496 IssueKind::TaintedEval => "Tainted eval() code — possible code injection".to_string(),
2497 IssueKind::TaintedUnserialize => {
2498 "Tainted unserialize() payload — possible object injection".to_string()
2499 }
2500
2501 IssueKind::DeprecatedCall { name, message } => {
2502 let base = format!("Call to deprecated function {name}");
2503 append_deprecation_message(base, message)
2504 }
2505 IssueKind::DeprecatedProperty {
2506 class,
2507 property,
2508 message,
2509 } => {
2510 let base = format!("Property {class}::${property} is deprecated");
2511 append_deprecation_message(base, message)
2512 }
2513 IssueKind::DeprecatedConstant {
2514 class,
2515 constant,
2516 message,
2517 } => {
2518 let base = format!("Constant {class}::{constant} is deprecated");
2519 append_deprecation_message(base, message)
2520 }
2521 IssueKind::OptionalParameterBeforeRequired { message }
2522 | IssueKind::ImplicitlyNullableParameter { message } => message.clone(),
2523 IssueKind::DeprecatedInterface { name, message } => {
2524 let base = format!("Interface {name} is deprecated");
2525 append_deprecation_message(base, message)
2526 }
2527 IssueKind::DeprecatedTrait { name, message } => {
2528 let base = format!("Trait {name} is deprecated");
2529 append_deprecation_message(base, message)
2530 }
2531 IssueKind::DeprecatedMethodCall {
2532 class,
2533 method,
2534 message,
2535 } => {
2536 let base = format!("Call to deprecated method {class}::{method}");
2537 append_deprecation_message(base, message)
2538 }
2539 IssueKind::DeprecatedMethod {
2540 class,
2541 method,
2542 message,
2543 } => {
2544 let base = format!("Method {class}::{method}() is deprecated");
2545 append_deprecation_message(base, message)
2546 }
2547 IssueKind::DeprecatedClass { name, message } => {
2548 let base = format!("Class {name} is deprecated");
2549 append_deprecation_message(base, message)
2550 }
2551 IssueKind::InternalMethod { class, method } => {
2552 format!("Method {class}::{method}() is marked @internal")
2553 }
2554 IssueKind::MissingReturnType { fn_name } => {
2555 format!("Function {fn_name}() has no return type annotation")
2556 }
2557 IssueKind::MissingClosureReturnType => {
2558 "Closure has no return type annotation".to_string()
2559 }
2560 IssueKind::MissingParamType { fn_name, param } => {
2561 format!("Parameter ${param} of {fn_name}() has no type annotation")
2562 }
2563 IssueKind::MissingPropertyType { class, property } => {
2564 format!("Property {class}::${property} has no type annotation")
2565 }
2566 IssueKind::InvalidThrow { ty } => {
2567 format!("Thrown type '{ty}' does not extend Throwable")
2568 }
2569 IssueKind::InvalidCatch { ty } => {
2570 format!("Caught type '{ty}' does not extend Throwable")
2571 }
2572 IssueKind::UnreachableCatch { ty, shadowed_by } => {
2573 format!("Catch block for '{ty}' is unreachable — already caught by '{shadowed_by}'")
2574 }
2575 IssueKind::MissingThrowsDocblock { class } => {
2576 format!("Exception {class} is thrown but not declared in @throws")
2577 }
2578 IssueKind::ImplicitToStringCast { class } => {
2579 format!("Class {class} is implicitly cast to string")
2580 }
2581 IssueKind::ImplicitFloatToIntCast { from } => {
2582 format!("Implicit cast from {from} to int truncates the fractional part")
2583 }
2584 IssueKind::ParseError { message, code } => format!("{message} [{code}]"),
2585 IssueKind::CompileError { message, code } => {
2586 format!("{message} [{code}]")
2587 }
2588 IssueKind::InvalidDocblock { message } => message.clone(),
2589 IssueKind::UndefinedThrowsDocblock { name } => {
2590 format!("@throws class '{name}' does not exist")
2591 }
2592 IssueKind::InvalidDocblockType { message } => message.clone(),
2593 IssueKind::MixedArgument { param, fn_name } => {
2594 format!("Argument ${param} of {fn_name}() is mixed")
2595 }
2596 IssueKind::MixedAssignment { var } => {
2597 format!("Variable ${var} is assigned a mixed type")
2598 }
2599 IssueKind::MixedMethodCall { method } => {
2600 format!("Method {method}() called on mixed type")
2601 }
2602 IssueKind::UnsupportedReferenceUsage => {
2603 "Reference assignment is not supported".to_string()
2604 }
2605 IssueKind::NoInterfaceProperties { property } => {
2606 format!("Property ${property} is not defined on this interface")
2607 }
2608 IssueKind::UndefinedDocblockClass { name } => {
2609 format!("Docblock type '{name}' does not exist")
2610 }
2611 IssueKind::MissingConstructor { class } => {
2612 format!("Class {class} has uninitialized properties but no constructor")
2613 }
2614 IssueKind::PropertyPossiblyUninitialized { class, property } => {
2615 format!(
2616 "Property {class}::${property} may be left uninitialized by the constructor"
2617 )
2618 }
2619 IssueKind::MixedFunctionCall => "Cannot call mixed type as a function".to_string(),
2620 IssueKind::MixedReturnStatement { declared } => {
2621 format!("Cannot return a mixed type from function with declared return type '{declared}'")
2622 }
2623 IssueKind::MixedPropertyFetch { property } => {
2624 format!("Property ${property} fetched on mixed type")
2625 }
2626 IssueKind::MixedPropertyAssignment { property } => {
2627 format!("Property ${property} assigned on mixed type")
2628 }
2629 IssueKind::MixedArrayAccess => "Array access on mixed type".to_string(),
2630 IssueKind::MixedArrayOffset => "Mixed type used as array offset".to_string(),
2631 IssueKind::MixedClone => "cannot clone mixed".to_string(),
2632 IssueKind::InvalidClone { ty, reason } => match reason {
2633 CloneFailure::NonObject => format!("cannot clone non-object {ty}"),
2634 CloneFailure::Enum => {
2635 format!("Trying to clone an uncloneable object of class {ty}")
2636 }
2637 CloneFailure::PrivateMethod { owner, scope } => match scope {
2638 Some(scope) => {
2639 format!("Call to private method {owner}::__clone() from scope {scope}")
2640 }
2641 None => format!("Call to private method {owner}::__clone() from global scope"),
2642 },
2643 },
2644 IssueKind::PossiblyInvalidClone { ty } => {
2645 format!("cannot clone possibly non-object {ty}")
2646 }
2647 IssueKind::InvalidToString { class } => {
2648 format!("Method {class}::__toString() must return a string")
2649 }
2650 IssueKind::CircularInheritance { class } => {
2651 format!("Class {class} has a circular inheritance chain")
2652 }
2653 IssueKind::InvalidTraitUse { trait_name, reason } => {
2654 format!("Trait {trait_name} used incorrectly: {reason}")
2655 }
2656 IssueKind::WrongCaseFunction { used, canonical } => {
2657 format!("Function name '{used}' has incorrect casing; use '{canonical}'")
2658 }
2659 IssueKind::WrongCaseMethod {
2660 class,
2661 used,
2662 canonical,
2663 } => {
2664 format!("Method name '{class}::{used}' has incorrect casing; use '{canonical}'")
2665 }
2666 IssueKind::WrongCaseClass { used, canonical } => {
2667 format!("Class name '{used}' has incorrect casing; use '{canonical}'")
2668 }
2669 IssueKind::InvalidAttribute { message } => message.clone(),
2670 IssueKind::UndefinedAttributeClass { name } => {
2671 format!("Attribute class {name} does not exist")
2672 }
2673 IssueKind::ForbiddenCode { message } => message.clone(),
2674 IssueKind::DuplicateClass { name } => {
2675 format!("Class {name} has already been defined")
2676 }
2677 IssueKind::DuplicateInterface { name } => {
2678 format!("Interface {name} has already been defined")
2679 }
2680 IssueKind::DuplicateTrait { name } => {
2681 format!("Trait {name} has already been defined")
2682 }
2683 IssueKind::DuplicateEnum { name } => {
2684 format!("Enum {name} has already been defined")
2685 }
2686 IssueKind::DuplicateFunction { name } => {
2687 format!("Function {name}() has already been defined")
2688 }
2689 IssueKind::UseStatementHasNoEffect { name } => {
2690 format!("The use statement with non-compound name '{name}' has no effect")
2691 }
2692 IssueKind::PrivateFinalMethod { class, method } => {
2693 format!("Private method {class}::{method}() cannot be final as it is never overridden by other classes")
2694 }
2695 IssueKind::NoDiscardReturnIgnored { callee, message } => {
2696 let reason = message.as_deref().map(|m| format!(", {m}")).unwrap_or_default();
2697 format!("The return value of {callee}() should either be used or intentionally ignored by casting it as (void){reason}")
2698 }
2699 IssueKind::NonPublicMagicMethod { class, method } => {
2700 format!("The magic method {class}::{method}() must have public visibility")
2701 }
2702 IssueKind::PluginIssue { message, .. } => message.clone(),
2703 }
2704 }
2705}
2706
2707#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2713pub struct TaintStep {
2714 pub label: String,
2716 pub location: Location,
2717}
2718
2719#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2720pub struct Issue {
2721 pub kind: IssueKind,
2722 pub severity: Severity,
2723 pub location: Location,
2724 pub snippet: Option<String>,
2725 pub suppressed: bool,
2726 #[serde(default)]
2728 pub taint_trace: Option<Box<[TaintStep]>>,
2729}
2730
2731impl Issue {
2732 pub fn new(kind: IssueKind, location: Location) -> Self {
2733 let severity = kind.default_severity();
2734 Self {
2735 severity,
2736 kind,
2737 location,
2738 snippet: None,
2739 suppressed: false,
2740 taint_trace: None,
2741 }
2742 }
2743
2744 pub fn with_snippet(mut self, snippet: impl Into<String>) -> Self {
2745 self.snippet = Some(snippet.into());
2746 self
2747 }
2748
2749 pub fn suppress(mut self) -> Self {
2750 self.suppressed = true;
2751 self
2752 }
2753}
2754
2755#[derive(Debug, Default)]
2760pub struct IssueBuffer {
2761 issues: Vec<Issue>,
2762 seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
2763 file_suppressions: Vec<String>,
2765 discard: bool,
2766}
2767
2768impl IssueBuffer {
2769 pub fn new() -> Self {
2770 Self::default()
2771 }
2772
2773 pub fn discarding(mut self) -> Self {
2774 self.discard = true;
2775 self
2776 }
2777
2778 pub fn is_discarding(&self) -> bool {
2779 self.discard
2780 }
2781
2782 pub fn add(&mut self, issue: Issue) {
2783 if self.discard {
2784 return;
2785 }
2786 let key = (
2787 issue.kind.name(),
2788 issue.location.file.clone(),
2789 issue.location.line,
2790 issue.location.col_start,
2791 );
2792 if self.seen.insert(key) {
2793 self.issues.push(issue);
2794 }
2795 }
2796
2797 pub fn has_impossible_comparison_within(&self, span: &Location) -> bool {
2800 self.issues.iter().any(|i| {
2801 matches!(
2802 i.kind,
2803 IssueKind::ImpossibleIdenticalComparison { .. }
2804 | IssueKind::ImpossibleLooseComparison { .. }
2805 | IssueKind::DocblockTypeContradiction { .. }
2806 | IssueKind::TypeDoesNotContainType { .. }
2807 ) && i.location.file == span.file
2808 && (i.location.line, i.location.col_start) >= (span.line, span.col_start)
2809 && (i.location.line, i.location.col_start) < (span.line_end, span.col_end)
2810 })
2811 }
2812
2813 pub fn add_suppression(&mut self, name: impl Into<String>) {
2814 self.file_suppressions.push(name.into());
2815 }
2816
2817 pub fn into_issues(self) -> Vec<Issue> {
2819 self.issues
2820 .into_iter()
2821 .filter(|i| !i.suppressed)
2822 .filter(|i| {
2823 !self
2824 .file_suppressions
2825 .iter()
2826 .any(|s| s == i.kind.display_name())
2827 })
2828 .collect()
2829 }
2830
2831 pub fn into_all_issues(self) -> Vec<Issue> {
2836 self.issues
2837 .into_iter()
2838 .map(|mut i| {
2839 if self
2840 .file_suppressions
2841 .iter()
2842 .any(|s| s == i.kind.display_name())
2843 {
2844 i.suppressed = true;
2845 }
2846 i
2847 })
2848 .collect()
2849 }
2850
2851 pub fn suppress_range(&mut self, from: usize, suppressions: &[String]) {
2854 if suppressions.is_empty() {
2855 return;
2856 }
2857 for issue in self.issues[from..].iter_mut() {
2858 if suppressions.iter().any(|s| s == issue.kind.display_name()) {
2859 issue.suppressed = true;
2860 }
2861 }
2862 }
2863
2864 pub fn suppress_range_where(&mut self, from: usize, pred: impl Fn(&Issue) -> bool) {
2866 for issue in self.issues[from..].iter_mut().filter(|i| pred(i)) {
2867 issue.suppressed = true;
2868 }
2869 }
2870
2871 pub fn issue_count(&self) -> usize {
2874 self.issues.len()
2875 }
2876
2877 pub fn truncate_to(&mut self, mark: usize) {
2883 for issue in self.issues.drain(mark..) {
2884 let key = (
2885 issue.kind.name(),
2886 issue.location.file.clone(),
2887 issue.location.line,
2888 issue.location.col_start,
2889 );
2890 self.seen.remove(&key);
2891 }
2892 }
2893
2894 pub fn take_since(&mut self, mark: usize, pred: impl Fn(&IssueKind) -> bool) -> Vec<Issue> {
2896 self.take_range(mark, self.issues.len(), pred)
2897 }
2898
2899 pub fn take_range(
2901 &mut self,
2902 mark: usize,
2903 mut end: usize,
2904 pred: impl Fn(&IssueKind) -> bool,
2905 ) -> Vec<Issue> {
2906 let mut taken = Vec::new();
2907 let mut i = mark;
2908 while i < end {
2909 if pred(&self.issues[i].kind) {
2910 let issue = self.issues.remove(i);
2911 self.seen.remove(&(
2912 issue.kind.name(),
2913 issue.location.file.clone(),
2914 issue.location.line,
2915 issue.location.col_start,
2916 ));
2917 end -= 1;
2918 taken.push(issue);
2919 } else {
2920 i += 1;
2921 }
2922 }
2923 taken
2924 }
2925
2926 pub fn is_empty(&self) -> bool {
2927 self.issues.is_empty()
2928 }
2929
2930 pub fn len(&self) -> usize {
2931 self.issues.len()
2932 }
2933
2934 pub fn error_count(&self) -> usize {
2935 self.issues
2936 .iter()
2937 .filter(|i| !i.suppressed && i.severity == Severity::Error)
2938 .count()
2939 }
2940
2941 pub fn warning_count(&self) -> usize {
2942 self.issues
2943 .iter()
2944 .filter(|i| !i.suppressed && i.severity == Severity::Warning)
2945 .count()
2946 }
2947}
2948
2949#[cfg(test)]
2950mod code_tests {
2951 use super::*;
2952 use std::collections::HashSet;
2953
2954 fn one_of_each() -> Vec<IssueKind> {
2960 let s = || String::new();
2961 vec![
2962 IssueKind::InvalidScope { in_class: false },
2963 IssueKind::NonStaticSelfCall {
2964 class: s(),
2965 method: s(),
2966 },
2967 IssueKind::DirectConstructorCall { class: s() },
2968 IssueKind::UndefinedVariable { name: s() },
2969 IssueKind::UndefinedFunction { name: s() },
2970 IssueKind::UndefinedMethod {
2971 class: s(),
2972 method: s(),
2973 },
2974 IssueKind::PossiblyUndefinedMethod {
2975 class: s(),
2976 method: s(),
2977 },
2978 IssueKind::UndefinedClass { name: s() },
2979 IssueKind::NotAnInterface { name: s() },
2980 IssueKind::UndefinedProperty {
2981 class: s(),
2982 property: s(),
2983 },
2984 IssueKind::UndefinedConstant { name: s() },
2985 IssueKind::InaccessibleClassConstant {
2986 class: s(),
2987 constant: s(),
2988 },
2989 IssueKind::InaccessibleProperty {
2990 class: s(),
2991 property: s(),
2992 },
2993 IssueKind::PossiblyUndefinedVariable { name: s() },
2994 IssueKind::UndefinedTrait { name: s() },
2995 IssueKind::TraitConstantAccessedDirectly {
2996 trait_name: s(),
2997 constant: s(),
2998 },
2999 IssueKind::UndefinedTraitAliasMethod {
3000 trait_name: Some(s()),
3001 method: s(),
3002 },
3003 IssueKind::ParentNotFound,
3004 IssueKind::NullArgument {
3005 param: s(),
3006 fn_name: s(),
3007 },
3008 IssueKind::NullPropertyFetch { property: s() },
3009 IssueKind::NullMethodCall { method: s() },
3010 IssueKind::NullArrayAccess,
3011 IssueKind::PossiblyNullArgument {
3012 param: s(),
3013 fn_name: s(),
3014 },
3015 IssueKind::PossiblyInvalidArgument {
3016 param: s(),
3017 fn_name: s(),
3018 expected: s(),
3019 actual: s(),
3020 },
3021 IssueKind::PossiblyNullPropertyFetch { property: s() },
3022 IssueKind::PossiblyNullMethodCall { method: s() },
3023 IssueKind::PossiblyNullArrayAccess,
3024 IssueKind::NullableReturnStatement {
3025 expected: s(),
3026 actual: s(),
3027 },
3028 IssueKind::InvalidReturnType {
3029 expected: s(),
3030 actual: s(),
3031 },
3032 IssueKind::LessSpecificReturnStatement {
3033 expected: s(),
3034 actual: s(),
3035 },
3036 IssueKind::InvalidArgument {
3037 param: s(),
3038 fn_name: s(),
3039 expected: s(),
3040 actual: s(),
3041 },
3042 IssueKind::InvalidScalarArgument {
3043 param: s(),
3044 fn_name: s(),
3045 expected: s(),
3046 actual: s(),
3047 },
3048 IssueKind::TooFewArguments {
3049 fn_name: s(),
3050 expected: 0,
3051 actual: 0,
3052 },
3053 IssueKind::TooManyArguments {
3054 fn_name: s(),
3055 expected: 0,
3056 actual: 0,
3057 },
3058 IssueKind::InvalidNamedArgument {
3059 fn_name: s(),
3060 name: s(),
3061 overwrites: false,
3062 },
3063 IssueKind::InvalidNamedArguments { fn_name: s() },
3064 IssueKind::InvalidPassByReference {
3065 fn_name: s(),
3066 param: s(),
3067 },
3068 IssueKind::InvalidPropertyFetch { ty: s() },
3069 IssueKind::InvalidMethodCall {
3070 method: s(),
3071 ty: s(),
3072 },
3073 IssueKind::InvalidMemberName {
3074 member: s(),
3075 ty: s(),
3076 },
3077 IssueKind::NativeResourceType { class: s() },
3078 IssueKind::InvalidUnpack { ty: s() },
3079 IssueKind::InvalidArrayAccess { ty: s() },
3080 IssueKind::PossiblyInvalidArrayAccess { ty: s() },
3081 IssueKind::InvalidArrayAssignment { ty: s() },
3082 IssueKind::InvalidPropertyAssignment {
3083 property: s(),
3084 expected: s(),
3085 actual: s(),
3086 },
3087 IssueKind::PossiblyNullPropertyAssignmentValue {
3088 property: s(),
3089 expected: s(),
3090 actual: s(),
3091 },
3092 IssueKind::PossiblyFalsePropertyAssignmentValue {
3093 property: s(),
3094 expected: s(),
3095 actual: s(),
3096 },
3097 IssueKind::PossiblyInvalidPropertyAssignmentValue {
3098 property: s(),
3099 expected: s(),
3100 actual: s(),
3101 },
3102 IssueKind::InvalidCast { from: s(), to: s() },
3103 IssueKind::InvalidStaticInvocation {
3104 class: s(),
3105 method: s(),
3106 },
3107 IssueKind::InvalidOperand {
3108 op: s(),
3109 left: s(),
3110 right: s(),
3111 },
3112 IssueKind::PossiblyInvalidOperand {
3113 op: s(),
3114 left: s(),
3115 right: s(),
3116 },
3117 IssueKind::PossiblyNullOperand { op: s(), ty: s() },
3118 IssueKind::DivisionByZero { op: s() },
3119 IssueKind::RawObjectIteration { ty: s() },
3120 IssueKind::PossiblyRawObjectIteration { ty: s() },
3121 IssueKind::InvalidGeneratorIteration { ty: s(), send: s() },
3122 IssueKind::MismatchingDocblockReturnType {
3123 declared: s(),
3124 inferred: s(),
3125 },
3126 IssueKind::MismatchingDocblockParamType {
3127 param: s(),
3128 declared: s(),
3129 inferred: s(),
3130 },
3131 IssueKind::TypeCheckMismatch {
3132 var: s(),
3133 expected: s(),
3134 actual: s(),
3135 },
3136 IssueKind::Trace {
3137 variable: s(),
3138 type_info: s(),
3139 },
3140 IssueKind::InvalidArrayOffset {
3141 expected: s(),
3142 actual: s(),
3143 },
3144 IssueKind::NonExistentArrayOffset { key: s() },
3145 IssueKind::PossiblyInvalidArrayOffset {
3146 expected: s(),
3147 actual: s(),
3148 },
3149 IssueKind::DuplicateArrayKey { key: s() },
3150 IssueKind::RedundantCondition {
3151 always_true: true,
3152 unreachable: None,
3153 },
3154 IssueKind::RedundantCast { from: s(), to: s() },
3155 IssueKind::UnnecessaryVarAnnotation { var: s() },
3156 IssueKind::TypeDoesNotContainType {
3157 left: s(),
3158 right: s(),
3159 },
3160 IssueKind::UnusedVariable { name: s() },
3161 IssueKind::UnusedParam { name: s() },
3162 IssueKind::UnreachableCode,
3163 IssueKind::UnhandledMatchCondition { detail: s() },
3164 IssueKind::UnusedMethod {
3165 class: s(),
3166 method: s(),
3167 },
3168 IssueKind::UnusedProperty {
3169 class: s(),
3170 property: s(),
3171 },
3172 IssueKind::UnusedFunction { name: s() },
3173 IssueKind::UnusedForeachValue { name: s() },
3174 IssueKind::UnusedClass { class: s() },
3175 IssueKind::UnusedConstant {
3176 class: s(),
3177 constant: s(),
3178 },
3179 IssueKind::UnusedSuppress { kind: s() },
3180 IssueKind::ArgumentTypeCoercion {
3181 param: s(),
3182 fn_name: s(),
3183 expected: s(),
3184 actual: s(),
3185 },
3186 IssueKind::PropertyTypeCoercion {
3187 property: s(),
3188 expected: s(),
3189 actual: s(),
3190 },
3191 IssueKind::ImpurePropertyAssignment { property: s() },
3192 IssueKind::ImpureMethodCall { method: s() },
3193 IssueKind::ImpureGlobalVariable { variable: s() },
3194 IssueKind::ImpureStaticVariable { variable: s() },
3195 IssueKind::ImpureByRefAssignment { variable: s() },
3196 IssueKind::ImpureStaticPropertyAssignment {
3197 class: s(),
3198 property: s(),
3199 },
3200 IssueKind::ImpureStaticPropertyAccess {
3201 class: s(),
3202 property: s(),
3203 },
3204 IssueKind::ImpureFunctionCall { fn_name: s() },
3205 IssueKind::ImmutablePropertyModification {
3206 receiver: s(),
3207 property: s(),
3208 },
3209 IssueKind::ReadonlyPropertyAssignment {
3210 class: s(),
3211 property: s(),
3212 unset: false,
3213 },
3214 IssueKind::ReadonlyPropertyAlreadyInitialized {
3215 class: s(),
3216 property: s(),
3217 },
3218 IssueKind::UnimplementedAbstractMethod {
3219 class: s(),
3220 method: s(),
3221 },
3222 IssueKind::UnimplementedInterfaceMethod {
3223 class: s(),
3224 interface: s(),
3225 method: s(),
3226 },
3227 IssueKind::MethodSignatureMismatch {
3228 class: s(),
3229 method: s(),
3230 detail: s(),
3231 },
3232 IssueKind::OverriddenMethodAccess {
3233 class: s(),
3234 method: s(),
3235 parent: s(),
3236 visibility: s(),
3237 },
3238 IssueKind::OverriddenPropertyAccess {
3239 class: s(),
3240 property: s(),
3241 parent: s(),
3242 visibility: s(),
3243 },
3244 IssueKind::PropertyTypeRedeclarationMismatch {
3245 class: s(),
3246 property: s(),
3247 parent: s(),
3248 expected: s(),
3249 covariant: false,
3250 before_php85: false,
3251 },
3252 IssueKind::NonInvariantDocblockPropertyType {
3253 class: s(),
3254 property: s(),
3255 parent: s(),
3256 expected: s(),
3257 actual: s(),
3258 },
3259 IssueKind::ReadonlyPropertyRedeclarationMismatch {
3260 parent_class: s(),
3261 class: s(),
3262 property: s(),
3263 parent_readonly: true,
3264 },
3265 IssueKind::StaticPropertyRedeclarationMismatch {
3266 parent_class: s(),
3267 class: s(),
3268 property: s(),
3269 parent_static: true,
3270 },
3271 IssueKind::ReadonlyClassExtendsMismatch {
3272 parent: s(),
3273 child: s(),
3274 parent_readonly: true,
3275 },
3276 IssueKind::InvalidReadonlyPropertyDeclaration {
3277 class: s(),
3278 property: s(),
3279 },
3280 IssueKind::BackedEnumCaseTypeMismatch {
3281 enum_name: s(),
3282 case_name: s(),
3283 expected: s(),
3284 actual: s(),
3285 },
3286 IssueKind::DuplicateEnumCaseValue {
3287 enum_name: s(),
3288 first_case: s(),
3289 case_name: s(),
3290 },
3291 IssueKind::InvalidExtendClass {
3292 parent: s(),
3293 child: s(),
3294 reason: None,
3295 },
3296 IssueKind::FinalMethodOverridden {
3297 class: s(),
3298 method: s(),
3299 parent: s(),
3300 },
3301 IssueKind::AbstractInstantiation { class: s() },
3302 IssueKind::AbstractMethodCall {
3303 class: s(),
3304 method: s(),
3305 },
3306 IssueKind::InterfaceInstantiation { class: s() },
3307 IssueKind::EnumInstantiation { class: s() },
3308 IssueKind::TraitInstantiation { class: s() },
3309 IssueKind::InvalidDynamicProperty {
3310 class: s(),
3311 property: s(),
3312 },
3313 IssueKind::DynamicPropertyCreation {
3314 class: s(),
3315 property: s(),
3316 },
3317 IssueKind::InvalidOverride {
3318 class: s(),
3319 member: s(),
3320 },
3321 IssueKind::CircularInheritance { class: s() },
3322 IssueKind::TaintedInput { sink: s() },
3323 IssueKind::TaintedHtml,
3324 IssueKind::TaintedSql,
3325 IssueKind::TaintedShell,
3326 IssueKind::TaintedLlmPrompt,
3327 IssueKind::TaintedHeader,
3328 IssueKind::TaintedCookie,
3329 IssueKind::TaintedSsrf,
3330 IssueKind::TaintedLdap,
3331 IssueKind::TaintedXpath,
3332 IssueKind::TaintedCallable,
3333 IssueKind::TaintedFile,
3334 IssueKind::TaintedInclude,
3335 IssueKind::TaintedEval,
3336 IssueKind::TaintedUnserialize,
3337 IssueKind::InvalidTemplateParam {
3338 name: s(),
3339 expected_bound: s(),
3340 actual: s(),
3341 },
3342 IssueKind::ShadowedTemplateParam { name: s() },
3343 IssueKind::DeprecatedCall {
3344 name: s(),
3345 message: None,
3346 },
3347 IssueKind::DeprecatedProperty {
3348 class: s(),
3349 property: s(),
3350 message: None,
3351 },
3352 IssueKind::DeprecatedConstant {
3353 class: s(),
3354 constant: s(),
3355 message: None,
3356 },
3357 IssueKind::OptionalParameterBeforeRequired { message: s() },
3358 IssueKind::ImplicitlyNullableParameter { message: s() },
3359 IssueKind::DeprecatedInterface {
3360 name: s(),
3361 message: None,
3362 },
3363 IssueKind::DeprecatedTrait {
3364 name: s(),
3365 message: None,
3366 },
3367 IssueKind::DeprecatedMethodCall {
3368 class: s(),
3369 method: s(),
3370 message: None,
3371 },
3372 IssueKind::DeprecatedMethod {
3373 class: s(),
3374 method: s(),
3375 message: None,
3376 },
3377 IssueKind::DeprecatedClass {
3378 name: s(),
3379 message: None,
3380 },
3381 IssueKind::InternalMethod {
3382 class: s(),
3383 method: s(),
3384 },
3385 IssueKind::MissingReturnType { fn_name: s() },
3386 IssueKind::MissingClosureReturnType,
3387 IssueKind::MissingParamType {
3388 fn_name: s(),
3389 param: s(),
3390 },
3391 IssueKind::MissingPropertyType {
3392 class: s(),
3393 property: s(),
3394 },
3395 IssueKind::MissingThrowsDocblock { class: s() },
3396 IssueKind::InvalidDocblock { message: s() },
3397 IssueKind::UndefinedThrowsDocblock { name: s() },
3398 IssueKind::InvalidDocblockType { message: s() },
3399 IssueKind::MixedArgument {
3400 param: s(),
3401 fn_name: s(),
3402 },
3403 IssueKind::MixedAssignment { var: s() },
3404 IssueKind::MixedMethodCall { method: s() },
3405 IssueKind::UnsupportedReferenceUsage,
3406 IssueKind::NoInterfaceProperties { property: s() },
3407 IssueKind::UndefinedDocblockClass { name: s() },
3408 IssueKind::MissingConstructor { class: s() },
3409 IssueKind::PropertyPossiblyUninitialized {
3410 class: s(),
3411 property: s(),
3412 },
3413 IssueKind::MixedFunctionCall,
3414 IssueKind::MixedReturnStatement { declared: s() },
3415 IssueKind::MixedPropertyFetch { property: s() },
3416 IssueKind::MixedPropertyAssignment { property: s() },
3417 IssueKind::MixedArrayAccess,
3418 IssueKind::MixedArrayOffset,
3419 IssueKind::MixedClone,
3420 IssueKind::InvalidClone {
3421 ty: s(),
3422 reason: CloneFailure::NonObject,
3423 },
3424 IssueKind::PossiblyInvalidClone { ty: s() },
3425 IssueKind::InvalidToString { class: s() },
3426 IssueKind::InvalidTraitUse {
3427 trait_name: s(),
3428 reason: s(),
3429 },
3430 IssueKind::ParseError {
3431 message: s(),
3432 code: s(),
3433 },
3434 IssueKind::CompileError {
3435 message: s(),
3436 code: s(),
3437 },
3438 IssueKind::InvalidThrow { ty: s() },
3439 IssueKind::InvalidCatch { ty: s() },
3440 IssueKind::UnreachableCatch {
3441 ty: s(),
3442 shadowed_by: s(),
3443 },
3444 IssueKind::ImplicitToStringCast { class: s() },
3445 IssueKind::ImplicitFloatToIntCast { from: s() },
3446 IssueKind::WrongCaseFunction {
3447 used: s(),
3448 canonical: s(),
3449 },
3450 IssueKind::WrongCaseMethod {
3451 class: s(),
3452 used: s(),
3453 canonical: s(),
3454 },
3455 IssueKind::WrongCaseClass {
3456 used: s(),
3457 canonical: s(),
3458 },
3459 IssueKind::InvalidAttribute { message: s() },
3460 IssueKind::UndefinedAttributeClass { name: s() },
3461 IssueKind::ForbiddenCode { message: s() },
3462 IssueKind::DuplicateClass { name: s() },
3463 IssueKind::DuplicateInterface { name: s() },
3464 IssueKind::DuplicateTrait { name: s() },
3465 IssueKind::DuplicateEnum { name: s() },
3466 IssueKind::DuplicateFunction { name: s() },
3467 IssueKind::UseStatementHasNoEffect { name: s() },
3468 IssueKind::PrivateFinalMethod {
3469 class: s(),
3470 method: s(),
3471 },
3472 IssueKind::NonPublicMagicMethod {
3473 class: s(),
3474 method: s(),
3475 },
3476 IssueKind::NoDiscardReturnIgnored {
3477 callee: s(),
3478 message: None,
3479 },
3480 ]
3481 }
3482
3483 #[test]
3484 fn codes_have_expected_shape() {
3485 for kind in one_of_each() {
3486 let code = kind.code();
3487 assert!(
3488 code.len() == 7
3489 && code.starts_with("MIR")
3490 && code[3..].chars().all(|c| c.is_ascii_digit()),
3491 "code {code:?} for {} does not match MIR####",
3492 kind.name(),
3493 );
3494 }
3495 }
3496
3497 #[test]
3498 fn codes_are_unique() {
3499 let kinds = one_of_each();
3500 let mut seen: HashSet<&'static str> = HashSet::new();
3501 for kind in &kinds {
3502 assert!(
3503 seen.insert(kind.code()),
3504 "duplicate code {} (variant {})",
3505 kind.code(),
3506 kind.name(),
3507 );
3508 }
3509 }
3510
3511 #[test]
3512 fn default_severity_for_code_round_trips() {
3513 for kind in one_of_each() {
3514 let code = kind.code();
3515 assert_eq!(
3516 IssueKind::default_severity_for_code(code),
3517 Some(kind.default_severity()),
3518 "severity mismatch for {code} (variant {})",
3519 kind.name(),
3520 );
3521 }
3522 }
3523
3524 #[test]
3525 fn default_severity_for_code_unknown_returns_none() {
3526 assert_eq!(IssueKind::default_severity_for_code("MIR9999"), None);
3527 assert_eq!(IssueKind::default_severity_for_code(""), None);
3528 assert_eq!(IssueKind::default_severity_for_code("mir0001"), None);
3529 }
3530
3531 #[test]
3534 fn one_of_each_has_every_variant() {
3535 assert_eq!(one_of_each().len(), 195);
3538 }
3539}