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