1use std::collections::HashSet;
2use std::fmt;
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
12pub enum Severity {
13 Info,
15 Warning,
17 Error,
19}
20
21impl fmt::Display for Severity {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Severity::Info => write!(f, "info"),
25 Severity::Warning => write!(f, "warning"),
26 Severity::Error => write!(f, "error"),
27 }
28 }
29}
30
31pub use mir_types::Location;
36
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[non_exhaustive]
43pub enum IssueKind {
44 NonStaticSelfCall { class: String, method: String },
50 InvalidScope {
51 in_class: bool,
53 },
54 UndefinedVariable { name: String },
57 UndefinedFunction { name: String },
60 UndefinedMethod { class: String, method: String },
63 UndefinedClass { name: String },
66 UndefinedProperty { class: String, property: String },
69 InaccessibleProperty { class: String, property: String },
74 UndefinedConstant { name: String },
77 InaccessibleClassConstant { class: String, constant: String },
80 PossiblyUndefinedVariable { name: String },
83 UndefinedTrait { name: String },
86 TraitConstantAccessedDirectly {
93 trait_name: String,
94 constant: String,
95 },
96 UndefinedTraitAliasMethod {
104 trait_name: Option<String>,
105 method: String,
106 },
107 ParentNotFound,
110 InvalidStringClass { actual: String },
113 NotAnInterface { name: String },
117
118 NullArgument { param: String, fn_name: String },
122 NullPropertyFetch { property: String },
125 NullMethodCall { method: String },
128 NullArrayAccess,
131 PossiblyNullArgument { param: String, fn_name: String },
134 PossiblyInvalidArgument {
137 param: String,
138 fn_name: String,
139 expected: String,
140 actual: String,
141 },
142 PossiblyNullPropertyFetch { property: String },
145 PossiblyNullMethodCall { method: String },
148 PossiblyNullArrayAccess,
151 NullableReturnStatement { expected: String, actual: String },
154
155 InvalidReturnType { expected: String, actual: String },
159 InvalidArgument {
162 param: String,
163 fn_name: String,
164 expected: String,
165 actual: String,
166 },
167 TooFewArguments {
170 fn_name: String,
171 expected: usize,
172 actual: usize,
173 },
174 TooManyArguments {
177 fn_name: String,
178 expected: usize,
179 actual: usize,
180 },
181 InvalidNamedArgument { fn_name: String, name: String },
184 InvalidNamedArguments { fn_name: String },
187 InvalidPassByReference { fn_name: String, param: String },
190 InvalidPropertyFetch { ty: String },
193 InvalidArrayAccess { ty: String },
196 PossiblyInvalidArrayAccess { ty: String },
199 InvalidArrayAssignment { ty: String },
202 InvalidPropertyAssignment {
205 property: String,
206 expected: String,
207 actual: String,
208 },
209 InvalidCast { from: String, to: String },
212 InvalidStaticInvocation { class: String, method: String },
215 InvalidOperand {
219 op: String,
220 left: String,
221 right: String,
222 },
223 PossiblyInvalidOperand {
226 op: String,
227 left: String,
228 right: String,
229 },
230 PossiblyNullOperand { op: String, ty: String },
233 DivisionByZero { op: String },
237 RawObjectIteration { ty: String },
240 PossiblyRawObjectIteration { ty: String },
243 MismatchingDocblockReturnType { declared: String, inferred: String },
246 MismatchingDocblockParamType {
249 param: String,
250 declared: String,
251 inferred: String,
252 },
253 TypeCheckMismatch {
259 var: String,
260 expected: String,
261 actual: String,
262 },
263
264 Trace { variable: String, type_info: String },
267
268 InvalidArrayOffset { expected: String, actual: String },
272 NonExistentArrayOffset { key: String },
276 PossiblyInvalidArrayOffset { expected: String, actual: String },
279 DuplicateArrayKey { key: String },
284
285 RedundantCondition { ty: String },
289 RedundantCast { from: String, to: String },
292 UnnecessaryVarAnnotation { var: String },
295 TypeDoesNotContainType { left: String, right: String },
298 ParadoxicalCondition { value: String },
301 DocblockTypeContradiction { expr: String, declared: String },
306 ImpossibleIdenticalComparison {
312 op: String,
313 left: String,
314 right: String,
315 },
316 ImpossibleLooseComparison {
323 op: String,
324 left: String,
325 right: String,
326 },
327 UnevaluatedCode { reason: String },
334
335 UnusedVariable { name: String },
339 UnusedParam { name: String },
342 UnreachableCode,
345 UnhandledMatchCondition { detail: String },
348 UnusedMethod { class: String, method: String },
351 UnusedProperty { class: String, property: String },
354 UnusedFunction { name: String },
357 UnusedForeachValue { name: String },
360 UnusedClass { class: String },
363 UnusedSuppress { kind: String },
367
368 ArgumentTypeCoercion {
371 param: String,
372 fn_name: String,
373 expected: String,
374 actual: String,
375 },
376
377 PropertyTypeCoercion {
380 property: String,
381 expected: String,
382 actual: String,
383 },
384
385 ImpurePropertyAssignment { property: String },
388 ImpureMethodCall { method: String },
390 ImpureGlobalVariable { variable: String },
392 ImpureStaticVariable { variable: String },
394 ImpureStaticPropertyAssignment { class: String, property: String },
398 ImpureStaticPropertyAccess { class: String, property: String },
403 ImpureByRefAssignment { variable: String },
408 ImpureFunctionCall { fn_name: String },
412 ImmutablePropertyModification { receiver: String, property: String },
418
419 ReadonlyPropertyAssignment { class: String, property: String },
423 ReadonlyPropertyAlreadyInitialized { class: String, property: String },
430
431 UnimplementedAbstractMethod { class: String, method: String },
435 UnimplementedInterfaceMethod {
438 class: String,
439 interface: String,
440 method: String,
441 },
442 MethodSignatureMismatch {
445 class: String,
446 method: String,
447 detail: String,
448 },
449 OverriddenMethodAccess { class: String, method: String },
452 OverriddenPropertyAccess { class: String, property: String },
455 PropertyTypeRedeclarationMismatch {
458 class: String,
459 property: String,
460 expected: String,
461 actual: String,
462 },
463 ReadonlyPropertyRedeclarationMismatch {
466 parent_class: String,
467 class: String,
468 property: String,
469 parent_readonly: bool,
472 },
473 StaticPropertyRedeclarationMismatch {
476 parent_class: String,
477 class: String,
478 property: String,
479 parent_static: bool,
482 },
483 ReadonlyClassExtendsMismatch {
489 parent: String,
490 child: String,
491 parent_readonly: bool,
494 },
495 InvalidReadonlyPropertyDeclaration { class: String, property: String },
501 BackedEnumCaseTypeMismatch {
504 enum_name: String,
505 case_name: String,
506 expected: String,
507 actual: String,
508 },
509 DirectConstructorCall { class: String },
512 InvalidExtendClass { parent: String, child: String },
515 FinalMethodOverridden {
518 class: String,
519 method: String,
520 parent: String,
521 },
522 AbstractInstantiation { class: String },
525 AbstractMethodCall { class: String, method: String },
528 InterfaceInstantiation { class: String },
531 InvalidOverride {
535 class: String,
536 method: String,
537 detail: String,
538 },
539
540 TaintedInput { sink: String },
544 TaintedHtml,
547 TaintedSql,
550 TaintedShell,
553 TaintedLlmPrompt,
557
558 InvalidTemplateParam {
562 name: String,
563 expected_bound: String,
564 actual: String,
565 },
566 ShadowedTemplateParam { name: String },
569 IfThisIsMismatch {
574 class: String,
575 method: String,
576 expected: String,
577 actual: String,
578 },
579
580 DeprecatedCall {
584 name: String,
585 message: Option<Arc<str>>,
586 },
587 DeprecatedProperty {
590 class: String,
591 property: String,
592 message: Option<Arc<str>>,
593 },
594 DeprecatedConstant {
597 class: String,
598 constant: String,
599 message: Option<Arc<str>>,
600 },
601 DeprecatedInterface {
604 name: String,
605 message: Option<Arc<str>>,
606 },
607 DeprecatedTrait {
610 name: String,
611 message: Option<Arc<str>>,
612 },
613 DeprecatedMethodCall {
616 class: String,
617 method: String,
618 message: Option<Arc<str>>,
619 },
620 DeprecatedMethod {
623 class: String,
624 method: String,
625 message: Option<Arc<str>>,
626 },
627 DeprecatedClass {
630 name: String,
631 message: Option<Arc<str>>,
632 },
633 InternalMethod { class: String, method: String },
636 MissingReturnType { fn_name: String },
639 MissingClosureReturnType,
642 MissingParamType { fn_name: String, param: String },
645 MissingPropertyType { class: String, property: String },
648 InvalidThrow { ty: String },
651 InvalidCatch { ty: String },
654 UnreachableCatch { ty: String, shadowed_by: String },
659 MissingThrowsDocblock { class: String },
662 ImplicitToStringCast { class: String },
665 ImplicitFloatToIntCast { from: String },
668 ParseError { message: String },
671 InvalidDocblock { message: String },
674 MixedArgument { param: String, fn_name: String },
677 MixedAssignment { var: String },
680 MixedMethodCall { method: String },
683 UnsupportedReferenceUsage,
686 NoInterfaceProperties { property: String },
690 UndefinedDocblockClass { name: String },
694 MissingConstructor { class: String },
697 PropertyPossiblyUninitialized { class: String, property: String },
709 MixedFunctionCall,
712 MixedReturnStatement { declared: String },
715 MixedPropertyFetch { property: String },
718 MixedPropertyAssignment { property: String },
721 MixedArrayAccess,
724 MixedArrayOffset,
727 MixedClone,
730 InvalidClone { ty: String },
734 PossiblyInvalidClone { ty: String },
738 InvalidToString { class: String },
742 CircularInheritance { class: String },
745
746 InvalidTraitUse { trait_name: String, reason: String },
750 ForbiddenCode { message: String },
753
754 InvalidAttribute { message: String },
758 UndefinedAttributeClass { name: String },
761
762 WrongCaseFunction { used: String, canonical: String },
766 WrongCaseMethod {
769 class: String,
770 used: String,
771 canonical: String,
772 },
773 WrongCaseClass { used: String, canonical: String },
776 DuplicateClass { name: String },
779 DuplicateInterface { name: String },
782 DuplicateTrait { name: String },
785 DuplicateEnum { name: String },
788 DuplicateFunction { name: String },
791
792 PluginIssue { name: String, message: String },
796}
797
798fn append_deprecation_message(base: String, message: &Option<Arc<str>>) -> String {
799 match message.as_deref().filter(|m| !m.is_empty()) {
800 Some(msg) => format!("{base}: {msg}"),
801 None => base,
802 }
803}
804
805impl IssueKind {
806 pub fn default_severity(&self) -> Severity {
808 match self {
809 IssueKind::NonStaticSelfCall { .. }
811 | IssueKind::DirectConstructorCall { .. }
812 | IssueKind::InvalidScope { .. }
813 | IssueKind::UndefinedVariable { .. }
814 | IssueKind::UndefinedFunction { .. }
815 | IssueKind::UndefinedMethod { .. }
816 | IssueKind::UndefinedClass { .. }
817 | IssueKind::NotAnInterface { .. }
818 | IssueKind::UndefinedConstant { .. }
819 | IssueKind::InaccessibleClassConstant { .. }
820 | IssueKind::InaccessibleProperty { .. }
821 | IssueKind::InvalidReturnType { .. }
822 | IssueKind::InvalidArgument { .. }
823 | IssueKind::TooFewArguments { .. }
824 | IssueKind::TooManyArguments { .. }
825 | IssueKind::InvalidNamedArgument { .. }
826 | IssueKind::InvalidNamedArguments { .. }
827 | IssueKind::InvalidPassByReference { .. }
828 | IssueKind::InvalidThrow { .. }
829 | IssueKind::InvalidCatch { .. }
830 | IssueKind::InvalidStaticInvocation { .. }
831 | IssueKind::UnimplementedAbstractMethod { .. }
832 | IssueKind::UnimplementedInterfaceMethod { .. }
833 | IssueKind::MethodSignatureMismatch { .. }
834 | IssueKind::InvalidExtendClass { .. }
835 | IssueKind::FinalMethodOverridden { .. }
836 | IssueKind::AbstractInstantiation { .. }
837 | IssueKind::AbstractMethodCall { .. }
838 | IssueKind::InterfaceInstantiation { .. }
839 | IssueKind::InvalidOverride { .. }
840 | IssueKind::InvalidTemplateParam { .. }
841 | IssueKind::ReadonlyPropertyAssignment { .. }
842 | IssueKind::ReadonlyPropertyAlreadyInitialized { .. }
843 | IssueKind::ParseError { .. }
844 | IssueKind::TaintedInput { .. }
845 | IssueKind::TaintedHtml
846 | IssueKind::TaintedSql
847 | IssueKind::TaintedShell
848 | IssueKind::TaintedLlmPrompt
849 | IssueKind::CircularInheritance { .. }
850 | IssueKind::InvalidTraitUse { .. }
851 | IssueKind::UndefinedTrait { .. }
852 | IssueKind::TraitConstantAccessedDirectly { .. }
853 | IssueKind::UndefinedTraitAliasMethod { .. }
854 | IssueKind::InvalidClone { .. }
855 | IssueKind::InvalidToString { .. }
856 | IssueKind::TypeCheckMismatch { .. }
857 | IssueKind::PropertyTypeRedeclarationMismatch { .. }
858 | IssueKind::ReadonlyPropertyRedeclarationMismatch { .. }
859 | IssueKind::StaticPropertyRedeclarationMismatch { .. }
860 | IssueKind::ReadonlyClassExtendsMismatch { .. }
861 | IssueKind::InvalidReadonlyPropertyDeclaration { .. }
862 | IssueKind::BackedEnumCaseTypeMismatch { .. }
863 | IssueKind::DivisionByZero { .. }
864 | IssueKind::ParentNotFound => Severity::Error,
865 IssueKind::Trace { .. } => Severity::Info,
866
867 IssueKind::NullArgument { .. }
869 | IssueKind::NullPropertyFetch { .. }
870 | IssueKind::NullMethodCall { .. }
871 | IssueKind::NullArrayAccess
872 | IssueKind::NullableReturnStatement { .. }
873 | IssueKind::InvalidPropertyFetch { .. }
874 | IssueKind::InvalidArrayAccess { .. }
875 | IssueKind::InvalidArrayAssignment { .. }
876 | IssueKind::InvalidPropertyAssignment { .. }
877 | IssueKind::InvalidArrayOffset { .. }
878 | IssueKind::NonExistentArrayOffset { .. }
879 | IssueKind::PossiblyInvalidArrayOffset { .. }
880 | IssueKind::UndefinedProperty { .. }
881 | IssueKind::InvalidOperand { .. }
882 | IssueKind::OverriddenMethodAccess { .. }
883 | IssueKind::OverriddenPropertyAccess { .. }
884 | IssueKind::ImplicitToStringCast { .. }
885 | IssueKind::ImplicitFloatToIntCast { .. }
886 | IssueKind::UnusedVariable { .. }
887 | IssueKind::UnusedForeachValue { .. }
888 | IssueKind::ImpurePropertyAssignment { .. }
889 | IssueKind::ImpureMethodCall { .. }
890 | IssueKind::ImpureGlobalVariable { .. }
891 | IssueKind::ImpureStaticVariable { .. }
892 | IssueKind::ImpureStaticPropertyAssignment { .. }
893 | IssueKind::ImpureStaticPropertyAccess { .. }
894 | IssueKind::ImpureFunctionCall { .. }
895 | IssueKind::ImpureByRefAssignment { .. }
896 | IssueKind::ImmutablePropertyModification { .. }
897 | IssueKind::UnsupportedReferenceUsage
898 | IssueKind::ParadoxicalCondition { .. }
899 | IssueKind::UnhandledMatchCondition { .. }
900 | IssueKind::InvalidStringClass { .. }
901 | IssueKind::ImpossibleIdenticalComparison { .. }
902 | IssueKind::ImpossibleLooseComparison { .. }
903 | IssueKind::DuplicateArrayKey { .. }
904 | IssueKind::ForbiddenCode { .. }
905 | IssueKind::PropertyPossiblyUninitialized { .. } => Severity::Warning,
906
907 IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
909
910 IssueKind::PossiblyNullArgument { .. }
912 | IssueKind::PossiblyInvalidArgument { .. }
913 | IssueKind::PossiblyNullPropertyFetch { .. }
914 | IssueKind::PossiblyNullMethodCall { .. }
915 | IssueKind::PossiblyNullArrayAccess
916 | IssueKind::PossiblyInvalidArrayAccess { .. }
917 | IssueKind::PossiblyInvalidClone { .. }
918 | IssueKind::PossiblyInvalidOperand { .. }
919 | IssueKind::PossiblyNullOperand { .. }
920 | IssueKind::PossiblyRawObjectIteration { .. } => Severity::Info,
921
922 IssueKind::RawObjectIteration { .. } => Severity::Warning,
923
924 IssueKind::RedundantCondition { .. }
926 | IssueKind::RedundantCast { .. }
927 | IssueKind::UnnecessaryVarAnnotation { .. }
928 | IssueKind::TypeDoesNotContainType { .. }
929 | IssueKind::DocblockTypeContradiction { .. }
930 | IssueKind::UnevaluatedCode { .. }
931 | IssueKind::IfThisIsMismatch { .. }
932 | IssueKind::UnusedParam { .. }
933 | IssueKind::UnreachableCode
934 | IssueKind::UnreachableCatch { .. }
935 | IssueKind::UnusedMethod { .. }
936 | IssueKind::UnusedProperty { .. }
937 | IssueKind::UnusedFunction { .. }
938 | IssueKind::UnusedClass { .. }
939 | IssueKind::UnusedSuppress { .. }
940 | IssueKind::ArgumentTypeCoercion { .. }
941 | IssueKind::PropertyTypeCoercion { .. }
942 | IssueKind::DeprecatedCall { .. }
943 | IssueKind::DeprecatedProperty { .. }
944 | IssueKind::DeprecatedConstant { .. }
945 | IssueKind::DeprecatedInterface { .. }
946 | IssueKind::DeprecatedTrait { .. }
947 | IssueKind::DeprecatedMethodCall { .. }
948 | IssueKind::DeprecatedMethod { .. }
949 | IssueKind::DeprecatedClass { .. }
950 | IssueKind::InternalMethod { .. }
951 | IssueKind::MissingReturnType { .. }
952 | IssueKind::MissingClosureReturnType
953 | IssueKind::MissingParamType { .. }
954 | IssueKind::MissingPropertyType { .. }
955 | IssueKind::MismatchingDocblockReturnType { .. }
956 | IssueKind::MismatchingDocblockParamType { .. }
957 | IssueKind::InvalidDocblock { .. }
958 | IssueKind::InvalidCast { .. }
959 | IssueKind::MixedArgument { .. }
960 | IssueKind::MixedAssignment { .. }
961 | IssueKind::MixedMethodCall { .. }
962 | IssueKind::NoInterfaceProperties { .. }
963 | IssueKind::UndefinedDocblockClass { .. }
964 | IssueKind::MissingConstructor { .. }
965 | IssueKind::MixedFunctionCall
966 | IssueKind::MixedReturnStatement { .. }
967 | IssueKind::MixedPropertyFetch { .. }
968 | IssueKind::MixedPropertyAssignment { .. }
969 | IssueKind::MixedArrayAccess
970 | IssueKind::MixedArrayOffset
971 | IssueKind::MixedClone
972 | IssueKind::ShadowedTemplateParam { .. }
973 | IssueKind::MissingThrowsDocblock { .. }
974 | IssueKind::WrongCaseFunction { .. }
975 | IssueKind::WrongCaseMethod { .. }
976 | IssueKind::WrongCaseClass { .. }
977 | IssueKind::InvalidAttribute { .. }
978 | IssueKind::UndefinedAttributeClass { .. } => Severity::Info,
979 IssueKind::DuplicateClass { .. }
980 | IssueKind::DuplicateInterface { .. }
981 | IssueKind::DuplicateTrait { .. }
982 | IssueKind::DuplicateEnum { .. }
983 | IssueKind::DuplicateFunction { .. } => Severity::Error,
984 IssueKind::PluginIssue { .. } => Severity::Error,
987 }
988 }
989
990 pub fn code(&self) -> &'static str {
1020 match self {
1021 IssueKind::NonStaticSelfCall { .. } => "MIR0216",
1023 IssueKind::DirectConstructorCall { .. } => "MIR0217",
1024 IssueKind::InvalidScope { .. } => "MIR0001",
1025 IssueKind::UndefinedVariable { .. } => "MIR0002",
1026 IssueKind::UndefinedFunction { .. } => "MIR0003",
1027 IssueKind::UndefinedMethod { .. } => "MIR0004",
1028 IssueKind::UndefinedClass { .. } => "MIR0005",
1029 IssueKind::UndefinedProperty { .. } => "MIR0006",
1030 IssueKind::UndefinedConstant { .. } => "MIR0007",
1031 IssueKind::InaccessibleClassConstant { .. } => "MIR0011",
1032 IssueKind::InaccessibleProperty { .. } => "MIR0014",
1033 IssueKind::TraitConstantAccessedDirectly { .. } => "MIR0012",
1034 IssueKind::UndefinedTraitAliasMethod { .. } => "MIR0013",
1035 IssueKind::PossiblyUndefinedVariable { .. } => "MIR0008",
1036 IssueKind::UndefinedTrait { .. } => "MIR0009",
1037 IssueKind::ParentNotFound => "MIR0010",
1038
1039 IssueKind::NullArgument { .. } => "MIR0100",
1041 IssueKind::NullPropertyFetch { .. } => "MIR0101",
1042 IssueKind::NullMethodCall { .. } => "MIR0102",
1043 IssueKind::NullArrayAccess => "MIR0103",
1044 IssueKind::PossiblyNullArgument { .. } => "MIR0104",
1045 IssueKind::PossiblyInvalidArgument { .. } => "MIR0105",
1046 IssueKind::PossiblyNullPropertyFetch { .. } => "MIR0106",
1047 IssueKind::PossiblyNullMethodCall { .. } => "MIR0107",
1048 IssueKind::PossiblyNullArrayAccess => "MIR0108",
1049 IssueKind::NullableReturnStatement { .. } => "MIR0109",
1050
1051 IssueKind::InvalidReturnType { .. } => "MIR0200",
1053 IssueKind::InvalidArgument { .. } => "MIR0201",
1054 IssueKind::TooFewArguments { .. } => "MIR0202",
1055 IssueKind::TooManyArguments { .. } => "MIR0203",
1056 IssueKind::InvalidNamedArgument { .. } => "MIR0204",
1057 IssueKind::InvalidNamedArguments { .. } => "MIR0224",
1058 IssueKind::InvalidPassByReference { .. } => "MIR0205",
1059 IssueKind::InvalidPropertyFetch { .. } => "MIR0218",
1060 IssueKind::InvalidArrayAccess { .. } => "MIR0219",
1061 IssueKind::PossiblyInvalidArrayAccess { .. } => "MIR0227",
1062 IssueKind::InvalidArrayAssignment { .. } => "MIR0220",
1063 IssueKind::InvalidPropertyAssignment { .. } => "MIR0206",
1064 IssueKind::InvalidCast { .. } => "MIR0207",
1065 IssueKind::InvalidStaticInvocation { .. } => "MIR0215",
1066 IssueKind::InvalidOperand { .. } => "MIR0208",
1067 IssueKind::PossiblyInvalidOperand { .. } => "MIR0213",
1068 IssueKind::PossiblyNullOperand { .. } => "MIR0214",
1069 IssueKind::DivisionByZero { .. } => "MIR0229",
1070 IssueKind::RawObjectIteration { .. } => "MIR0222",
1071 IssueKind::PossiblyRawObjectIteration { .. } => "MIR0223",
1072 IssueKind::MismatchingDocblockReturnType { .. } => "MIR0209",
1073 IssueKind::MismatchingDocblockParamType { .. } => "MIR0210",
1074 IssueKind::InvalidStringClass { .. } => "MIR0211",
1075 IssueKind::NotAnInterface { .. } => "MIR0228",
1076 IssueKind::TypeCheckMismatch { .. } => "MIR0212",
1077 IssueKind::Trace { .. } => "MIR0221",
1078 IssueKind::ArgumentTypeCoercion { .. } => "MIR0225",
1079 IssueKind::PropertyTypeCoercion { .. } => "MIR0226",
1080
1081 IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1083 IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1084 IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1085 IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1086
1087 IssueKind::RedundantCondition { .. } => "MIR0400",
1089 IssueKind::RedundantCast { .. } => "MIR0401",
1090 IssueKind::UnnecessaryVarAnnotation { .. } => "MIR0402",
1091 IssueKind::TypeDoesNotContainType { .. } => "MIR0403",
1092 IssueKind::ParadoxicalCondition { .. } => "MIR0404",
1093 IssueKind::UnhandledMatchCondition { .. } => "MIR0405",
1094 IssueKind::DocblockTypeContradiction { .. } => "MIR0406",
1095 IssueKind::UnevaluatedCode { .. } => "MIR0407",
1096 IssueKind::ImpossibleIdenticalComparison { .. } => "MIR0408",
1097 IssueKind::ImpossibleLooseComparison { .. } => "MIR0409",
1098
1099 IssueKind::UnusedVariable { .. } => "MIR0500",
1101 IssueKind::UnusedParam { .. } => "MIR0501",
1102 IssueKind::UnreachableCode => "MIR0502",
1103 IssueKind::UnusedMethod { .. } => "MIR0503",
1104 IssueKind::UnusedProperty { .. } => "MIR0504",
1105 IssueKind::UnusedFunction { .. } => "MIR0505",
1106 IssueKind::UnusedForeachValue { .. } => "MIR0506",
1107 IssueKind::UnusedClass { .. } => "MIR0507",
1108 IssueKind::UnusedSuppress { .. } => "MIR0508",
1109
1110 IssueKind::ImpurePropertyAssignment { .. } => "MIR1700",
1112 IssueKind::ImpureMethodCall { .. } => "MIR1701",
1113 IssueKind::ImpureGlobalVariable { .. } => "MIR1702",
1114 IssueKind::ImpureStaticVariable { .. } => "MIR1703",
1115 IssueKind::ImpureStaticPropertyAssignment { .. } => "MIR1706",
1116 IssueKind::ImpureByRefAssignment { .. } => "MIR1707",
1117 IssueKind::ImpureStaticPropertyAccess { .. } => "MIR1708",
1118 IssueKind::ImpureFunctionCall { .. } => "MIR1704",
1119 IssueKind::ImmutablePropertyModification { .. } => "MIR1705",
1120 IssueKind::UnsupportedReferenceUsage => "MIR1506",
1121 IssueKind::NoInterfaceProperties { .. } => "MIR1504",
1122 IssueKind::UndefinedDocblockClass { .. } => "MIR1505",
1123 IssueKind::MissingConstructor { .. } => "MIR1507",
1124 IssueKind::PropertyPossiblyUninitialized { .. } => "MIR1510",
1125 IssueKind::MixedFunctionCall => "MIR1211",
1126 IssueKind::MixedReturnStatement { .. } => "MIR1212",
1127
1128 IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1130 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1131
1132 IssueKind::UnimplementedAbstractMethod { .. } => "MIR0700",
1134 IssueKind::UnimplementedInterfaceMethod { .. } => "MIR0701",
1135 IssueKind::MethodSignatureMismatch { .. } => "MIR0702",
1136 IssueKind::OverriddenMethodAccess { .. } => "MIR0703",
1137 IssueKind::OverriddenPropertyAccess { .. } => "MIR0710",
1138 IssueKind::PropertyTypeRedeclarationMismatch { .. } => "MIR0712",
1139 IssueKind::BackedEnumCaseTypeMismatch { .. } => "MIR0713",
1140 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => "MIR0714",
1141 IssueKind::StaticPropertyRedeclarationMismatch { .. } => "MIR0715",
1142 IssueKind::ReadonlyClassExtendsMismatch { .. } => "MIR0716",
1143 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => "MIR0717",
1144 IssueKind::InvalidExtendClass { .. } => "MIR0704",
1145 IssueKind::FinalMethodOverridden { .. } => "MIR0705",
1146 IssueKind::AbstractInstantiation { .. } => "MIR0706",
1147 IssueKind::AbstractMethodCall { .. } => "MIR0711",
1148 IssueKind::InterfaceInstantiation { .. } => "MIR0709",
1149 IssueKind::CircularInheritance { .. } => "MIR0707",
1150 IssueKind::InvalidOverride { .. } => "MIR0708",
1151
1152 IssueKind::TaintedInput { .. } => "MIR0800",
1154 IssueKind::TaintedHtml => "MIR0801",
1155 IssueKind::TaintedSql => "MIR0802",
1156 IssueKind::TaintedShell => "MIR0803",
1157 IssueKind::TaintedLlmPrompt => "MIR0804",
1158
1159 IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1161 IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1162 IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1163
1164 IssueKind::DeprecatedCall { .. } => "MIR1000",
1166 IssueKind::WrongCaseFunction { .. } => "MIR1009",
1167 IssueKind::WrongCaseMethod { .. } => "MIR1010",
1168 IssueKind::WrongCaseClass { .. } => "MIR1011",
1169 IssueKind::DeprecatedProperty { .. } => "MIR1005",
1170 IssueKind::DeprecatedInterface { .. } => "MIR1006",
1171 IssueKind::DeprecatedTrait { .. } => "MIR1007",
1172 IssueKind::DeprecatedConstant { .. } => "MIR1008",
1173 IssueKind::DeprecatedMethodCall { .. } => "MIR1001",
1174 IssueKind::DeprecatedMethod { .. } => "MIR1002",
1175 IssueKind::DeprecatedClass { .. } => "MIR1003",
1176 IssueKind::InternalMethod { .. } => "MIR1004",
1177
1178 IssueKind::MissingReturnType { .. } => "MIR1100",
1180 IssueKind::MissingParamType { .. } => "MIR1101",
1181 IssueKind::MissingPropertyType { .. } => "MIR1104",
1182 IssueKind::MissingClosureReturnType => "MIR1105",
1183 IssueKind::MissingThrowsDocblock { .. } => "MIR1102",
1184 IssueKind::InvalidDocblock { .. } => "MIR1103",
1185
1186 IssueKind::MixedArgument { .. } => "MIR1200",
1188 IssueKind::MixedAssignment { .. } => "MIR1201",
1189 IssueKind::MixedMethodCall { .. } => "MIR1202",
1190 IssueKind::MixedPropertyFetch { .. } => "MIR1203",
1191 IssueKind::MixedPropertyAssignment { .. } => "MIR1208",
1192 IssueKind::MixedArrayAccess => "MIR1209",
1193 IssueKind::MixedArrayOffset => "MIR1210",
1194 IssueKind::MixedClone => "MIR1204",
1195 IssueKind::InvalidClone { .. } => "MIR1205",
1196 IssueKind::PossiblyInvalidClone { .. } => "MIR1206",
1197 IssueKind::InvalidToString { .. } => "MIR1207",
1198
1199 IssueKind::InvalidTraitUse { .. } => "MIR1300",
1201 IssueKind::ForbiddenCode { .. } => "MIR1301",
1202
1203 IssueKind::ParseError { .. } => "MIR1400",
1205
1206 IssueKind::InvalidAttribute { .. } => "MIR1600",
1208 IssueKind::UndefinedAttributeClass { .. } => "MIR1601",
1209 IssueKind::DuplicateClass { .. } => "MIR1602",
1210 IssueKind::DuplicateInterface { .. } => "MIR1603",
1211 IssueKind::DuplicateTrait { .. } => "MIR1604",
1212 IssueKind::DuplicateEnum { .. } => "MIR1605",
1213 IssueKind::DuplicateFunction { .. } => "MIR1606",
1214
1215 IssueKind::InvalidThrow { .. } => "MIR1500",
1217 IssueKind::InvalidCatch { .. } => "MIR1503",
1218 IssueKind::UnreachableCatch { .. } => "MIR1508",
1219 IssueKind::PluginIssue { .. } => "MIR1509",
1220 IssueKind::ImplicitToStringCast { .. } => "MIR1501",
1221 IssueKind::ImplicitFloatToIntCast { .. } => "MIR1502",
1222 }
1223 }
1224
1225 pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1231 match code {
1232 "MIR0001" | "MIR0002" | "MIR0003" | "MIR0004" | "MIR0005" | "MIR0007" | "MIR0009"
1234 | "MIR0010" | "MIR0011" | "MIR0012" | "MIR0013" | "MIR0014" | "MIR0200" | "MIR0201"
1235 | "MIR0202" | "MIR0203" | "MIR0204" | "MIR0205" | "MIR0212" | "MIR0215" | "MIR0216"
1236 | "MIR0217" | "MIR0224" | "MIR0600" | "MIR0601" | "MIR0700" | "MIR0701" | "MIR0702"
1237 | "MIR0704" | "MIR0705" | "MIR0706" | "MIR0707" | "MIR0708" | "MIR0709" | "MIR0711"
1238 | "MIR0712" | "MIR0713" | "MIR0714" | "MIR0715" | "MIR0716" | "MIR0717" | "MIR0228"
1239 | "MIR0229" | "MIR0800" | "MIR0801" | "MIR0802" | "MIR0803" | "MIR0804" | "MIR0900"
1240 | "MIR1205" | "MIR1207" | "MIR1300" | "MIR1400" | "MIR1500" | "MIR1503" | "MIR1602"
1241 | "MIR1603" | "MIR1604" | "MIR1605" | "MIR1606" => Some(Severity::Error),
1242
1243 "MIR0006" | "MIR0008" | "MIR0100" | "MIR0101" | "MIR0102" | "MIR0103" | "MIR0109"
1245 | "MIR0206" | "MIR0208" | "MIR0211" | "MIR0218" | "MIR0219" | "MIR0220" | "MIR0222"
1246 | "MIR0300" | "MIR0301" | "MIR0302" | "MIR0303" | "MIR0404" | "MIR0405" | "MIR0408"
1247 | "MIR0500" | "MIR0506" | "MIR0703" | "MIR0710" | "MIR1301" | "MIR1501" | "MIR1502"
1248 | "MIR1700" | "MIR1701" | "MIR1702" | "MIR1703" | "MIR1704" | "MIR1705" | "MIR1706"
1249 | "MIR1707" | "MIR1708" | "MIR1506" | "MIR1510" => Some(Severity::Warning),
1250
1251 "MIR0104" | "MIR0105" | "MIR0106" | "MIR0107" | "MIR0108" | "MIR0207" | "MIR0209"
1253 | "MIR0210" | "MIR0213" | "MIR0214" | "MIR0221" | "MIR0223" | "MIR0400" | "MIR0401"
1254 | "MIR0402" | "MIR0403" | "MIR0501" | "MIR0502" | "MIR0503" | "MIR0504" | "MIR0505"
1255 | "MIR0507" | "MIR0508" | "MIR0901" | "MIR1000" | "MIR1001" | "MIR1002" | "MIR1003"
1256 | "MIR1004" | "MIR1005" | "MIR1006" | "MIR1007" | "MIR1008" | "MIR1009" | "MIR1010"
1257 | "MIR1011" | "MIR1100" | "MIR1101" | "MIR1102" | "MIR1103" | "MIR1104" | "MIR1105"
1258 | "MIR1200" | "MIR1201" | "MIR1202" | "MIR1203" | "MIR1204" | "MIR1206" | "MIR1208"
1259 | "MIR1209" | "MIR1210" | "MIR1211" | "MIR1212" | "MIR1504" | "MIR1505" | "MIR1507"
1260 | "MIR1508" | "MIR1600" | "MIR1601" | "MIR0225" | "MIR0226" | "MIR0227" | "MIR0406"
1261 | "MIR0407" | "MIR0902" => Some(Severity::Info),
1262
1263 _ => None,
1264 }
1265 }
1266
1267 pub fn name(&self) -> &'static str {
1269 match self {
1270 IssueKind::NonStaticSelfCall { .. } => "NonStaticSelfCall",
1271 IssueKind::DirectConstructorCall { .. } => "DirectConstructorCall",
1272 IssueKind::InvalidScope { .. } => "InvalidScope",
1273 IssueKind::UndefinedVariable { .. } => "UndefinedVariable",
1274 IssueKind::UndefinedFunction { .. } => "UndefinedFunction",
1275 IssueKind::UndefinedMethod { .. } => "UndefinedMethod",
1276 IssueKind::UndefinedClass { .. } => "UndefinedClass",
1277 IssueKind::UndefinedProperty { .. } => "UndefinedProperty",
1278 IssueKind::UndefinedConstant { .. } => "UndefinedConstant",
1279 IssueKind::InaccessibleClassConstant { .. } => "InaccessibleClassConstant",
1280 IssueKind::InaccessibleProperty { .. } => "InaccessibleProperty",
1281 IssueKind::TraitConstantAccessedDirectly { .. } => "TraitConstantAccessedDirectly",
1282 IssueKind::UndefinedTraitAliasMethod { .. } => "UndefinedTraitAliasMethod",
1283 IssueKind::PossiblyUndefinedVariable { .. } => "PossiblyUndefinedVariable",
1284 IssueKind::UndefinedTrait { .. } => "UndefinedTrait",
1285 IssueKind::ParentNotFound => "ParentNotFound",
1286 IssueKind::InvalidStringClass { .. } => "InvalidStringClass",
1287 IssueKind::NotAnInterface { .. } => "NotAnInterface",
1288 IssueKind::NullArgument { .. } => "NullArgument",
1289 IssueKind::NullPropertyFetch { .. } => "NullPropertyFetch",
1290 IssueKind::NullMethodCall { .. } => "NullMethodCall",
1291 IssueKind::NullArrayAccess => "NullArrayAccess",
1292 IssueKind::PossiblyNullArgument { .. } => "PossiblyNullArgument",
1293 IssueKind::PossiblyInvalidArgument { .. } => "PossiblyInvalidArgument",
1294 IssueKind::PossiblyNullPropertyFetch { .. } => "PossiblyNullPropertyFetch",
1295 IssueKind::PossiblyNullMethodCall { .. } => "PossiblyNullMethodCall",
1296 IssueKind::PossiblyNullArrayAccess => "PossiblyNullArrayAccess",
1297 IssueKind::NullableReturnStatement { .. } => "NullableReturnStatement",
1298 IssueKind::InvalidReturnType { .. } => "InvalidReturnType",
1299 IssueKind::InvalidArgument { .. } => "InvalidArgument",
1300 IssueKind::TooFewArguments { .. } => "TooFewArguments",
1301 IssueKind::TooManyArguments { .. } => "TooManyArguments",
1302 IssueKind::InvalidNamedArgument { .. } => "InvalidNamedArgument",
1303 IssueKind::InvalidNamedArguments { .. } => "InvalidNamedArguments",
1304 IssueKind::InvalidPassByReference { .. } => "InvalidPassByReference",
1305 IssueKind::InvalidPropertyFetch { .. } => "InvalidPropertyFetch",
1306 IssueKind::InvalidArrayAccess { .. } => "InvalidArrayAccess",
1307 IssueKind::PossiblyInvalidArrayAccess { .. } => "PossiblyInvalidArrayAccess",
1308 IssueKind::InvalidArrayAssignment { .. } => "InvalidArrayAssignment",
1309 IssueKind::InvalidPropertyAssignment { .. } => "InvalidPropertyAssignment",
1310 IssueKind::InvalidCast { .. } => "InvalidCast",
1311 IssueKind::InvalidStaticInvocation { .. } => "InvalidStaticInvocation",
1312 IssueKind::InvalidOperand { .. } => "InvalidOperand",
1313 IssueKind::PossiblyInvalidOperand { .. } => "PossiblyInvalidOperand",
1314 IssueKind::PossiblyNullOperand { .. } => "PossiblyNullOperand",
1315 IssueKind::DivisionByZero { .. } => "DivisionByZero",
1316 IssueKind::RawObjectIteration { .. } => "RawObjectIteration",
1317 IssueKind::PossiblyRawObjectIteration { .. } => "PossiblyRawObjectIteration",
1318 IssueKind::MismatchingDocblockReturnType { .. } => "MismatchingDocblockReturnType",
1319 IssueKind::MismatchingDocblockParamType { .. } => "MismatchingDocblockParamType",
1320 IssueKind::TypeCheckMismatch { .. } => "TypeCheckMismatch",
1321 IssueKind::DocblockTypeContradiction { .. } => "DocblockTypeContradiction",
1322 IssueKind::ImpossibleIdenticalComparison { .. } => "ImpossibleIdenticalComparison",
1323 IssueKind::ImpossibleLooseComparison { .. } => "ImpossibleLooseComparison",
1324 IssueKind::UnevaluatedCode { .. } => "UnevaluatedCode",
1325 IssueKind::IfThisIsMismatch { .. } => "IfThisIsMismatch",
1326 IssueKind::Trace { .. } => "Trace",
1327 IssueKind::InvalidArrayOffset { .. } => "InvalidArrayOffset",
1328 IssueKind::NonExistentArrayOffset { .. } => "NonExistentArrayOffset",
1329 IssueKind::PossiblyInvalidArrayOffset { .. } => "PossiblyInvalidArrayOffset",
1330 IssueKind::DuplicateArrayKey { .. } => "DuplicateArrayKey",
1331 IssueKind::RedundantCondition { .. } => "RedundantCondition",
1332 IssueKind::RedundantCast { .. } => "RedundantCast",
1333 IssueKind::UnnecessaryVarAnnotation { .. } => "UnnecessaryVarAnnotation",
1334 IssueKind::TypeDoesNotContainType { .. } => "TypeDoesNotContainType",
1335 IssueKind::ParadoxicalCondition { .. } => "ParadoxicalCondition",
1336 IssueKind::UnhandledMatchCondition { .. } => "UnhandledMatchCondition",
1337 IssueKind::UnusedVariable { .. } => "UnusedVariable",
1338 IssueKind::UnusedParam { .. } => "UnusedParam",
1339 IssueKind::UnreachableCode => "UnreachableCode",
1340 IssueKind::UnusedMethod { .. } => "UnusedMethod",
1341 IssueKind::UnusedProperty { .. } => "UnusedProperty",
1342 IssueKind::UnusedFunction { .. } => "UnusedFunction",
1343 IssueKind::UnusedForeachValue { .. } => "UnusedForeachValue",
1344 IssueKind::UnusedClass { .. } => "UnusedClass",
1345 IssueKind::UnusedSuppress { .. } => "UnusedSuppress",
1346 IssueKind::ArgumentTypeCoercion { .. } => "ArgumentTypeCoercion",
1347 IssueKind::PropertyTypeCoercion { .. } => "PropertyTypeCoercion",
1348 IssueKind::ImpurePropertyAssignment { .. } => "ImpurePropertyAssignment",
1349 IssueKind::ImpureMethodCall { .. } => "ImpureMethodCall",
1350 IssueKind::ImpureGlobalVariable { .. } => "ImpureGlobalVariable",
1351 IssueKind::ImpureStaticVariable { .. } => "ImpureStaticVariable",
1352 IssueKind::ImpureByRefAssignment { .. } => "ImpureByRefAssignment",
1353 IssueKind::ImpureStaticPropertyAssignment { .. } => "ImpureStaticPropertyAssignment",
1354 IssueKind::ImpureStaticPropertyAccess { .. } => "ImpureStaticPropertyAccess",
1355 IssueKind::ImpureFunctionCall { .. } => "ImpureFunctionCall",
1356 IssueKind::ImmutablePropertyModification { .. } => "ImmutablePropertyModification",
1357 IssueKind::UnsupportedReferenceUsage => "UnsupportedReferenceUsage",
1358 IssueKind::NoInterfaceProperties { .. } => "NoInterfaceProperties",
1359 IssueKind::UndefinedDocblockClass { .. } => "UndefinedDocblockClass",
1360 IssueKind::MissingConstructor { .. } => "MissingConstructor",
1361 IssueKind::PropertyPossiblyUninitialized { .. } => "PropertyPossiblyUninitialized",
1362 IssueKind::MixedFunctionCall => "MixedFunctionCall",
1363 IssueKind::MixedReturnStatement { .. } => "MixedReturnStatement",
1364 IssueKind::UnimplementedAbstractMethod { .. } => "UnimplementedAbstractMethod",
1365 IssueKind::UnimplementedInterfaceMethod { .. } => "UnimplementedInterfaceMethod",
1366 IssueKind::MethodSignatureMismatch { .. } => "MethodSignatureMismatch",
1367 IssueKind::OverriddenMethodAccess { .. } => "OverriddenMethodAccess",
1368 IssueKind::OverriddenPropertyAccess { .. } => "OverriddenPropertyAccess",
1369 IssueKind::PropertyTypeRedeclarationMismatch { .. } => {
1370 "PropertyTypeRedeclarationMismatch"
1371 }
1372 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => {
1373 "ReadonlyPropertyRedeclarationMismatch"
1374 }
1375 IssueKind::StaticPropertyRedeclarationMismatch { .. } => {
1376 "StaticPropertyRedeclarationMismatch"
1377 }
1378 IssueKind::ReadonlyClassExtendsMismatch { .. } => "ReadonlyClassExtendsMismatch",
1379 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => {
1380 "InvalidReadonlyPropertyDeclaration"
1381 }
1382 IssueKind::BackedEnumCaseTypeMismatch { .. } => "BackedEnumCaseTypeMismatch",
1383 IssueKind::InvalidExtendClass { .. } => "InvalidExtendClass",
1384 IssueKind::FinalMethodOverridden { .. } => "FinalMethodOverridden",
1385 IssueKind::AbstractInstantiation { .. } => "AbstractInstantiation",
1386 IssueKind::AbstractMethodCall { .. } => "AbstractMethodCall",
1387 IssueKind::InterfaceInstantiation { .. } => "InterfaceInstantiation",
1388 IssueKind::InvalidOverride { .. } => "InvalidOverride",
1389 IssueKind::ReadonlyPropertyAssignment { .. } => "ReadonlyPropertyAssignment",
1390 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => {
1391 "ReadonlyPropertyAlreadyInitialized"
1392 }
1393 IssueKind::InvalidTemplateParam { .. } => "InvalidTemplateParam",
1394 IssueKind::ShadowedTemplateParam { .. } => "ShadowedTemplateParam",
1395 IssueKind::TaintedInput { .. } => "TaintedInput",
1396 IssueKind::TaintedHtml => "TaintedHtml",
1397 IssueKind::TaintedSql => "TaintedSql",
1398 IssueKind::TaintedShell => "TaintedShell",
1399 IssueKind::TaintedLlmPrompt => "TaintedLlmPrompt",
1400 IssueKind::DeprecatedCall { .. } => "DeprecatedCall",
1401 IssueKind::DeprecatedProperty { .. } => "DeprecatedProperty",
1402 IssueKind::DeprecatedConstant { .. } => "DeprecatedConstant",
1403 IssueKind::DeprecatedInterface { .. } => "DeprecatedInterface",
1404 IssueKind::DeprecatedTrait { .. } => "DeprecatedTrait",
1405 IssueKind::DeprecatedMethodCall { .. } => "DeprecatedMethodCall",
1406 IssueKind::DeprecatedMethod { .. } => "DeprecatedMethod",
1407 IssueKind::DeprecatedClass { .. } => "DeprecatedClass",
1408 IssueKind::InternalMethod { .. } => "InternalMethod",
1409 IssueKind::MissingReturnType { .. } => "MissingReturnType",
1410 IssueKind::MissingClosureReturnType => "MissingClosureReturnType",
1411 IssueKind::MissingParamType { .. } => "MissingParamType",
1412 IssueKind::MissingPropertyType { .. } => "MissingPropertyType",
1413 IssueKind::InvalidThrow { .. } => "InvalidThrow",
1414 IssueKind::InvalidCatch { .. } => "InvalidCatch",
1415 IssueKind::UnreachableCatch { .. } => "UnreachableCatch",
1416 IssueKind::MissingThrowsDocblock { .. } => "MissingThrowsDocblock",
1417 IssueKind::ImplicitToStringCast { .. } => "ImplicitToStringCast",
1418 IssueKind::ImplicitFloatToIntCast { .. } => "ImplicitFloatToIntCast",
1419 IssueKind::ParseError { .. } => "ParseError",
1420 IssueKind::InvalidDocblock { .. } => "InvalidDocblock",
1421 IssueKind::MixedArgument { .. } => "MixedArgument",
1422 IssueKind::MixedAssignment { .. } => "MixedAssignment",
1423 IssueKind::MixedMethodCall { .. } => "MixedMethodCall",
1424 IssueKind::MixedPropertyFetch { .. } => "MixedPropertyFetch",
1425 IssueKind::MixedPropertyAssignment { .. } => "MixedPropertyAssignment",
1426 IssueKind::MixedArrayAccess => "MixedArrayAccess",
1427 IssueKind::MixedArrayOffset => "MixedArrayOffset",
1428 IssueKind::MixedClone => "MixedClone",
1429 IssueKind::InvalidClone { .. } => "InvalidClone",
1430 IssueKind::PossiblyInvalidClone { .. } => "PossiblyInvalidClone",
1431 IssueKind::InvalidToString { .. } => "InvalidToString",
1432 IssueKind::CircularInheritance { .. } => "CircularInheritance",
1433 IssueKind::InvalidTraitUse { .. } => "InvalidTraitUse",
1434 IssueKind::ForbiddenCode { .. } => "ForbiddenCode",
1435 IssueKind::WrongCaseFunction { .. } => "WrongCaseFunction",
1436 IssueKind::WrongCaseMethod { .. } => "WrongCaseMethod",
1437 IssueKind::WrongCaseClass { .. } => "WrongCaseClass",
1438 IssueKind::InvalidAttribute { .. } => "InvalidAttribute",
1439 IssueKind::UndefinedAttributeClass { .. } => "UndefinedAttributeClass",
1440 IssueKind::DuplicateClass { .. } => "DuplicateClass",
1441 IssueKind::DuplicateInterface { .. } => "DuplicateInterface",
1442 IssueKind::DuplicateTrait { .. } => "DuplicateTrait",
1443 IssueKind::DuplicateEnum { .. } => "DuplicateEnum",
1444 IssueKind::DuplicateFunction { .. } => "DuplicateFunction",
1445 IssueKind::PluginIssue { .. } => "PluginIssue",
1446 }
1447 }
1448
1449 pub fn display_name(&self) -> &str {
1453 match self {
1454 IssueKind::PluginIssue { name, .. } => name,
1455 other => other.name(),
1456 }
1457 }
1458
1459 pub fn message(&self) -> String {
1461 match self {
1462 IssueKind::NonStaticSelfCall { class, method } => {
1463 format!("Non-static method {class}::{method}() cannot be called statically")
1464 }
1465 IssueKind::DirectConstructorCall { class } => {
1466 format!("Cannot call constructor of {class} directly")
1467 }
1468 IssueKind::InvalidScope { in_class } => {
1469 if *in_class {
1470 "$this cannot be used in a static method".to_string()
1471 } else {
1472 "$this cannot be used outside of a class".to_string()
1473 }
1474 }
1475 IssueKind::UndefinedVariable { name } => format!("Variable ${name} is not defined"),
1476 IssueKind::UndefinedFunction { name } => format!("Function {name}() is not defined"),
1477 IssueKind::UndefinedMethod { class, method } => {
1478 format!("Method {class}::{method}() does not exist")
1479 }
1480 IssueKind::UndefinedClass { name } => format!("Class {name} does not exist"),
1481 IssueKind::UndefinedProperty { class, property } => {
1482 format!("Property {class}::${property} does not exist")
1483 }
1484 IssueKind::UndefinedConstant { name } => format!("Constant {name} is not defined"),
1485 IssueKind::InaccessibleClassConstant { class, constant } => {
1486 format!("Cannot access constant {class}::{constant}")
1487 }
1488 IssueKind::InaccessibleProperty { class, property } => {
1489 format!("Cannot access property {class}::${property}")
1490 }
1491 IssueKind::PossiblyUndefinedVariable { name } => {
1492 format!("Variable ${name} might not be defined")
1493 }
1494 IssueKind::UndefinedTrait { name } => format!("Trait {name} does not exist"),
1495 IssueKind::TraitConstantAccessedDirectly {
1496 trait_name,
1497 constant,
1498 } => {
1499 format!("Cannot access trait constant {trait_name}::{constant} directly")
1500 }
1501 IssueKind::UndefinedTraitAliasMethod { trait_name, method } => match trait_name {
1502 Some(t) => {
1503 format!("An alias was defined for {t}::{method} but this method does not exist")
1504 }
1505 None => format!("An alias was defined for {method} but this method does not exist"),
1506 },
1507 IssueKind::ParentNotFound => {
1508 "Cannot use parent:: when current class has no parent".to_string()
1509 }
1510 IssueKind::InvalidStringClass { actual } => {
1511 format!("Dynamic class instantiation requires string or class-string type, got '{actual}'")
1512 }
1513 IssueKind::NotAnInterface { name } => {
1514 format!("{name} is not an interface")
1515 }
1516
1517 IssueKind::NullArgument { param, fn_name } => {
1518 format!("Argument ${param} of {fn_name}() cannot be null")
1519 }
1520 IssueKind::NullPropertyFetch { property } => {
1521 format!("Cannot access property ${property} on null")
1522 }
1523 IssueKind::NullMethodCall { method } => {
1524 format!("Cannot call method {method}() on null")
1525 }
1526 IssueKind::NullArrayAccess => "Cannot access array on null".to_string(),
1527 IssueKind::PossiblyNullArgument { param, fn_name } => {
1528 format!("Argument ${param} of {fn_name}() might be null")
1529 }
1530 IssueKind::PossiblyInvalidArgument {
1531 param,
1532 fn_name,
1533 expected,
1534 actual,
1535 } => {
1536 format!("Argument ${param} of {fn_name}() expects '{expected}', possibly different type '{actual}' provided")
1537 }
1538 IssueKind::PossiblyNullPropertyFetch { property } => {
1539 format!("Cannot access property ${property} on possibly null value")
1540 }
1541 IssueKind::PossiblyNullMethodCall { method } => {
1542 format!("Cannot call method {method}() on possibly null value")
1543 }
1544 IssueKind::PossiblyNullArrayAccess => {
1545 "Cannot access array on possibly null value".to_string()
1546 }
1547 IssueKind::NullableReturnStatement { expected, actual } => {
1548 format!("Return type '{actual}' is not compatible with declared '{expected}'")
1549 }
1550
1551 IssueKind::InvalidReturnType { expected, actual } => {
1552 format!("Return type '{actual}' is not compatible with declared '{expected}'")
1553 }
1554 IssueKind::InvalidArgument {
1555 param,
1556 fn_name,
1557 expected,
1558 actual,
1559 } => {
1560 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}'")
1561 }
1562 IssueKind::TooFewArguments {
1563 fn_name,
1564 expected,
1565 actual,
1566 } => {
1567 format!(
1568 "Too few arguments for {}(): expected {}, got {}",
1569 fn_name, expected, actual
1570 )
1571 }
1572 IssueKind::TooManyArguments {
1573 fn_name,
1574 expected,
1575 actual,
1576 } => {
1577 format!(
1578 "Too many arguments for {}(): expected {}, got {}",
1579 fn_name, expected, actual
1580 )
1581 }
1582 IssueKind::InvalidNamedArgument { fn_name, name } => {
1583 format!("{}() has no parameter named ${}", fn_name, name)
1584 }
1585 IssueKind::InvalidNamedArguments { fn_name } => {
1586 format!("{}() does not accept named arguments", fn_name)
1587 }
1588 IssueKind::InvalidPassByReference { fn_name, param } => {
1589 format!(
1590 "Argument ${} of {}() must be passed by reference",
1591 param, fn_name
1592 )
1593 }
1594 IssueKind::InvalidPropertyFetch { ty } => {
1595 format!("Cannot fetch property on non-object type '{ty}'")
1596 }
1597 IssueKind::InvalidArrayAccess { ty } => {
1598 format!("Cannot use [] operator on non-array type '{ty}'")
1599 }
1600 IssueKind::PossiblyInvalidArrayAccess { ty } => {
1601 format!("Possibly invalid array access: '{ty}' might not support []")
1602 }
1603 IssueKind::InvalidArrayAssignment { ty } => {
1604 format!("Cannot use [] assignment on non-array type '{ty}'")
1605 }
1606 IssueKind::InvalidPropertyAssignment {
1607 property,
1608 expected,
1609 actual,
1610 } => {
1611 format!("Property ${property} expects '{expected}', cannot assign '{actual}'")
1612 }
1613 IssueKind::InvalidCast { from, to } => {
1614 format!("Cannot cast '{from}' to '{to}'")
1615 }
1616 IssueKind::InvalidStaticInvocation { class, method } => {
1617 format!("Non-static method {class}::{method}() cannot be called statically")
1618 }
1619 IssueKind::InvalidOperand { op, left, right } => {
1620 if right.is_empty() {
1621 format!("Operator '{op}' not supported for operand of type '{left}'")
1622 } else {
1623 format!("Operator '{op}' not supported between '{left}' and '{right}'")
1624 }
1625 }
1626 IssueKind::PossiblyInvalidOperand { op, left, right } => {
1627 format!("Operator '{op}' might not be supported between '{left}' and '{right}'")
1628 }
1629 IssueKind::PossiblyNullOperand { op, ty } => {
1630 format!("Operator '{op}' operand '{ty}' might be null")
1631 }
1632 IssueKind::DivisionByZero { op } => {
1633 format!("Division by zero: right operand of '{op}' is always 0")
1634 }
1635 IssueKind::RawObjectIteration { ty } => {
1636 format!("Cannot iterate over non-iterable object '{ty}'")
1637 }
1638 IssueKind::PossiblyRawObjectIteration { ty } => {
1639 format!("Cannot iterate over possibly non-iterable object '{ty}'")
1640 }
1641 IssueKind::MismatchingDocblockReturnType { declared, inferred } => {
1642 format!("Docblock return type '{declared}' does not match inferred '{inferred}'")
1643 }
1644 IssueKind::MismatchingDocblockParamType {
1645 param,
1646 declared,
1647 inferred,
1648 } => {
1649 format!(
1650 "Docblock type '{declared}' for ${param} does not match inferred '{inferred}'"
1651 )
1652 }
1653 IssueKind::TypeCheckMismatch {
1654 var,
1655 expected,
1656 actual,
1657 } => {
1658 format!("Type of {var} is expected to be {expected}, got {actual}")
1659 }
1660 IssueKind::Trace {
1661 variable,
1662 type_info,
1663 } => {
1664 format!("Type of ${variable} is {type_info}")
1665 }
1666
1667 IssueKind::InvalidArrayOffset { expected, actual } => {
1668 format!("Array offset expects '{expected}', got '{actual}'")
1669 }
1670 IssueKind::NonExistentArrayOffset { key } => {
1671 format!("Array offset '{key}' does not exist")
1672 }
1673 IssueKind::PossiblyInvalidArrayOffset { expected, actual } => {
1674 format!("Array offset might be invalid: expects '{expected}', got '{actual}'")
1675 }
1676 IssueKind::DuplicateArrayKey { key } => {
1677 format!("Array key {key} is duplicated — the earlier entry is silently overwritten")
1678 }
1679
1680 IssueKind::RedundantCondition { ty } => {
1681 format!("Condition is always true/false for type '{ty}'")
1682 }
1683 IssueKind::RedundantCast { from, to } => {
1684 format!("Casting '{from}' to '{to}' is redundant")
1685 }
1686 IssueKind::UnnecessaryVarAnnotation { var } => {
1687 format!("@var annotation for ${var} is unnecessary")
1688 }
1689 IssueKind::TypeDoesNotContainType { left, right } => {
1690 format!("Type '{left}' can never contain type '{right}'")
1691 }
1692 IssueKind::ParadoxicalCondition { value } => {
1693 format!("Value {value} is duplicated; this branch can never be reached")
1694 }
1695 IssueKind::UnhandledMatchCondition { detail } => {
1696 format!("Unhandled match condition: {detail}")
1697 }
1698 IssueKind::DocblockTypeContradiction { expr, declared } => {
1699 format!("Type '{declared}' makes '{expr}' impossible — this can never hold")
1700 }
1701 IssueKind::ImpossibleIdenticalComparison { op, left, right } => {
1702 let result = if op == "===" { "false" } else { "true" };
1703 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be identical")
1704 }
1705 IssueKind::ImpossibleLooseComparison { op, left, right } => {
1706 let result = if op == "==" { "false" } else { "true" };
1707 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be loosely equal")
1708 }
1709 IssueKind::UnevaluatedCode { reason } => {
1710 format!("Unevaluated code: {reason}")
1711 }
1712 IssueKind::IfThisIsMismatch {
1713 class,
1714 method,
1715 expected,
1716 actual,
1717 } => {
1718 format!(
1719 "Cannot call {class}::{method}() — @if-this-is requires $this to be '{expected}', but it is '{actual}'"
1720 )
1721 }
1722
1723 IssueKind::UnusedVariable { name } => format!("Variable ${name} is never read"),
1724 IssueKind::UnusedParam { name } => format!("Parameter ${name} is never used"),
1725 IssueKind::UnreachableCode => "Unreachable code detected".to_string(),
1726 IssueKind::UnusedMethod { class, method } => {
1727 format!("Private method {class}::{method}() is never called")
1728 }
1729 IssueKind::UnusedProperty { class, property } => {
1730 format!("Private property {class}::${property} is never read")
1731 }
1732 IssueKind::UnusedFunction { name } => {
1733 format!("Function {name}() is never called")
1734 }
1735 IssueKind::UnusedForeachValue { name } => {
1736 format!("Foreach value ${name} is never read")
1737 }
1738 IssueKind::UnusedClass { class } => {
1739 format!("Class {class} is never referenced")
1740 }
1741 IssueKind::UnusedSuppress { kind } => {
1742 format!("Suppress annotation for '{kind}' is never used")
1743 }
1744 IssueKind::ArgumentTypeCoercion {
1745 param,
1746 fn_name,
1747 expected,
1748 actual,
1749 } => {
1750 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}' — coercion may fail at runtime")
1751 }
1752 IssueKind::PropertyTypeCoercion {
1753 property,
1754 expected,
1755 actual,
1756 } => {
1757 format!("Property ${property} expects '{expected}', cannot assign '{actual}' — coercion may fail at runtime")
1758 }
1759 IssueKind::ImpurePropertyAssignment { property } => {
1760 format!("Assigning to property {property} of a parameter in a pure or external-mutation-free context")
1761 }
1762 IssueKind::ImpureMethodCall { method } => {
1763 format!("Calling impure method {method}() in a pure or immutable context")
1764 }
1765 IssueKind::ImpureGlobalVariable { variable } => {
1766 format!("Using global variable ${variable} in a @pure function")
1767 }
1768 IssueKind::ImpureStaticVariable { variable } => {
1769 format!("Using static variable ${variable} in a @pure function")
1770 }
1771 IssueKind::ImpureByRefAssignment { variable } => {
1772 format!("Assigning to by-reference parameter ${variable} in a @pure function")
1773 }
1774 IssueKind::ImpureStaticPropertyAssignment { class, property } => {
1775 format!("Assigning to static property {class}::${property} in a @pure function")
1776 }
1777 IssueKind::ImpureStaticPropertyAccess { class, property } => {
1778 format!("Reading static property {class}::${property} in a @pure function")
1779 }
1780 IssueKind::ImpureFunctionCall { fn_name } => {
1781 format!("Calling impure function {fn_name}() in a @pure function")
1782 }
1783 IssueKind::ImmutablePropertyModification { receiver, property } => {
1784 format!("Assigning to property {property} of {receiver} in an immutable context (@psalm-immutable class or @psalm-mutation-free method)")
1785 }
1786
1787 IssueKind::UnimplementedAbstractMethod { class, method } => {
1788 format!("Class {class} must implement abstract method {method}()")
1789 }
1790 IssueKind::UnimplementedInterfaceMethod {
1791 class,
1792 interface,
1793 method,
1794 } => {
1795 format!("Class {class} must implement {interface}::{method}() from interface")
1796 }
1797 IssueKind::MethodSignatureMismatch {
1798 class,
1799 method,
1800 detail,
1801 } => {
1802 format!("Method {class}::{method}() signature mismatch: {detail}")
1803 }
1804 IssueKind::OverriddenMethodAccess { class, method } => {
1805 format!("Method {class}::{method}() overrides with less visibility")
1806 }
1807 IssueKind::OverriddenPropertyAccess { class, property } => {
1808 format!("Property {class}::${property} overrides with less visibility")
1809 }
1810 IssueKind::PropertyTypeRedeclarationMismatch {
1811 class,
1812 property,
1813 expected,
1814 actual,
1815 } => {
1816 format!(
1817 "Type of {class}::${property} must be {expected} (as in parent class), {actual} given"
1818 )
1819 }
1820 IssueKind::ReadonlyPropertyRedeclarationMismatch {
1821 parent_class,
1822 class,
1823 property,
1824 parent_readonly,
1825 } => {
1826 if *parent_readonly {
1827 format!(
1828 "Cannot redeclare readonly property {parent_class}::${property} as non-readonly {class}::${property}"
1829 )
1830 } else {
1831 format!(
1832 "Cannot redeclare non-readonly property {parent_class}::${property} as readonly {class}::${property}"
1833 )
1834 }
1835 }
1836 IssueKind::StaticPropertyRedeclarationMismatch {
1837 parent_class,
1838 class,
1839 property,
1840 parent_static,
1841 } => {
1842 if *parent_static {
1843 format!(
1844 "Cannot redeclare static property {parent_class}::${property} as non-static {class}::${property}"
1845 )
1846 } else {
1847 format!(
1848 "Cannot redeclare non-static property {parent_class}::${property} as static {class}::${property}"
1849 )
1850 }
1851 }
1852 IssueKind::BackedEnumCaseTypeMismatch {
1853 enum_name,
1854 case_name,
1855 expected,
1856 actual,
1857 } => {
1858 format!(
1859 "Backed enum case {enum_name}::{case_name} has value of type {actual}, but backing type is {expected}"
1860 )
1861 }
1862 IssueKind::ReadonlyClassExtendsMismatch {
1863 parent,
1864 child,
1865 parent_readonly,
1866 } => {
1867 if *parent_readonly {
1868 format!("Non-readonly class {child} cannot extend readonly class {parent}")
1869 } else {
1870 format!("Readonly class {child} cannot extend non-readonly class {parent}")
1871 }
1872 }
1873 IssueKind::InvalidReadonlyPropertyDeclaration { class, property } => {
1874 format!("Readonly property {class}::${property} cannot have a default value")
1875 }
1876 IssueKind::ReadonlyPropertyAssignment { class, property } => {
1877 format!(
1878 "Cannot assign to readonly property {class}::${property} outside of constructor"
1879 )
1880 }
1881 IssueKind::ReadonlyPropertyAlreadyInitialized { class, property } => {
1882 format!(
1883 "Cannot modify readonly property {class}::${property} — already initialized"
1884 )
1885 }
1886 IssueKind::InvalidExtendClass { parent, child } => {
1887 format!("Class {child} cannot extend final class {parent}")
1888 }
1889 IssueKind::InvalidTemplateParam {
1890 name,
1891 expected_bound,
1892 actual,
1893 } => {
1894 format!(
1895 "Template type '{name}' inferred as '{actual}' does not satisfy bound '{expected_bound}'"
1896 )
1897 }
1898 IssueKind::ShadowedTemplateParam { name } => {
1899 format!(
1900 "Method template parameter '{name}' shadows class-level template parameter with the same name"
1901 )
1902 }
1903 IssueKind::FinalMethodOverridden {
1904 class,
1905 method,
1906 parent,
1907 } => {
1908 format!("Method {class}::{method}() cannot override final method from {parent}")
1909 }
1910 IssueKind::AbstractInstantiation { class } => {
1911 format!("Cannot instantiate abstract class {class}")
1912 }
1913 IssueKind::AbstractMethodCall { class, method } => {
1914 format!("Cannot call abstract method {class}::{method}()")
1915 }
1916 IssueKind::InterfaceInstantiation { class } => {
1917 format!("Cannot instantiate interface {class}")
1918 }
1919 IssueKind::InvalidOverride {
1920 class,
1921 method,
1922 detail,
1923 } => {
1924 format!("Method {class}::{method}() has #[Override] but {detail}")
1925 }
1926
1927 IssueKind::TaintedInput { sink } => format!("Tainted input reaching sink '{sink}'"),
1928 IssueKind::TaintedHtml => "Tainted HTML output — possible XSS".to_string(),
1929 IssueKind::TaintedSql => "Tainted SQL query — possible SQL injection".to_string(),
1930 IssueKind::TaintedShell => {
1931 "Tainted shell command — possible command injection".to_string()
1932 }
1933 IssueKind::TaintedLlmPrompt => {
1934 "Tainted LLM prompt — possible prompt injection".to_string()
1935 }
1936
1937 IssueKind::DeprecatedCall { name, message } => {
1938 let base = format!("Call to deprecated function {name}");
1939 append_deprecation_message(base, message)
1940 }
1941 IssueKind::DeprecatedProperty {
1942 class,
1943 property,
1944 message,
1945 } => {
1946 let base = format!("Property {class}::${property} is deprecated");
1947 append_deprecation_message(base, message)
1948 }
1949 IssueKind::DeprecatedConstant {
1950 class,
1951 constant,
1952 message,
1953 } => {
1954 let base = format!("Constant {class}::{constant} is deprecated");
1955 append_deprecation_message(base, message)
1956 }
1957 IssueKind::DeprecatedInterface { name, message } => {
1958 let base = format!("Interface {name} is deprecated");
1959 append_deprecation_message(base, message)
1960 }
1961 IssueKind::DeprecatedTrait { name, message } => {
1962 let base = format!("Trait {name} is deprecated");
1963 append_deprecation_message(base, message)
1964 }
1965 IssueKind::DeprecatedMethodCall {
1966 class,
1967 method,
1968 message,
1969 } => {
1970 let base = format!("Call to deprecated method {class}::{method}");
1971 append_deprecation_message(base, message)
1972 }
1973 IssueKind::DeprecatedMethod {
1974 class,
1975 method,
1976 message,
1977 } => {
1978 let base = format!("Method {class}::{method}() is deprecated");
1979 append_deprecation_message(base, message)
1980 }
1981 IssueKind::DeprecatedClass { name, message } => {
1982 let base = format!("Class {name} is deprecated");
1983 append_deprecation_message(base, message)
1984 }
1985 IssueKind::InternalMethod { class, method } => {
1986 format!("Method {class}::{method}() is marked @internal")
1987 }
1988 IssueKind::MissingReturnType { fn_name } => {
1989 format!("Function {fn_name}() has no return type annotation")
1990 }
1991 IssueKind::MissingClosureReturnType => {
1992 "Closure has no return type annotation".to_string()
1993 }
1994 IssueKind::MissingParamType { fn_name, param } => {
1995 format!("Parameter ${param} of {fn_name}() has no type annotation")
1996 }
1997 IssueKind::MissingPropertyType { class, property } => {
1998 format!("Property {class}::${property} has no type annotation")
1999 }
2000 IssueKind::InvalidThrow { ty } => {
2001 format!("Thrown type '{ty}' does not extend Throwable")
2002 }
2003 IssueKind::InvalidCatch { ty } => {
2004 format!("Caught type '{ty}' does not extend Throwable")
2005 }
2006 IssueKind::UnreachableCatch { ty, shadowed_by } => {
2007 format!("Catch block for '{ty}' is unreachable — already caught by '{shadowed_by}'")
2008 }
2009 IssueKind::MissingThrowsDocblock { class } => {
2010 format!("Exception {class} is thrown but not declared in @throws")
2011 }
2012 IssueKind::ImplicitToStringCast { class } => {
2013 format!("Class {class} is implicitly cast to string")
2014 }
2015 IssueKind::ImplicitFloatToIntCast { from } => {
2016 format!("Implicit cast from {from} to int truncates the fractional part")
2017 }
2018 IssueKind::ParseError { message } => format!("Parse error: {message}"),
2019 IssueKind::InvalidDocblock { message } => format!("Invalid docblock: {message}"),
2020 IssueKind::MixedArgument { param, fn_name } => {
2021 format!("Argument ${param} of {fn_name}() is mixed")
2022 }
2023 IssueKind::MixedAssignment { var } => {
2024 format!("Variable ${var} is assigned a mixed type")
2025 }
2026 IssueKind::MixedMethodCall { method } => {
2027 format!("Method {method}() called on mixed type")
2028 }
2029 IssueKind::UnsupportedReferenceUsage => {
2030 "Reference assignment is not supported".to_string()
2031 }
2032 IssueKind::NoInterfaceProperties { property } => {
2033 format!("Property ${property} is not defined on this interface")
2034 }
2035 IssueKind::UndefinedDocblockClass { name } => {
2036 format!("Docblock type '{name}' does not exist")
2037 }
2038 IssueKind::MissingConstructor { class } => {
2039 format!("Class {class} has uninitialized properties but no constructor")
2040 }
2041 IssueKind::PropertyPossiblyUninitialized { class, property } => {
2042 format!(
2043 "Property {class}::${property} may be left uninitialized by the constructor"
2044 )
2045 }
2046 IssueKind::MixedFunctionCall => "Cannot call mixed type as a function".to_string(),
2047 IssueKind::MixedReturnStatement { declared } => {
2048 format!("Cannot return a mixed type from function with declared return type '{declared}'")
2049 }
2050 IssueKind::MixedPropertyFetch { property } => {
2051 format!("Property ${property} fetched on mixed type")
2052 }
2053 IssueKind::MixedPropertyAssignment { property } => {
2054 format!("Property ${property} assigned on mixed type")
2055 }
2056 IssueKind::MixedArrayAccess => "Array access on mixed type".to_string(),
2057 IssueKind::MixedArrayOffset => "Mixed type used as array offset".to_string(),
2058 IssueKind::MixedClone => "cannot clone mixed".to_string(),
2059 IssueKind::InvalidClone { ty } => format!("cannot clone non-object {ty}"),
2060 IssueKind::PossiblyInvalidClone { ty } => {
2061 format!("cannot clone possibly non-object {ty}")
2062 }
2063 IssueKind::InvalidToString { class } => {
2064 format!("Method {class}::__toString() must return a string")
2065 }
2066 IssueKind::CircularInheritance { class } => {
2067 format!("Class {class} has a circular inheritance chain")
2068 }
2069 IssueKind::InvalidTraitUse { trait_name, reason } => {
2070 format!("Trait {trait_name} used incorrectly: {reason}")
2071 }
2072 IssueKind::WrongCaseFunction { used, canonical } => {
2073 format!("Function name '{used}' has incorrect casing; use '{canonical}'")
2074 }
2075 IssueKind::WrongCaseMethod {
2076 class,
2077 used,
2078 canonical,
2079 } => {
2080 format!("Method name '{class}::{used}' has incorrect casing; use '{canonical}'")
2081 }
2082 IssueKind::WrongCaseClass { used, canonical } => {
2083 format!("Class name '{used}' has incorrect casing; use '{canonical}'")
2084 }
2085 IssueKind::InvalidAttribute { message } => message.clone(),
2086 IssueKind::UndefinedAttributeClass { name } => {
2087 format!("Attribute class {name} does not exist")
2088 }
2089 IssueKind::ForbiddenCode { message } => message.clone(),
2090 IssueKind::DuplicateClass { name } => {
2091 format!("Class {name} has already been defined")
2092 }
2093 IssueKind::DuplicateInterface { name } => {
2094 format!("Interface {name} has already been defined")
2095 }
2096 IssueKind::DuplicateTrait { name } => {
2097 format!("Trait {name} has already been defined")
2098 }
2099 IssueKind::DuplicateEnum { name } => {
2100 format!("Enum {name} has already been defined")
2101 }
2102 IssueKind::DuplicateFunction { name } => {
2103 format!("Function {name}() has already been defined")
2104 }
2105 IssueKind::PluginIssue { message, .. } => message.clone(),
2106 }
2107 }
2108}
2109
2110#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2115pub struct Issue {
2116 pub kind: IssueKind,
2117 pub severity: Severity,
2118 pub location: Location,
2119 pub snippet: Option<String>,
2120 pub suppressed: bool,
2121}
2122
2123impl Issue {
2124 pub fn new(kind: IssueKind, location: Location) -> Self {
2125 let severity = kind.default_severity();
2126 Self {
2127 severity,
2128 kind,
2129 location,
2130 snippet: None,
2131 suppressed: false,
2132 }
2133 }
2134
2135 pub fn with_snippet(mut self, snippet: impl Into<String>) -> Self {
2136 self.snippet = Some(snippet.into());
2137 self
2138 }
2139
2140 pub fn suppress(mut self) -> Self {
2141 self.suppressed = true;
2142 self
2143 }
2144}
2145
2146#[derive(Debug, Default)]
2151pub struct IssueBuffer {
2152 issues: Vec<Issue>,
2153 seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
2154 file_suppressions: Vec<String>,
2156}
2157
2158impl IssueBuffer {
2159 pub fn new() -> Self {
2160 Self::default()
2161 }
2162
2163 pub fn add(&mut self, issue: Issue) {
2164 let key = (
2165 issue.kind.name(),
2166 issue.location.file.clone(),
2167 issue.location.line,
2168 issue.location.col_start,
2169 );
2170 if self.seen.insert(key) {
2171 self.issues.push(issue);
2172 }
2173 }
2174
2175 pub fn add_suppression(&mut self, name: impl Into<String>) {
2176 self.file_suppressions.push(name.into());
2177 }
2178
2179 pub fn into_issues(self) -> Vec<Issue> {
2181 self.issues
2182 .into_iter()
2183 .filter(|i| !i.suppressed)
2184 .filter(|i| {
2185 !self
2186 .file_suppressions
2187 .iter()
2188 .any(|s| s == i.kind.display_name())
2189 })
2190 .collect()
2191 }
2192
2193 pub fn into_all_issues(self) -> Vec<Issue> {
2198 self.issues
2199 .into_iter()
2200 .map(|mut i| {
2201 if self
2202 .file_suppressions
2203 .iter()
2204 .any(|s| s == i.kind.display_name())
2205 {
2206 i.suppressed = true;
2207 }
2208 i
2209 })
2210 .collect()
2211 }
2212
2213 pub fn suppress_range(&mut self, from: usize, suppressions: &[String]) {
2216 if suppressions.is_empty() {
2217 return;
2218 }
2219 for issue in self.issues[from..].iter_mut() {
2220 if suppressions.iter().any(|s| s == issue.kind.display_name()) {
2221 issue.suppressed = true;
2222 }
2223 }
2224 }
2225
2226 pub fn issue_count(&self) -> usize {
2229 self.issues.len()
2230 }
2231
2232 pub fn truncate_to(&mut self, mark: usize) {
2238 for issue in self.issues.drain(mark..) {
2239 let key = (
2240 issue.kind.name(),
2241 issue.location.file.clone(),
2242 issue.location.line,
2243 issue.location.col_start,
2244 );
2245 self.seen.remove(&key);
2246 }
2247 }
2248
2249 pub fn is_empty(&self) -> bool {
2250 self.issues.is_empty()
2251 }
2252
2253 pub fn len(&self) -> usize {
2254 self.issues.len()
2255 }
2256
2257 pub fn error_count(&self) -> usize {
2258 self.issues
2259 .iter()
2260 .filter(|i| !i.suppressed && i.severity == Severity::Error)
2261 .count()
2262 }
2263
2264 pub fn warning_count(&self) -> usize {
2265 self.issues
2266 .iter()
2267 .filter(|i| !i.suppressed && i.severity == Severity::Warning)
2268 .count()
2269 }
2270}
2271
2272#[cfg(test)]
2273mod code_tests {
2274 use super::*;
2275 use std::collections::HashSet;
2276
2277 fn one_of_each() -> Vec<IssueKind> {
2283 let s = || String::new();
2284 vec![
2285 IssueKind::InvalidScope { in_class: false },
2286 IssueKind::NonStaticSelfCall {
2287 class: s(),
2288 method: s(),
2289 },
2290 IssueKind::DirectConstructorCall { class: s() },
2291 IssueKind::UndefinedVariable { name: s() },
2292 IssueKind::UndefinedFunction { name: s() },
2293 IssueKind::UndefinedMethod {
2294 class: s(),
2295 method: s(),
2296 },
2297 IssueKind::UndefinedClass { name: s() },
2298 IssueKind::NotAnInterface { name: s() },
2299 IssueKind::UndefinedProperty {
2300 class: s(),
2301 property: s(),
2302 },
2303 IssueKind::UndefinedConstant { name: s() },
2304 IssueKind::InaccessibleClassConstant {
2305 class: s(),
2306 constant: s(),
2307 },
2308 IssueKind::InaccessibleProperty {
2309 class: s(),
2310 property: s(),
2311 },
2312 IssueKind::PossiblyUndefinedVariable { name: s() },
2313 IssueKind::UndefinedTrait { name: s() },
2314 IssueKind::TraitConstantAccessedDirectly {
2315 trait_name: s(),
2316 constant: s(),
2317 },
2318 IssueKind::UndefinedTraitAliasMethod {
2319 trait_name: Some(s()),
2320 method: s(),
2321 },
2322 IssueKind::ParentNotFound,
2323 IssueKind::NullArgument {
2324 param: s(),
2325 fn_name: s(),
2326 },
2327 IssueKind::NullPropertyFetch { property: s() },
2328 IssueKind::NullMethodCall { method: s() },
2329 IssueKind::NullArrayAccess,
2330 IssueKind::PossiblyNullArgument {
2331 param: s(),
2332 fn_name: s(),
2333 },
2334 IssueKind::PossiblyInvalidArgument {
2335 param: s(),
2336 fn_name: s(),
2337 expected: s(),
2338 actual: s(),
2339 },
2340 IssueKind::PossiblyNullPropertyFetch { property: s() },
2341 IssueKind::PossiblyNullMethodCall { method: s() },
2342 IssueKind::PossiblyNullArrayAccess,
2343 IssueKind::NullableReturnStatement {
2344 expected: s(),
2345 actual: s(),
2346 },
2347 IssueKind::InvalidReturnType {
2348 expected: s(),
2349 actual: s(),
2350 },
2351 IssueKind::InvalidArgument {
2352 param: s(),
2353 fn_name: s(),
2354 expected: s(),
2355 actual: s(),
2356 },
2357 IssueKind::TooFewArguments {
2358 fn_name: s(),
2359 expected: 0,
2360 actual: 0,
2361 },
2362 IssueKind::TooManyArguments {
2363 fn_name: s(),
2364 expected: 0,
2365 actual: 0,
2366 },
2367 IssueKind::InvalidNamedArgument {
2368 fn_name: s(),
2369 name: s(),
2370 },
2371 IssueKind::InvalidNamedArguments { fn_name: s() },
2372 IssueKind::InvalidPassByReference {
2373 fn_name: s(),
2374 param: s(),
2375 },
2376 IssueKind::InvalidPropertyFetch { ty: s() },
2377 IssueKind::InvalidArrayAccess { ty: s() },
2378 IssueKind::PossiblyInvalidArrayAccess { ty: s() },
2379 IssueKind::InvalidArrayAssignment { ty: s() },
2380 IssueKind::InvalidPropertyAssignment {
2381 property: s(),
2382 expected: s(),
2383 actual: s(),
2384 },
2385 IssueKind::InvalidCast { from: s(), to: s() },
2386 IssueKind::InvalidStaticInvocation {
2387 class: s(),
2388 method: s(),
2389 },
2390 IssueKind::InvalidOperand {
2391 op: s(),
2392 left: s(),
2393 right: s(),
2394 },
2395 IssueKind::PossiblyInvalidOperand {
2396 op: s(),
2397 left: s(),
2398 right: s(),
2399 },
2400 IssueKind::PossiblyNullOperand { op: s(), ty: s() },
2401 IssueKind::DivisionByZero { op: s() },
2402 IssueKind::RawObjectIteration { ty: s() },
2403 IssueKind::PossiblyRawObjectIteration { ty: s() },
2404 IssueKind::MismatchingDocblockReturnType {
2405 declared: s(),
2406 inferred: s(),
2407 },
2408 IssueKind::MismatchingDocblockParamType {
2409 param: s(),
2410 declared: s(),
2411 inferred: s(),
2412 },
2413 IssueKind::TypeCheckMismatch {
2414 var: s(),
2415 expected: s(),
2416 actual: s(),
2417 },
2418 IssueKind::Trace {
2419 variable: s(),
2420 type_info: s(),
2421 },
2422 IssueKind::InvalidArrayOffset {
2423 expected: s(),
2424 actual: s(),
2425 },
2426 IssueKind::NonExistentArrayOffset { key: s() },
2427 IssueKind::PossiblyInvalidArrayOffset {
2428 expected: s(),
2429 actual: s(),
2430 },
2431 IssueKind::DuplicateArrayKey { key: s() },
2432 IssueKind::RedundantCondition { ty: s() },
2433 IssueKind::RedundantCast { from: s(), to: s() },
2434 IssueKind::UnnecessaryVarAnnotation { var: s() },
2435 IssueKind::TypeDoesNotContainType {
2436 left: s(),
2437 right: s(),
2438 },
2439 IssueKind::UnusedVariable { name: s() },
2440 IssueKind::UnusedParam { name: s() },
2441 IssueKind::UnreachableCode,
2442 IssueKind::UnhandledMatchCondition { detail: s() },
2443 IssueKind::UnusedMethod {
2444 class: s(),
2445 method: s(),
2446 },
2447 IssueKind::UnusedProperty {
2448 class: s(),
2449 property: s(),
2450 },
2451 IssueKind::UnusedFunction { name: s() },
2452 IssueKind::UnusedForeachValue { name: s() },
2453 IssueKind::UnusedClass { class: s() },
2454 IssueKind::UnusedSuppress { kind: s() },
2455 IssueKind::ArgumentTypeCoercion {
2456 param: s(),
2457 fn_name: s(),
2458 expected: s(),
2459 actual: s(),
2460 },
2461 IssueKind::PropertyTypeCoercion {
2462 property: s(),
2463 expected: s(),
2464 actual: s(),
2465 },
2466 IssueKind::ImpurePropertyAssignment { property: s() },
2467 IssueKind::ImpureMethodCall { method: s() },
2468 IssueKind::ImpureGlobalVariable { variable: s() },
2469 IssueKind::ImpureStaticVariable { variable: s() },
2470 IssueKind::ImpureByRefAssignment { variable: s() },
2471 IssueKind::ImpureStaticPropertyAssignment {
2472 class: s(),
2473 property: s(),
2474 },
2475 IssueKind::ImpureStaticPropertyAccess {
2476 class: s(),
2477 property: s(),
2478 },
2479 IssueKind::ImpureFunctionCall { fn_name: s() },
2480 IssueKind::ImmutablePropertyModification {
2481 receiver: s(),
2482 property: s(),
2483 },
2484 IssueKind::ReadonlyPropertyAssignment {
2485 class: s(),
2486 property: s(),
2487 },
2488 IssueKind::ReadonlyPropertyAlreadyInitialized {
2489 class: s(),
2490 property: s(),
2491 },
2492 IssueKind::UnimplementedAbstractMethod {
2493 class: s(),
2494 method: s(),
2495 },
2496 IssueKind::UnimplementedInterfaceMethod {
2497 class: s(),
2498 interface: s(),
2499 method: s(),
2500 },
2501 IssueKind::MethodSignatureMismatch {
2502 class: s(),
2503 method: s(),
2504 detail: s(),
2505 },
2506 IssueKind::OverriddenMethodAccess {
2507 class: s(),
2508 method: s(),
2509 },
2510 IssueKind::OverriddenPropertyAccess {
2511 class: s(),
2512 property: s(),
2513 },
2514 IssueKind::PropertyTypeRedeclarationMismatch {
2515 class: s(),
2516 property: s(),
2517 expected: s(),
2518 actual: s(),
2519 },
2520 IssueKind::ReadonlyPropertyRedeclarationMismatch {
2521 parent_class: s(),
2522 class: s(),
2523 property: s(),
2524 parent_readonly: true,
2525 },
2526 IssueKind::StaticPropertyRedeclarationMismatch {
2527 parent_class: s(),
2528 class: s(),
2529 property: s(),
2530 parent_static: true,
2531 },
2532 IssueKind::ReadonlyClassExtendsMismatch {
2533 parent: s(),
2534 child: s(),
2535 parent_readonly: true,
2536 },
2537 IssueKind::InvalidReadonlyPropertyDeclaration {
2538 class: s(),
2539 property: s(),
2540 },
2541 IssueKind::BackedEnumCaseTypeMismatch {
2542 enum_name: s(),
2543 case_name: s(),
2544 expected: s(),
2545 actual: s(),
2546 },
2547 IssueKind::InvalidExtendClass {
2548 parent: s(),
2549 child: s(),
2550 },
2551 IssueKind::FinalMethodOverridden {
2552 class: s(),
2553 method: s(),
2554 parent: s(),
2555 },
2556 IssueKind::AbstractInstantiation { class: s() },
2557 IssueKind::AbstractMethodCall {
2558 class: s(),
2559 method: s(),
2560 },
2561 IssueKind::InterfaceInstantiation { class: s() },
2562 IssueKind::InvalidOverride {
2563 class: s(),
2564 method: s(),
2565 detail: s(),
2566 },
2567 IssueKind::CircularInheritance { class: s() },
2568 IssueKind::TaintedInput { sink: s() },
2569 IssueKind::TaintedHtml,
2570 IssueKind::TaintedSql,
2571 IssueKind::TaintedShell,
2572 IssueKind::TaintedLlmPrompt,
2573 IssueKind::InvalidTemplateParam {
2574 name: s(),
2575 expected_bound: s(),
2576 actual: s(),
2577 },
2578 IssueKind::ShadowedTemplateParam { name: s() },
2579 IssueKind::DeprecatedCall {
2580 name: s(),
2581 message: None,
2582 },
2583 IssueKind::DeprecatedProperty {
2584 class: s(),
2585 property: s(),
2586 message: None,
2587 },
2588 IssueKind::DeprecatedConstant {
2589 class: s(),
2590 constant: s(),
2591 message: None,
2592 },
2593 IssueKind::DeprecatedInterface {
2594 name: s(),
2595 message: None,
2596 },
2597 IssueKind::DeprecatedTrait {
2598 name: s(),
2599 message: None,
2600 },
2601 IssueKind::DeprecatedMethodCall {
2602 class: s(),
2603 method: s(),
2604 message: None,
2605 },
2606 IssueKind::DeprecatedMethod {
2607 class: s(),
2608 method: s(),
2609 message: None,
2610 },
2611 IssueKind::DeprecatedClass {
2612 name: s(),
2613 message: None,
2614 },
2615 IssueKind::InternalMethod {
2616 class: s(),
2617 method: s(),
2618 },
2619 IssueKind::MissingReturnType { fn_name: s() },
2620 IssueKind::MissingClosureReturnType,
2621 IssueKind::MissingParamType {
2622 fn_name: s(),
2623 param: s(),
2624 },
2625 IssueKind::MissingPropertyType {
2626 class: s(),
2627 property: s(),
2628 },
2629 IssueKind::MissingThrowsDocblock { class: s() },
2630 IssueKind::InvalidDocblock { message: s() },
2631 IssueKind::MixedArgument {
2632 param: s(),
2633 fn_name: s(),
2634 },
2635 IssueKind::MixedAssignment { var: s() },
2636 IssueKind::MixedMethodCall { method: s() },
2637 IssueKind::UnsupportedReferenceUsage,
2638 IssueKind::NoInterfaceProperties { property: s() },
2639 IssueKind::UndefinedDocblockClass { name: s() },
2640 IssueKind::MissingConstructor { class: s() },
2641 IssueKind::PropertyPossiblyUninitialized {
2642 class: s(),
2643 property: s(),
2644 },
2645 IssueKind::MixedFunctionCall,
2646 IssueKind::MixedReturnStatement { declared: s() },
2647 IssueKind::MixedPropertyFetch { property: s() },
2648 IssueKind::MixedPropertyAssignment { property: s() },
2649 IssueKind::MixedArrayAccess,
2650 IssueKind::MixedArrayOffset,
2651 IssueKind::MixedClone,
2652 IssueKind::InvalidClone { ty: s() },
2653 IssueKind::PossiblyInvalidClone { ty: s() },
2654 IssueKind::InvalidToString { class: s() },
2655 IssueKind::InvalidTraitUse {
2656 trait_name: s(),
2657 reason: s(),
2658 },
2659 IssueKind::ParseError { message: s() },
2660 IssueKind::InvalidThrow { ty: s() },
2661 IssueKind::InvalidCatch { ty: s() },
2662 IssueKind::UnreachableCatch {
2663 ty: s(),
2664 shadowed_by: s(),
2665 },
2666 IssueKind::ImplicitToStringCast { class: s() },
2667 IssueKind::ImplicitFloatToIntCast { from: s() },
2668 IssueKind::WrongCaseFunction {
2669 used: s(),
2670 canonical: s(),
2671 },
2672 IssueKind::WrongCaseMethod {
2673 class: s(),
2674 used: s(),
2675 canonical: s(),
2676 },
2677 IssueKind::WrongCaseClass {
2678 used: s(),
2679 canonical: s(),
2680 },
2681 IssueKind::InvalidAttribute { message: s() },
2682 IssueKind::UndefinedAttributeClass { name: s() },
2683 IssueKind::ForbiddenCode { message: s() },
2684 IssueKind::DuplicateClass { name: s() },
2685 IssueKind::DuplicateInterface { name: s() },
2686 IssueKind::DuplicateTrait { name: s() },
2687 IssueKind::DuplicateEnum { name: s() },
2688 IssueKind::DuplicateFunction { name: s() },
2689 ]
2690 }
2691
2692 #[test]
2693 fn codes_have_expected_shape() {
2694 for kind in one_of_each() {
2695 let code = kind.code();
2696 assert!(
2697 code.len() == 7
2698 && code.starts_with("MIR")
2699 && code[3..].chars().all(|c| c.is_ascii_digit()),
2700 "code {code:?} for {} does not match MIR####",
2701 kind.name(),
2702 );
2703 }
2704 }
2705
2706 #[test]
2707 fn codes_are_unique() {
2708 let kinds = one_of_each();
2709 let mut seen: HashSet<&'static str> = HashSet::new();
2710 for kind in &kinds {
2711 assert!(
2712 seen.insert(kind.code()),
2713 "duplicate code {} (variant {})",
2714 kind.code(),
2715 kind.name(),
2716 );
2717 }
2718 }
2719
2720 #[test]
2721 fn default_severity_for_code_round_trips() {
2722 for kind in one_of_each() {
2723 let code = kind.code();
2724 assert_eq!(
2725 IssueKind::default_severity_for_code(code),
2726 Some(kind.default_severity()),
2727 "severity mismatch for {code} (variant {})",
2728 kind.name(),
2729 );
2730 }
2731 }
2732
2733 #[test]
2734 fn default_severity_for_code_unknown_returns_none() {
2735 assert_eq!(IssueKind::default_severity_for_code("MIR9999"), None);
2736 assert_eq!(IssueKind::default_severity_for_code(""), None);
2737 assert_eq!(IssueKind::default_severity_for_code("mir0001"), None);
2738 }
2739
2740 #[test]
2743 fn one_of_each_has_every_variant() {
2744 assert_eq!(one_of_each().len(), 158);
2747 }
2748}