1use std::collections::HashSet;
2use std::fmt;
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7mod psalm_levels;
8pub use psalm_levels::psalm_error_level;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
15pub enum Severity {
16 Info,
18 Warning,
20 Error,
22}
23
24impl fmt::Display for Severity {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Severity::Info => write!(f, "info"),
28 Severity::Warning => write!(f, "warning"),
29 Severity::Error => write!(f, "error"),
30 }
31 }
32}
33
34pub use mir_types::Location;
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub enum CloneFailure {
47 NonObject,
48 Enum,
49 PrivateMethod {
51 owner: String,
52 scope: Option<String>,
53 },
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57#[non_exhaustive]
58pub enum IssueKind {
59 NonStaticSelfCall { class: String, method: String },
65 InvalidScope {
66 in_class: bool,
68 },
69 UndefinedVariable { name: String },
72 UndefinedFunction { name: String },
75 UndefinedMethod { class: String, method: String },
78 PossiblyUndefinedMethod { class: String, method: String },
81 UndefinedClass { name: String },
84 UndefinedProperty { class: String, property: String },
87 InaccessibleProperty { class: String, property: String },
92 UndefinedConstant { name: String },
95 InaccessibleClassConstant { class: String, constant: String },
98 PossiblyUndefinedVariable { name: String },
101 UndefinedTrait { name: String },
104 TraitConstantAccessedDirectly {
111 trait_name: String,
112 constant: String,
113 },
114 UndefinedTraitAliasMethod {
122 trait_name: Option<String>,
123 method: String,
124 },
125 ParentNotFound,
128 InvalidStringClass { actual: String },
131 NotAnInterface { name: String },
135
136 NullArgument { param: String, fn_name: String },
140 NullPropertyFetch { property: String },
143 NullMethodCall { method: String },
146 NullArrayAccess,
149 PossiblyNullArgument { param: String, fn_name: String },
152 PossiblyInvalidArgument {
155 param: String,
156 fn_name: String,
157 expected: String,
158 actual: String,
159 },
160 PossiblyNullPropertyFetch { property: String },
163 PossiblyNullMethodCall { method: String },
166 PossiblyNullArrayAccess,
169 NullableReturnStatement { expected: String, actual: String },
172
173 InvalidReturnType { expected: String, actual: String },
177 LessSpecificReturnStatement { expected: String, actual: String },
180 InvalidArgument {
183 param: String,
184 fn_name: String,
185 expected: String,
186 actual: String,
187 },
188 InvalidScalarArgument {
191 param: String,
192 fn_name: String,
193 expected: String,
194 actual: String,
195 },
196 TooFewArguments {
199 fn_name: String,
200 expected: usize,
201 actual: usize,
202 },
203 TooManyArguments {
206 fn_name: String,
207 expected: usize,
208 actual: usize,
209 },
210 InvalidNamedArgument {
213 fn_name: String,
214 name: String,
215 overwrites: bool,
216 },
217 InvalidNamedArguments { fn_name: String },
220 InvalidPassByReference { fn_name: String, param: String },
223 InvalidPropertyFetch { ty: String },
226 InvalidMethodCall { method: String, ty: String },
229 InvalidMemberName { member: String, ty: String },
232 NativeResourceType { class: String },
235 InvalidUnpack {
238 ty: String,
240 },
241 InvalidArrayAccess { ty: String },
244 PossiblyInvalidArrayAccess { ty: String },
247 InvalidArrayAssignment { ty: String },
250 InvalidPropertyAssignment {
253 property: String,
254 expected: String,
255 actual: String,
256 },
257 PossiblyNullPropertyAssignmentValue {
260 property: String,
261 expected: String,
262 actual: String,
263 },
264 PossiblyFalsePropertyAssignmentValue {
267 property: String,
268 expected: String,
269 actual: String,
270 },
271 PossiblyInvalidPropertyAssignmentValue {
274 property: String,
275 expected: String,
276 actual: String,
277 },
278 InvalidCast { from: String, to: String },
281 InvalidStaticInvocation { class: String, method: String },
284 InvalidOperand {
288 op: String,
289 left: String,
290 right: String,
291 },
292 PossiblyInvalidOperand {
295 op: String,
296 left: String,
297 right: String,
298 },
299 PossiblyNullOperand { op: String, ty: String },
302 DivisionByZero { op: String },
306 RawObjectIteration { ty: String },
309 PossiblyRawObjectIteration { ty: String },
312 InvalidGeneratorIteration { ty: String, send: String },
316 MismatchingDocblockReturnType { declared: String, inferred: String },
319 MismatchingDocblockParamType {
322 param: String,
323 declared: String,
324 inferred: String,
325 },
326 TypeCheckMismatch {
332 var: String,
333 expected: String,
334 actual: String,
335 },
336
337 Trace { variable: String, type_info: String },
340
341 InvalidArrayOffset { expected: String, actual: String },
345 NonExistentArrayOffset { key: String },
349 PossiblyInvalidArrayOffset { expected: String, actual: String },
352 DuplicateArrayKey { key: String },
357
358 RedundantCondition {
362 always_true: bool,
363 unreachable: Option<String>,
365 },
366 RedundantCast { from: String, to: String },
369 UnnecessaryVarAnnotation { var: String },
372 TypeDoesNotContainType { left: String, right: String },
375 ParadoxicalCondition { value: String },
378 DocblockTypeContradiction { expr: String, declared: String },
383 ImpossibleIdenticalComparison {
389 op: String,
390 left: String,
391 right: String,
392 },
393 ImpossibleLooseComparison {
400 op: String,
401 left: String,
402 right: String,
403 },
404 UnevaluatedCode { reason: String },
411
412 UnusedVariable { name: String },
416 UnusedParam { name: String },
419 UnreachableCode,
422 UnhandledMatchCondition { detail: String },
425 UnusedMethod { class: String, method: String },
428 UnusedProperty { class: String, property: String },
431 UnusedFunction { name: String },
434 UnusedForeachValue { name: String },
437 UnusedClass { class: String },
440 UnusedConstant { class: String, constant: String },
443 UnusedSuppress { kind: String },
447
448 ArgumentTypeCoercion {
451 param: String,
452 fn_name: String,
453 expected: String,
454 actual: String,
455 },
456
457 PropertyTypeCoercion {
460 property: String,
461 expected: String,
462 actual: String,
463 },
464
465 ImpurePropertyAssignment { property: String },
468 ImpureMethodCall { method: String },
470 ImpureGlobalVariable { variable: String },
472 ImpureStaticVariable { variable: String },
474 ImpureStaticPropertyAssignment { class: String, property: String },
478 ImpureStaticPropertyAccess { class: String, property: String },
483 ImpureByRefAssignment { variable: String },
488 ImpureFunctionCall { fn_name: String },
492 ImmutablePropertyModification { receiver: String, property: String },
498
499 ReadonlyPropertyAssignment {
503 class: String,
504 property: String,
505 unset: bool,
506 },
507 ReadonlyPropertyAlreadyInitialized { class: String, property: String },
514
515 UnimplementedAbstractMethod { class: String, method: String },
519 UnimplementedInterfaceMethod {
522 class: String,
523 interface: String,
524 method: String,
525 },
526 MethodSignatureMismatch {
529 class: String,
530 method: String,
531 detail: String,
532 },
533 OverriddenMethodAccess {
536 class: String,
537 method: String,
538 parent: String,
539 visibility: String,
540 },
541 OverriddenPropertyAccess {
544 class: String,
545 property: String,
546 parent: String,
547 visibility: String,
548 },
549 PropertyTypeRedeclarationMismatch {
552 class: String,
553 property: String,
554 parent: String,
555 expected: String,
556 covariant: bool,
558 before_php85: bool,
560 },
561 NonInvariantDocblockPropertyType {
564 class: String,
565 property: String,
566 parent: String,
567 expected: String,
568 actual: String,
569 },
570 ReadonlyPropertyRedeclarationMismatch {
573 parent_class: String,
574 class: String,
575 property: String,
576 parent_readonly: bool,
579 },
580 StaticPropertyRedeclarationMismatch {
583 parent_class: String,
584 class: String,
585 property: String,
586 parent_static: bool,
589 },
590 ReadonlyClassExtendsMismatch {
596 parent: String,
597 child: String,
598 parent_readonly: bool,
601 },
602 InvalidReadonlyPropertyDeclaration { class: String, property: String },
608 BackedEnumCaseTypeMismatch {
611 enum_name: String,
612 case_name: String,
613 expected: String,
614 actual: String,
615 },
616 DuplicateEnumCaseValue {
620 enum_name: String,
621 first_case: String,
622 case_name: String,
623 },
624 DirectConstructorCall { class: String },
627 InvalidExtendClass {
630 parent: String,
631 child: String,
632 #[serde(default)]
634 reason: Option<String>,
635 },
636 FinalMethodOverridden {
639 class: String,
640 method: String,
641 parent: String,
642 },
643 AbstractInstantiation { class: String },
646 AbstractMethodCall { class: String, method: String },
649 InterfaceInstantiation { class: String },
652 EnumInstantiation { class: String },
655 TraitInstantiation { class: String },
658 InvalidDynamicProperty { class: String, property: String },
662 InvalidOverride { class: String, member: String },
667
668 TaintedInput { sink: String },
672 TaintedHtml,
675 TaintedSql,
678 TaintedShell,
681 TaintedLlmPrompt,
685 TaintedHeader,
688 TaintedCookie,
691 TaintedSsrf,
694 TaintedLdap,
697 TaintedXpath,
700 TaintedCallable,
703 TaintedFile,
706 TaintedInclude,
709 TaintedEval,
712 TaintedUnserialize,
715
716 InsecurePasswordHash { reason: String },
720
721 WeakCryptography { reason: String },
725
726 InsecureSessionConfig { reason: String },
730
731 InsecureRandomness { context: String },
735
736 TaintedXml,
740
741 UnsafeUnserialize,
745
746 UnserializeGadget { class: String, method: String },
750
751 MissingSensitiveParameter { param: String },
755
756 TaintedMassAssignment { target: String },
760
761 TaintedCommandArgument,
765
766 QuotedShellEscape,
770
771 UnrestrictedFileUpload,
775
776 HostHeaderInjection { target: String },
780
781 TaintedNoSql,
785
786 TaintedRegex,
790
791 TaintedEnvironment,
795
796 UnescapedLikeWildcard,
800
801 UnquotedSqlEscape,
805
806 InsufficientHtmlEscape,
811
812 MissingAuthorizationCheck {
819 handler: String,
820 missing: String,
821 who: String,
822 },
823
824 UntracedTaint { call: String, reason: String },
829
830 TaintedCsv,
834
835 TaintedLog,
839
840 ResourceExhaustion { function: String },
844
845 SpoofableClientIp,
849
850 CodeAfterRedirect,
854
855 InsecureCheckResult { reason: String },
859
860 LdapAnonymousBind,
864
865 InsecureFilePermissions { reason: String },
869
870 HardcodedCredential { what: String },
874
875 InsecureCors,
879
880 PredictableSeed { function: String },
884
885 ObfuscatedCode,
889
890 InsecureTls { reason: String },
894
895 TimingUnsafeComparison { what: String },
899
900 InvalidTemplateParam {
904 name: String,
905 expected_bound: String,
906 actual: String,
907 },
908 ShadowedTemplateParam { name: String },
911 IfThisIsMismatch {
916 class: String,
917 method: String,
918 expected: String,
919 actual: String,
920 },
921
922 DeprecatedCall {
926 name: String,
927 message: Option<Arc<str>>,
928 },
929 DeprecatedProperty {
932 class: String,
933 property: String,
934 message: Option<Arc<str>>,
935 },
936 DeprecatedConstant {
939 class: String,
940 constant: String,
941 message: Option<Arc<str>>,
942 },
943 OptionalParameterBeforeRequired { message: String },
948 ImplicitlyNullableParameter { message: String },
953 DeprecatedSyntax { message: String },
957 DynamicPropertyCreation { class: String, property: String },
961 DeprecatedInterface {
964 name: String,
965 message: Option<Arc<str>>,
966 },
967 DeprecatedTrait {
970 name: String,
971 message: Option<Arc<str>>,
972 },
973 DeprecatedMethodCall {
976 class: String,
977 method: String,
978 message: Option<Arc<str>>,
979 },
980 DeprecatedMethod {
983 class: String,
984 method: String,
985 message: Option<Arc<str>>,
986 },
987 DeprecatedClass {
990 name: String,
991 message: Option<Arc<str>>,
992 },
993 InternalMethod { class: String, method: String },
996 MissingReturnType { fn_name: String },
999 MissingClosureReturnType,
1002 MissingParamType { fn_name: String, param: String },
1005 MissingPropertyType { class: String, property: String },
1008 InvalidThrow { ty: String },
1011 InvalidCatch { ty: String },
1014 UnreachableCatch { ty: String, shadowed_by: String },
1019 MissingThrowsDocblock { class: String },
1022 UndefinedThrowsDocblock { name: String },
1027 ImplicitToStringCast { class: String },
1030 ImplicitFloatToIntCast { from: String },
1033 ParseError {
1036 message: String,
1037 code: String,
1039 },
1040 CompileError {
1043 message: String,
1044 code: String,
1046 },
1047 InvalidDocblock { message: String },
1050 InvalidDocblockType { message: String },
1052 MixedArgument { param: String, fn_name: String },
1055 MixedAssignment { var: String },
1058 MixedMethodCall { method: String },
1061 UnsupportedReferenceUsage,
1064 NoInterfaceProperties { property: String },
1068 UndefinedDocblockClass { name: String },
1072 MissingConstructor { class: String },
1075 PropertyPossiblyUninitialized { class: String, property: String },
1087 MixedFunctionCall,
1090 MixedReturnStatement { declared: String },
1093 MixedPropertyFetch { property: String },
1096 MixedPropertyAssignment { property: String },
1099 MixedArrayAccess,
1102 MixedArrayOffset,
1105 MixedClone,
1108 InvalidClone { ty: String, reason: CloneFailure },
1113 PossiblyInvalidClone { ty: String },
1117 InvalidToString { class: String },
1121 CircularInheritance { class: String },
1124
1125 InvalidTraitUse { trait_name: String, reason: String },
1129 ForbiddenCode { message: String },
1132
1133 InvalidAttribute { message: String },
1137 UndefinedAttributeClass { name: String },
1140
1141 WrongCaseFunction { used: String, canonical: String },
1145 WrongCaseMethod {
1148 class: String,
1149 used: String,
1150 canonical: String,
1151 },
1152 WrongCaseClass { used: String, canonical: String },
1155 DuplicateClass { name: String },
1158 DuplicateInterface { name: String },
1161 DuplicateTrait { name: String },
1164 DuplicateEnum { name: String },
1167 DuplicateFunction { name: String },
1170
1171 UseStatementHasNoEffect { name: String },
1177 PrivateFinalMethod { class: String, method: String },
1182 NonPublicMagicMethod { class: String, method: String },
1187 NoDiscardReturnIgnored {
1191 callee: String,
1193 message: Option<String>,
1194 },
1195 AnalyzerError { message: String },
1198
1199 PluginIssue { name: String, message: String },
1203}
1204
1205fn append_deprecation_message(base: String, message: &Option<Arc<str>>) -> String {
1206 match message.as_deref().filter(|m| !m.is_empty()) {
1207 Some(msg) => format!("{base}: {msg}"),
1208 None => base,
1209 }
1210}
1211
1212impl IssueKind {
1213 pub fn is_constant_condition(&self) -> bool {
1215 matches!(
1216 self,
1217 IssueKind::RedundantCondition { .. }
1218 | IssueKind::ImpossibleIdenticalComparison { .. }
1219 | IssueKind::ImpossibleLooseComparison { .. }
1220 | IssueKind::TypeDoesNotContainType { .. }
1221 | IssueKind::DocblockTypeContradiction { .. }
1222 | IssueKind::ParadoxicalCondition { .. }
1223 )
1224 }
1225
1226 pub fn default_severity(&self) -> Severity {
1228 match self {
1229 IssueKind::NonStaticSelfCall { .. }
1231 | IssueKind::DirectConstructorCall { .. }
1232 | IssueKind::InvalidScope { .. }
1233 | IssueKind::UndefinedVariable { .. }
1234 | IssueKind::UndefinedFunction { .. }
1235 | IssueKind::UndefinedMethod { .. }
1236 | IssueKind::UndefinedClass { .. }
1237 | IssueKind::NotAnInterface { .. }
1238 | IssueKind::UndefinedConstant { .. }
1239 | IssueKind::InaccessibleClassConstant { .. }
1240 | IssueKind::InaccessibleProperty { .. }
1241 | IssueKind::InvalidReturnType { .. }
1242 | IssueKind::InvalidArgument { .. }
1243 | IssueKind::InvalidUnpack { .. }
1244 | IssueKind::TooFewArguments { .. }
1245 | IssueKind::TooManyArguments { .. }
1246 | IssueKind::InvalidNamedArgument { .. }
1247 | IssueKind::InvalidNamedArguments { .. }
1248 | IssueKind::InvalidPassByReference { .. }
1249 | IssueKind::InvalidThrow { .. }
1250 | IssueKind::InvalidCatch { .. }
1251 | IssueKind::InvalidStaticInvocation { .. }
1252 | IssueKind::UnimplementedAbstractMethod { .. }
1253 | IssueKind::UnimplementedInterfaceMethod { .. }
1254 | IssueKind::MethodSignatureMismatch { .. }
1255 | IssueKind::InvalidExtendClass { .. }
1256 | IssueKind::FinalMethodOverridden { .. }
1257 | IssueKind::OverriddenMethodAccess { .. }
1258 | IssueKind::OverriddenPropertyAccess { .. }
1259 | IssueKind::AbstractInstantiation { .. }
1260 | IssueKind::AbstractMethodCall { .. }
1261 | IssueKind::InterfaceInstantiation { .. }
1262 | IssueKind::EnumInstantiation { .. }
1263 | IssueKind::TraitInstantiation { .. }
1264 | IssueKind::InvalidDynamicProperty { .. }
1265 | IssueKind::InvalidOverride { .. }
1266 | IssueKind::InvalidTemplateParam { .. }
1267 | IssueKind::ReadonlyPropertyAssignment { .. }
1268 | IssueKind::ReadonlyPropertyAlreadyInitialized { .. }
1269 | IssueKind::ParseError { .. }
1270 | IssueKind::CompileError { .. }
1271 | IssueKind::AnalyzerError { .. }
1272 | IssueKind::TaintedInput { .. }
1273 | IssueKind::TaintedHtml
1274 | IssueKind::TaintedSql
1275 | IssueKind::TaintedShell
1276 | IssueKind::TaintedLlmPrompt
1277 | IssueKind::TaintedHeader
1278 | IssueKind::TaintedCookie
1279 | IssueKind::TaintedSsrf
1280 | IssueKind::TaintedLdap
1281 | IssueKind::TaintedXpath
1282 | IssueKind::TaintedCallable
1283 | IssueKind::TaintedFile
1284 | IssueKind::TaintedInclude
1285 | IssueKind::TaintedEval
1286 | IssueKind::TaintedUnserialize
1287 | IssueKind::TaintedXml
1288 | IssueKind::TaintedLog
1289 | IssueKind::TaintedCsv
1290 | IssueKind::TaintedNoSql
1291 | IssueKind::TaintedRegex
1292 | IssueKind::TaintedEnvironment
1293 | IssueKind::TaintedCommandArgument
1294 | IssueKind::TaintedMassAssignment { .. }
1295 | IssueKind::CircularInheritance { .. }
1296 | IssueKind::InvalidTraitUse { .. }
1297 | IssueKind::UndefinedTrait { .. }
1298 | IssueKind::TraitConstantAccessedDirectly { .. }
1299 | IssueKind::UndefinedTraitAliasMethod { .. }
1300 | IssueKind::InvalidClone { .. }
1301 | IssueKind::InvalidToString { .. }
1302 | IssueKind::TypeCheckMismatch { .. }
1303 | IssueKind::PropertyTypeRedeclarationMismatch { .. }
1304 | IssueKind::ReadonlyPropertyRedeclarationMismatch { .. }
1305 | IssueKind::StaticPropertyRedeclarationMismatch { .. }
1306 | IssueKind::ReadonlyClassExtendsMismatch { .. }
1307 | IssueKind::InvalidReadonlyPropertyDeclaration { .. }
1308 | IssueKind::BackedEnumCaseTypeMismatch { .. }
1309 | IssueKind::DuplicateEnumCaseValue { .. }
1310 | IssueKind::DivisionByZero { .. }
1311 | IssueKind::InvalidMemberName { .. }
1312 | IssueKind::NativeResourceType { .. }
1313 | IssueKind::ParentNotFound => Severity::Error,
1314 IssueKind::Trace { .. } => Severity::Info,
1315
1316 IssueKind::NullArgument { .. }
1318 | IssueKind::NullPropertyFetch { .. }
1319 | IssueKind::NullMethodCall { .. }
1320 | IssueKind::NullArrayAccess
1321 | IssueKind::NullableReturnStatement { .. }
1322 | IssueKind::InvalidPropertyFetch { .. }
1323 | IssueKind::InvalidMethodCall { .. }
1324 | IssueKind::InvalidArrayAccess { .. }
1325 | IssueKind::InvalidArrayAssignment { .. }
1326 | IssueKind::InvalidPropertyAssignment { .. }
1327 | IssueKind::InvalidArrayOffset { .. }
1328 | IssueKind::NonExistentArrayOffset { .. }
1329 | IssueKind::PossiblyInvalidArrayOffset { .. }
1330 | IssueKind::UndefinedProperty { .. }
1331 | IssueKind::InvalidOperand { .. }
1332 | IssueKind::InvalidScalarArgument { .. }
1333 | IssueKind::ImplicitToStringCast { .. }
1334 | IssueKind::ImplicitFloatToIntCast { .. }
1335 | IssueKind::UnusedVariable { .. }
1336 | IssueKind::UnusedForeachValue { .. }
1337 | IssueKind::ImpurePropertyAssignment { .. }
1338 | IssueKind::ImpureMethodCall { .. }
1339 | IssueKind::ImpureGlobalVariable { .. }
1340 | IssueKind::ImpureStaticVariable { .. }
1341 | IssueKind::ImpureStaticPropertyAssignment { .. }
1342 | IssueKind::ImpureStaticPropertyAccess { .. }
1343 | IssueKind::ImpureFunctionCall { .. }
1344 | IssueKind::ImpureByRefAssignment { .. }
1345 | IssueKind::ImmutablePropertyModification { .. }
1346 | IssueKind::UnsupportedReferenceUsage
1347 | IssueKind::ParadoxicalCondition { .. }
1348 | IssueKind::UnhandledMatchCondition { .. }
1349 | IssueKind::InvalidStringClass { .. }
1350 | IssueKind::ImpossibleIdenticalComparison { .. }
1351 | IssueKind::ImpossibleLooseComparison { .. }
1352 | IssueKind::DuplicateArrayKey { .. }
1353 | IssueKind::ForbiddenCode { .. }
1354 | IssueKind::UndefinedThrowsDocblock { .. }
1355 | IssueKind::InvalidDocblockType { .. }
1356 | IssueKind::UseStatementHasNoEffect { .. }
1357 | IssueKind::PrivateFinalMethod { .. }
1358 | IssueKind::NonPublicMagicMethod { .. }
1359 | IssueKind::InsecurePasswordHash { .. }
1360 | IssueKind::WeakCryptography { .. }
1361 | IssueKind::InsecureSessionConfig { .. }
1362 | IssueKind::InsecureRandomness { .. }
1363 | IssueKind::UnsafeUnserialize
1364 | IssueKind::UnserializeGadget { .. }
1365 | IssueKind::MissingSensitiveParameter { .. }
1366 | IssueKind::QuotedShellEscape
1367 | IssueKind::UnrestrictedFileUpload
1368 | IssueKind::HostHeaderInjection { .. }
1369 | IssueKind::ResourceExhaustion { .. }
1370 | IssueKind::SpoofableClientIp
1371 | IssueKind::CodeAfterRedirect
1372 | IssueKind::InsecureCheckResult { .. }
1373 | IssueKind::LdapAnonymousBind
1374 | IssueKind::InsecureFilePermissions { .. }
1375 | IssueKind::HardcodedCredential { .. }
1376 | IssueKind::InsecureCors
1377 | IssueKind::PredictableSeed { .. }
1378 | IssueKind::ObfuscatedCode
1379 | IssueKind::InsecureTls { .. }
1380 | IssueKind::TimingUnsafeComparison { .. }
1381 | IssueKind::UnescapedLikeWildcard
1382 | IssueKind::UnquotedSqlEscape
1383 | IssueKind::InsufficientHtmlEscape
1384 | IssueKind::MissingAuthorizationCheck { .. }
1385 | IssueKind::UntracedTaint { .. }
1386 | IssueKind::NoDiscardReturnIgnored { .. } => Severity::Warning,
1387
1388 IssueKind::PossiblyUndefinedVariable { .. } => Severity::Warning,
1390
1391 IssueKind::PossiblyNullArgument { .. }
1393 | IssueKind::PossiblyInvalidArgument { .. }
1394 | IssueKind::PossiblyNullPropertyFetch { .. }
1395 | IssueKind::PossiblyNullMethodCall { .. }
1396 | IssueKind::PossiblyUndefinedMethod { .. }
1397 | IssueKind::PossiblyNullArrayAccess
1398 | IssueKind::PossiblyInvalidArrayAccess { .. }
1399 | IssueKind::PossiblyInvalidClone { .. }
1400 | IssueKind::PossiblyInvalidOperand { .. }
1401 | IssueKind::PossiblyNullOperand { .. }
1402 | IssueKind::PossiblyRawObjectIteration { .. }
1403 | IssueKind::InvalidGeneratorIteration { .. }
1404 | IssueKind::PossiblyNullPropertyAssignmentValue { .. }
1405 | IssueKind::PossiblyFalsePropertyAssignmentValue { .. }
1406 | IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => Severity::Info,
1407
1408 IssueKind::RawObjectIteration { .. } => Severity::Warning,
1409
1410 IssueKind::RedundantCondition { .. }
1412 | IssueKind::RedundantCast { .. }
1413 | IssueKind::UnnecessaryVarAnnotation { .. }
1414 | IssueKind::TypeDoesNotContainType { .. }
1415 | IssueKind::DocblockTypeContradiction { .. }
1416 | IssueKind::UnevaluatedCode { .. }
1417 | IssueKind::IfThisIsMismatch { .. }
1418 | IssueKind::UnusedParam { .. }
1419 | IssueKind::UnreachableCode
1420 | IssueKind::UnreachableCatch { .. }
1421 | IssueKind::UnusedMethod { .. }
1422 | IssueKind::UnusedProperty { .. }
1423 | IssueKind::UnusedFunction { .. }
1424 | IssueKind::UnusedClass { .. }
1425 | IssueKind::UnusedConstant { .. }
1426 | IssueKind::UnusedSuppress { .. }
1427 | IssueKind::ArgumentTypeCoercion { .. }
1428 | IssueKind::PropertyTypeCoercion { .. }
1429 | IssueKind::LessSpecificReturnStatement { .. }
1430 | IssueKind::DeprecatedCall { .. }
1431 | IssueKind::DeprecatedProperty { .. }
1432 | IssueKind::DeprecatedConstant { .. }
1433 | IssueKind::OptionalParameterBeforeRequired { .. }
1434 | IssueKind::ImplicitlyNullableParameter { .. }
1435 | IssueKind::DeprecatedSyntax { .. }
1436 | IssueKind::DynamicPropertyCreation { .. }
1437 | IssueKind::DeprecatedInterface { .. }
1438 | IssueKind::DeprecatedTrait { .. }
1439 | IssueKind::DeprecatedMethodCall { .. }
1440 | IssueKind::DeprecatedMethod { .. }
1441 | IssueKind::DeprecatedClass { .. }
1442 | IssueKind::InternalMethod { .. }
1443 | IssueKind::MissingReturnType { .. }
1444 | IssueKind::MissingClosureReturnType
1445 | IssueKind::MissingParamType { .. }
1446 | IssueKind::MissingPropertyType { .. }
1447 | IssueKind::MismatchingDocblockReturnType { .. }
1448 | IssueKind::MismatchingDocblockParamType { .. }
1449 | IssueKind::InvalidDocblock { .. }
1450 | IssueKind::InvalidCast { .. }
1451 | IssueKind::MixedArgument { .. }
1452 | IssueKind::MixedAssignment { .. }
1453 | IssueKind::MixedMethodCall { .. }
1454 | IssueKind::NoInterfaceProperties { .. }
1455 | IssueKind::UndefinedDocblockClass { .. }
1456 | IssueKind::MissingConstructor { .. }
1457 | IssueKind::PropertyPossiblyUninitialized { .. }
1458 | IssueKind::MixedFunctionCall
1459 | IssueKind::MixedReturnStatement { .. }
1460 | IssueKind::MixedPropertyFetch { .. }
1461 | IssueKind::MixedPropertyAssignment { .. }
1462 | IssueKind::MixedArrayAccess
1463 | IssueKind::MixedArrayOffset
1464 | IssueKind::MixedClone
1465 | IssueKind::ShadowedTemplateParam { .. }
1466 | IssueKind::MissingThrowsDocblock { .. }
1467 | IssueKind::WrongCaseFunction { .. }
1468 | IssueKind::WrongCaseMethod { .. }
1469 | IssueKind::WrongCaseClass { .. }
1470 | IssueKind::InvalidAttribute { .. }
1471 | IssueKind::UndefinedAttributeClass { .. }
1472 | IssueKind::NonInvariantDocblockPropertyType { .. } => Severity::Info,
1473 IssueKind::DuplicateClass { .. }
1474 | IssueKind::DuplicateInterface { .. }
1475 | IssueKind::DuplicateTrait { .. }
1476 | IssueKind::DuplicateEnum { .. }
1477 | IssueKind::DuplicateFunction { .. } => Severity::Error,
1478 IssueKind::PluginIssue { .. } => Severity::Error,
1481 }
1482 }
1483
1484 pub fn code(&self) -> &'static str {
1514 match self {
1515 IssueKind::NonStaticSelfCall { .. } => "MIR0216",
1517 IssueKind::DirectConstructorCall { .. } => "MIR0217",
1518 IssueKind::InvalidScope { .. } => "MIR0001",
1519 IssueKind::UndefinedVariable { .. } => "MIR0002",
1520 IssueKind::UndefinedFunction { .. } => "MIR0003",
1521 IssueKind::UndefinedMethod { .. } => "MIR0004",
1522 IssueKind::PossiblyUndefinedMethod { .. } => "MIR0015",
1523 IssueKind::InvalidDynamicProperty { .. } => "MIR0016",
1524 IssueKind::UndefinedClass { .. } => "MIR0005",
1525 IssueKind::UndefinedProperty { .. } => "MIR0006",
1526 IssueKind::UndefinedConstant { .. } => "MIR0007",
1527 IssueKind::InaccessibleClassConstant { .. } => "MIR0011",
1528 IssueKind::InaccessibleProperty { .. } => "MIR0014",
1529 IssueKind::TraitConstantAccessedDirectly { .. } => "MIR0012",
1530 IssueKind::UndefinedTraitAliasMethod { .. } => "MIR0013",
1531 IssueKind::PossiblyUndefinedVariable { .. } => "MIR0008",
1532 IssueKind::UndefinedTrait { .. } => "MIR0009",
1533 IssueKind::ParentNotFound => "MIR0010",
1534
1535 IssueKind::NullArgument { .. } => "MIR0100",
1537 IssueKind::NullPropertyFetch { .. } => "MIR0101",
1538 IssueKind::NullMethodCall { .. } => "MIR0102",
1539 IssueKind::NullArrayAccess => "MIR0103",
1540 IssueKind::PossiblyNullArgument { .. } => "MIR0104",
1541 IssueKind::PossiblyInvalidArgument { .. } => "MIR0105",
1542 IssueKind::PossiblyNullPropertyFetch { .. } => "MIR0106",
1543 IssueKind::PossiblyNullMethodCall { .. } => "MIR0107",
1544 IssueKind::PossiblyNullArrayAccess => "MIR0108",
1545 IssueKind::NullableReturnStatement { .. } => "MIR0109",
1546 IssueKind::LessSpecificReturnStatement { .. } => "MIR0110",
1547
1548 IssueKind::InvalidReturnType { .. } => "MIR0200",
1550 IssueKind::InvalidArgument { .. } => "MIR0201",
1551 IssueKind::InvalidScalarArgument { .. } => "MIR0238",
1552 IssueKind::TooFewArguments { .. } => "MIR0202",
1553 IssueKind::TooManyArguments { .. } => "MIR0203",
1554 IssueKind::InvalidNamedArgument { .. } => "MIR0204",
1555 IssueKind::InvalidNamedArguments { .. } => "MIR0224",
1556 IssueKind::InvalidPassByReference { .. } => "MIR0205",
1557 IssueKind::InvalidPropertyFetch { .. } => "MIR0218",
1558 IssueKind::InvalidArrayAccess { .. } => "MIR0219",
1559 IssueKind::PossiblyInvalidArrayAccess { .. } => "MIR0227",
1560 IssueKind::InvalidArrayAssignment { .. } => "MIR0220",
1561 IssueKind::InvalidPropertyAssignment { .. } => "MIR0206",
1562 IssueKind::PossiblyNullPropertyAssignmentValue { .. } => "MIR0232",
1563 IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => "MIR0233",
1564 IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => "MIR0234",
1565 IssueKind::InvalidCast { .. } => "MIR0207",
1566 IssueKind::InvalidStaticInvocation { .. } => "MIR0215",
1567 IssueKind::InvalidOperand { .. } => "MIR0208",
1568 IssueKind::PossiblyInvalidOperand { .. } => "MIR0213",
1569 IssueKind::PossiblyNullOperand { .. } => "MIR0214",
1570 IssueKind::DivisionByZero { .. } => "MIR0229",
1571 IssueKind::InvalidMethodCall { .. } => "MIR0230",
1572 IssueKind::InvalidMemberName { .. } => "MIR0235",
1573 IssueKind::NativeResourceType { .. } => "MIR0236",
1574 IssueKind::InvalidUnpack { .. } => "MIR0231",
1575 IssueKind::RawObjectIteration { .. } => "MIR0222",
1576 IssueKind::PossiblyRawObjectIteration { .. } => "MIR0223",
1577 IssueKind::InvalidGeneratorIteration { .. } => "MIR0237",
1578 IssueKind::MismatchingDocblockReturnType { .. } => "MIR0209",
1579 IssueKind::MismatchingDocblockParamType { .. } => "MIR0210",
1580 IssueKind::InvalidStringClass { .. } => "MIR0211",
1581 IssueKind::NotAnInterface { .. } => "MIR0228",
1582 IssueKind::TypeCheckMismatch { .. } => "MIR0212",
1583 IssueKind::Trace { .. } => "MIR0221",
1584 IssueKind::ArgumentTypeCoercion { .. } => "MIR0225",
1585 IssueKind::PropertyTypeCoercion { .. } => "MIR0226",
1586
1587 IssueKind::InvalidArrayOffset { .. } => "MIR0300",
1589 IssueKind::NonExistentArrayOffset { .. } => "MIR0301",
1590 IssueKind::PossiblyInvalidArrayOffset { .. } => "MIR0302",
1591 IssueKind::DuplicateArrayKey { .. } => "MIR0303",
1592
1593 IssueKind::RedundantCondition { .. } => "MIR0400",
1595 IssueKind::RedundantCast { .. } => "MIR0401",
1596 IssueKind::UnnecessaryVarAnnotation { .. } => "MIR0402",
1597 IssueKind::TypeDoesNotContainType { .. } => "MIR0403",
1598 IssueKind::ParadoxicalCondition { .. } => "MIR0404",
1599 IssueKind::UnhandledMatchCondition { .. } => "MIR0405",
1600 IssueKind::DocblockTypeContradiction { .. } => "MIR0406",
1601 IssueKind::UnevaluatedCode { .. } => "MIR0407",
1602 IssueKind::ImpossibleIdenticalComparison { .. } => "MIR0408",
1603 IssueKind::ImpossibleLooseComparison { .. } => "MIR0409",
1604
1605 IssueKind::UnusedVariable { .. } => "MIR0500",
1607 IssueKind::UnusedParam { .. } => "MIR0501",
1608 IssueKind::UnreachableCode => "MIR0502",
1609 IssueKind::UnusedMethod { .. } => "MIR0503",
1610 IssueKind::UnusedProperty { .. } => "MIR0504",
1611 IssueKind::UnusedFunction { .. } => "MIR0505",
1612 IssueKind::UnusedForeachValue { .. } => "MIR0506",
1613 IssueKind::UnusedClass { .. } => "MIR0507",
1614 IssueKind::UnusedSuppress { .. } => "MIR0508",
1615 IssueKind::UnusedConstant { .. } => "MIR0509",
1616
1617 IssueKind::ImpurePropertyAssignment { .. } => "MIR1700",
1619 IssueKind::ImpureMethodCall { .. } => "MIR1701",
1620 IssueKind::ImpureGlobalVariable { .. } => "MIR1702",
1621 IssueKind::ImpureStaticVariable { .. } => "MIR1703",
1622 IssueKind::ImpureStaticPropertyAssignment { .. } => "MIR1706",
1623 IssueKind::ImpureByRefAssignment { .. } => "MIR1707",
1624 IssueKind::ImpureStaticPropertyAccess { .. } => "MIR1708",
1625 IssueKind::ImpureFunctionCall { .. } => "MIR1704",
1626 IssueKind::ImmutablePropertyModification { .. } => "MIR1705",
1627 IssueKind::UnsupportedReferenceUsage => "MIR1506",
1628 IssueKind::NoInterfaceProperties { .. } => "MIR1504",
1629 IssueKind::UndefinedDocblockClass { .. } => "MIR1505",
1630 IssueKind::MissingConstructor { .. } => "MIR1507",
1631 IssueKind::PropertyPossiblyUninitialized { .. } => "MIR1510",
1632 IssueKind::MixedFunctionCall => "MIR1211",
1633 IssueKind::MixedReturnStatement { .. } => "MIR1212",
1634
1635 IssueKind::ReadonlyPropertyAssignment { .. } => "MIR0600",
1637 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => "MIR0601",
1638
1639 IssueKind::UnimplementedAbstractMethod { .. } => "MIR0700",
1641 IssueKind::UnimplementedInterfaceMethod { .. } => "MIR0701",
1642 IssueKind::MethodSignatureMismatch { .. } => "MIR0702",
1643 IssueKind::OverriddenMethodAccess { .. } => "MIR0703",
1644 IssueKind::OverriddenPropertyAccess { .. } => "MIR0710",
1645 IssueKind::PropertyTypeRedeclarationMismatch { .. } => "MIR0712",
1646 IssueKind::BackedEnumCaseTypeMismatch { .. } => "MIR0713",
1647 IssueKind::DuplicateEnumCaseValue { .. } => "MIR0718",
1648 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => "MIR0714",
1649 IssueKind::StaticPropertyRedeclarationMismatch { .. } => "MIR0715",
1650 IssueKind::ReadonlyClassExtendsMismatch { .. } => "MIR0716",
1651 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => "MIR0717",
1652 IssueKind::InvalidExtendClass { .. } => "MIR0704",
1653 IssueKind::FinalMethodOverridden { .. } => "MIR0705",
1654 IssueKind::AbstractInstantiation { .. } => "MIR0706",
1655 IssueKind::AbstractMethodCall { .. } => "MIR0711",
1656 IssueKind::InterfaceInstantiation { .. } => "MIR0709",
1657 IssueKind::EnumInstantiation { .. } => "MIR0719",
1658 IssueKind::TraitInstantiation { .. } => "MIR0720",
1659 IssueKind::NonInvariantDocblockPropertyType { .. } => "MIR0721",
1660 IssueKind::CircularInheritance { .. } => "MIR0707",
1661 IssueKind::InvalidOverride { .. } => "MIR0708",
1662
1663 IssueKind::TaintedMassAssignment { .. } => "MIR0823",
1665 IssueKind::TaintedCommandArgument => "MIR0824",
1666 IssueKind::QuotedShellEscape => "MIR0825",
1667 IssueKind::UnrestrictedFileUpload => "MIR0826",
1668 IssueKind::HostHeaderInjection { .. } => "MIR0827",
1669 IssueKind::TaintedNoSql => "MIR0828",
1670 IssueKind::TaintedRegex => "MIR0843",
1671 IssueKind::TaintedEnvironment => "MIR0844",
1672 IssueKind::UnescapedLikeWildcard => "MIR0845",
1673 IssueKind::UnquotedSqlEscape => "MIR0846",
1674 IssueKind::InsufficientHtmlEscape => "MIR0847",
1675 IssueKind::MissingAuthorizationCheck { .. } => "MIR0848",
1676 IssueKind::UntracedTaint { .. } => "MIR0849",
1677 IssueKind::TaintedCsv => "MIR0829",
1678 IssueKind::TaintedLog => "MIR0830",
1679 IssueKind::ResourceExhaustion { .. } => "MIR0831",
1680 IssueKind::SpoofableClientIp => "MIR0832",
1681 IssueKind::CodeAfterRedirect => "MIR0833",
1682 IssueKind::InsecureCheckResult { .. } => "MIR0834",
1683 IssueKind::LdapAnonymousBind => "MIR0835",
1684 IssueKind::InsecureFilePermissions { .. } => "MIR0836",
1685 IssueKind::HardcodedCredential { .. } => "MIR0837",
1686 IssueKind::InsecureCors => "MIR0838",
1687 IssueKind::PredictableSeed { .. } => "MIR0839",
1688 IssueKind::ObfuscatedCode => "MIR0840",
1689 IssueKind::InsecureTls { .. } => "MIR0841",
1690 IssueKind::TimingUnsafeComparison { .. } => "MIR0842",
1691 IssueKind::TaintedInput { .. } => "MIR0800",
1692 IssueKind::TaintedHtml => "MIR0801",
1693 IssueKind::TaintedSql => "MIR0802",
1694 IssueKind::TaintedShell => "MIR0803",
1695 IssueKind::TaintedLlmPrompt => "MIR0804",
1696 IssueKind::TaintedHeader => "MIR0805",
1697 IssueKind::TaintedCookie => "MIR0806",
1698 IssueKind::TaintedSsrf => "MIR0807",
1699 IssueKind::TaintedLdap => "MIR0808",
1700 IssueKind::TaintedXpath => "MIR0809",
1701 IssueKind::TaintedCallable => "MIR0810",
1702 IssueKind::TaintedFile => "MIR0811",
1703 IssueKind::TaintedInclude => "MIR0812",
1704 IssueKind::TaintedEval => "MIR0813",
1705 IssueKind::TaintedUnserialize => "MIR0814",
1706 IssueKind::MissingSensitiveParameter { .. } => "MIR0822",
1707 IssueKind::UnserializeGadget { .. } => "MIR0821",
1708 IssueKind::UnsafeUnserialize => "MIR0820",
1709 IssueKind::TaintedXml => "MIR0819",
1710 IssueKind::InsecureRandomness { .. } => "MIR0818",
1711 IssueKind::InsecureSessionConfig { .. } => "MIR0817",
1712 IssueKind::WeakCryptography { .. } => "MIR0816",
1713 IssueKind::InsecurePasswordHash { .. } => "MIR0815",
1714
1715 IssueKind::InvalidTemplateParam { .. } => "MIR0900",
1717 IssueKind::ShadowedTemplateParam { .. } => "MIR0901",
1718 IssueKind::IfThisIsMismatch { .. } => "MIR0902",
1719
1720 IssueKind::DeprecatedCall { .. } => "MIR1000",
1722 IssueKind::WrongCaseFunction { .. } => "MIR1009",
1723 IssueKind::WrongCaseMethod { .. } => "MIR1010",
1724 IssueKind::WrongCaseClass { .. } => "MIR1011",
1725 IssueKind::DeprecatedProperty { .. } => "MIR1005",
1726 IssueKind::DeprecatedInterface { .. } => "MIR1006",
1727 IssueKind::DeprecatedTrait { .. } => "MIR1007",
1728 IssueKind::DeprecatedConstant { .. } => "MIR1008",
1729 IssueKind::DeprecatedMethodCall { .. } => "MIR1001",
1730 IssueKind::DeprecatedMethod { .. } => "MIR1002",
1731 IssueKind::DeprecatedClass { .. } => "MIR1003",
1732 IssueKind::InternalMethod { .. } => "MIR1004",
1733 IssueKind::OptionalParameterBeforeRequired { .. } => "MIR1012",
1734 IssueKind::ImplicitlyNullableParameter { .. } => "MIR1013",
1735 IssueKind::DynamicPropertyCreation { .. } => "MIR1014",
1736 IssueKind::DeprecatedSyntax { .. } => "MIR1015",
1737
1738 IssueKind::MissingReturnType { .. } => "MIR1100",
1740 IssueKind::MissingParamType { .. } => "MIR1101",
1741 IssueKind::MissingPropertyType { .. } => "MIR1104",
1742 IssueKind::MissingClosureReturnType => "MIR1105",
1743 IssueKind::MissingThrowsDocblock { .. } => "MIR1102",
1744 IssueKind::InvalidDocblock { .. } => "MIR1103",
1745 IssueKind::UndefinedThrowsDocblock { .. } => "MIR1106",
1746 IssueKind::InvalidDocblockType { .. } => "MIR1107",
1747
1748 IssueKind::MixedArgument { .. } => "MIR1200",
1750 IssueKind::MixedAssignment { .. } => "MIR1201",
1751 IssueKind::MixedMethodCall { .. } => "MIR1202",
1752 IssueKind::MixedPropertyFetch { .. } => "MIR1203",
1753 IssueKind::MixedPropertyAssignment { .. } => "MIR1208",
1754 IssueKind::MixedArrayAccess => "MIR1209",
1755 IssueKind::MixedArrayOffset => "MIR1210",
1756 IssueKind::MixedClone => "MIR1204",
1757 IssueKind::InvalidClone { .. } => "MIR1205",
1758 IssueKind::PossiblyInvalidClone { .. } => "MIR1206",
1759 IssueKind::InvalidToString { .. } => "MIR1207",
1760
1761 IssueKind::InvalidTraitUse { .. } => "MIR1300",
1763 IssueKind::ForbiddenCode { .. } => "MIR1301",
1764
1765 IssueKind::ParseError { .. } => "MIR1400",
1767 IssueKind::CompileError { .. } => "MIR1401",
1768
1769 IssueKind::InvalidAttribute { .. } => "MIR1600",
1771 IssueKind::UndefinedAttributeClass { .. } => "MIR1601",
1772 IssueKind::DuplicateClass { .. } => "MIR1602",
1773 IssueKind::DuplicateInterface { .. } => "MIR1603",
1774 IssueKind::DuplicateTrait { .. } => "MIR1604",
1775 IssueKind::DuplicateEnum { .. } => "MIR1605",
1776 IssueKind::DuplicateFunction { .. } => "MIR1606",
1777
1778 IssueKind::InvalidThrow { .. } => "MIR1500",
1780 IssueKind::InvalidCatch { .. } => "MIR1503",
1781 IssueKind::UnreachableCatch { .. } => "MIR1508",
1782 IssueKind::PluginIssue { .. } => "MIR1509",
1783 IssueKind::ImplicitToStringCast { .. } => "MIR1501",
1784 IssueKind::ImplicitFloatToIntCast { .. } => "MIR1502",
1785 IssueKind::UseStatementHasNoEffect { .. } => "MIR1511",
1786 IssueKind::PrivateFinalMethod { .. } => "MIR1512",
1787 IssueKind::NonPublicMagicMethod { .. } => "MIR1513",
1788 IssueKind::NoDiscardReturnIgnored { .. } => "MIR1514",
1789 IssueKind::AnalyzerError { .. } => "MIR1515",
1790 }
1791 }
1792
1793 pub fn default_severity_for_code(code: &str) -> Option<Severity> {
1799 match code {
1800 "MIR0001" | "MIR0002" | "MIR0003" | "MIR0004" | "MIR0005" | "MIR0007" | "MIR0009"
1802 | "MIR0010" | "MIR0011" | "MIR0012" | "MIR0013" | "MIR0014" | "MIR0016" | "MIR0200"
1803 | "MIR0201" | "MIR0202" | "MIR0203" | "MIR0204" | "MIR0205" | "MIR0212" | "MIR0215"
1804 | "MIR0216" | "MIR0217" | "MIR0224" | "MIR0231" | "MIR0235" | "MIR0236" | "MIR0600"
1805 | "MIR0601" | "MIR0700" | "MIR0701" | "MIR0702" | "MIR0703" | "MIR0704" | "MIR0705"
1806 | "MIR0706" | "MIR0707" | "MIR0708" | "MIR0709" | "MIR0710" | "MIR0711" | "MIR0712"
1807 | "MIR0713" | "MIR0714" | "MIR0715" | "MIR0716" | "MIR0717" | "MIR0718" | "MIR0719"
1808 | "MIR0720" | "MIR0228" | "MIR0229" | "MIR0800" | "MIR0801" | "MIR0802" | "MIR0803"
1809 | "MIR0804" | "MIR0805" | "MIR0806" | "MIR0807" | "MIR0808" | "MIR0809" | "MIR0810"
1810 | "MIR0811" | "MIR0812" | "MIR0813" | "MIR0814" | "MIR0819" | "MIR0900" | "MIR1205"
1811 | "MIR1207" | "MIR1300" | "MIR1400" | "MIR1401" | "MIR1500" | "MIR1503" | "MIR1602"
1812 | "MIR1603" | "MIR1604" | "MIR1605" | "MIR1606" | "MIR0823" | "MIR0824" | "MIR0828"
1813 | "MIR0829" | "MIR0830" | "MIR0843" | "MIR0844" | "MIR1515" => Some(Severity::Error),
1814
1815 "MIR0006" | "MIR0008" | "MIR0100" | "MIR0101" | "MIR0102" | "MIR0103" | "MIR0109"
1817 | "MIR0206" | "MIR0208" | "MIR0211" | "MIR0218" | "MIR0230" | "MIR0219" | "MIR0220"
1818 | "MIR0222" | "MIR0300" | "MIR0301" | "MIR0302" | "MIR0303" | "MIR0404" | "MIR0405"
1819 | "MIR0408" | "MIR0500" | "MIR0506" | "MIR1301" | "MIR1501" | "MIR1502" | "MIR1700"
1820 | "MIR1701" | "MIR1702" | "MIR1703" | "MIR1704" | "MIR1705" | "MIR1706" | "MIR1707"
1821 | "MIR1708" | "MIR1506" | "MIR1106" | "MIR1107" | "MIR1511" | "MIR1512" | "MIR1513"
1822 | "MIR1514" | "MIR0238" | "MIR0815" | "MIR0816" | "MIR0817" | "MIR0818" | "MIR0820"
1823 | "MIR0821" | "MIR0822" | "MIR0825" | "MIR0826" | "MIR0827" | "MIR0831" | "MIR0832"
1824 | "MIR0833" | "MIR0834" | "MIR0835" | "MIR0836" | "MIR0837" | "MIR0838" | "MIR0839"
1825 | "MIR0840" | "MIR0841" | "MIR0842" | "MIR0845" | "MIR0846" | "MIR0847" | "MIR0848"
1826 | "MIR0849" => Some(Severity::Warning),
1827
1828 "MIR0015" | "MIR0104" | "MIR0105" | "MIR0106" | "MIR0107" | "MIR0108" | "MIR0207"
1830 | "MIR0232" | "MIR0233" | "MIR0234" | "MIR0209" | "MIR0210" | "MIR0213" | "MIR0214"
1831 | "MIR0221" | "MIR0223" | "MIR0400" | "MIR0401" | "MIR0402" | "MIR0403" | "MIR0501"
1832 | "MIR0502" | "MIR0503" | "MIR0504" | "MIR0505" | "MIR0507" | "MIR0508" | "MIR0509"
1833 | "MIR0901" | "MIR1000" | "MIR1001" | "MIR1002" | "MIR1003" | "MIR1004" | "MIR1005"
1834 | "MIR1006" | "MIR1007" | "MIR1008" | "MIR1009" | "MIR1010" | "MIR1011" | "MIR1012"
1835 | "MIR1013" | "MIR1014" | "MIR1015" | "MIR1100" | "MIR1101" | "MIR1102" | "MIR1103"
1836 | "MIR1104" | "MIR1105" | "MIR1200" | "MIR1201" | "MIR1202" | "MIR1203" | "MIR1204"
1837 | "MIR1206" | "MIR1208" | "MIR1209" | "MIR1210" | "MIR1211" | "MIR1212" | "MIR1504"
1838 | "MIR1505" | "MIR1507" | "MIR1508" | "MIR1600" | "MIR1601" | "MIR0225" | "MIR0226"
1839 | "MIR0227" | "MIR0406" | "MIR0407" | "MIR0902" | "MIR1510" | "MIR0721" | "MIR0237"
1840 | "MIR0110" => Some(Severity::Info),
1841
1842 _ => None,
1843 }
1844 }
1845
1846 pub fn name(&self) -> &'static str {
1848 match self {
1849 IssueKind::NonStaticSelfCall { .. } => "NonStaticSelfCall",
1850 IssueKind::DirectConstructorCall { .. } => "DirectConstructorCall",
1851 IssueKind::InvalidScope { .. } => "InvalidScope",
1852 IssueKind::UndefinedVariable { .. } => "UndefinedVariable",
1853 IssueKind::UndefinedFunction { .. } => "UndefinedFunction",
1854 IssueKind::UndefinedMethod { .. } => "UndefinedMethod",
1855 IssueKind::PossiblyUndefinedMethod { .. } => "PossiblyUndefinedMethod",
1856 IssueKind::UndefinedClass { .. } => "UndefinedClass",
1857 IssueKind::UndefinedProperty { .. } => "UndefinedProperty",
1858 IssueKind::UndefinedConstant { .. } => "UndefinedConstant",
1859 IssueKind::InaccessibleClassConstant { .. } => "InaccessibleClassConstant",
1860 IssueKind::InaccessibleProperty { .. } => "InaccessibleProperty",
1861 IssueKind::TraitConstantAccessedDirectly { .. } => "TraitConstantAccessedDirectly",
1862 IssueKind::UndefinedTraitAliasMethod { .. } => "UndefinedTraitAliasMethod",
1863 IssueKind::PossiblyUndefinedVariable { .. } => "PossiblyUndefinedVariable",
1864 IssueKind::UndefinedTrait { .. } => "UndefinedTrait",
1865 IssueKind::ParentNotFound => "ParentNotFound",
1866 IssueKind::InvalidStringClass { .. } => "InvalidStringClass",
1867 IssueKind::NotAnInterface { .. } => "NotAnInterface",
1868 IssueKind::NullArgument { .. } => "NullArgument",
1869 IssueKind::NullPropertyFetch { .. } => "NullPropertyFetch",
1870 IssueKind::NullMethodCall { .. } => "NullMethodCall",
1871 IssueKind::NullArrayAccess => "NullArrayAccess",
1872 IssueKind::PossiblyNullArgument { .. } => "PossiblyNullArgument",
1873 IssueKind::PossiblyInvalidArgument { .. } => "PossiblyInvalidArgument",
1874 IssueKind::PossiblyNullPropertyFetch { .. } => "PossiblyNullPropertyFetch",
1875 IssueKind::PossiblyNullMethodCall { .. } => "PossiblyNullMethodCall",
1876 IssueKind::PossiblyNullArrayAccess => "PossiblyNullArrayAccess",
1877 IssueKind::NullableReturnStatement { .. } => "NullableReturnStatement",
1878 IssueKind::InvalidReturnType { .. } => "InvalidReturnType",
1879 IssueKind::InvalidArgument { .. } => "InvalidArgument",
1880 IssueKind::InvalidScalarArgument { .. } => "InvalidScalarArgument",
1881 IssueKind::LessSpecificReturnStatement { .. } => "LessSpecificReturnStatement",
1882 IssueKind::TooFewArguments { .. } => "TooFewArguments",
1883 IssueKind::TooManyArguments { .. } => "TooManyArguments",
1884 IssueKind::InvalidNamedArgument { .. } => "InvalidNamedArgument",
1885 IssueKind::InvalidNamedArguments { .. } => "InvalidNamedArguments",
1886 IssueKind::InvalidPassByReference { .. } => "InvalidPassByReference",
1887 IssueKind::InvalidPropertyFetch { .. } => "InvalidPropertyFetch",
1888 IssueKind::InvalidMethodCall { .. } => "InvalidMethodCall",
1889 IssueKind::InvalidMemberName { .. } => "InvalidMemberName",
1890 IssueKind::NativeResourceType { .. } => "NativeResourceType",
1891 IssueKind::InvalidUnpack { .. } => "InvalidUnpack",
1892 IssueKind::InvalidArrayAccess { .. } => "InvalidArrayAccess",
1893 IssueKind::PossiblyInvalidArrayAccess { .. } => "PossiblyInvalidArrayAccess",
1894 IssueKind::InvalidArrayAssignment { .. } => "InvalidArrayAssignment",
1895 IssueKind::InvalidPropertyAssignment { .. } => "InvalidPropertyAssignment",
1896 IssueKind::PossiblyNullPropertyAssignmentValue { .. } => {
1897 "PossiblyNullPropertyAssignmentValue"
1898 }
1899 IssueKind::PossiblyFalsePropertyAssignmentValue { .. } => {
1900 "PossiblyFalsePropertyAssignmentValue"
1901 }
1902 IssueKind::PossiblyInvalidPropertyAssignmentValue { .. } => {
1903 "PossiblyInvalidPropertyAssignmentValue"
1904 }
1905 IssueKind::InvalidCast { .. } => "InvalidCast",
1906 IssueKind::InvalidStaticInvocation { .. } => "InvalidStaticInvocation",
1907 IssueKind::InvalidOperand { .. } => "InvalidOperand",
1908 IssueKind::PossiblyInvalidOperand { .. } => "PossiblyInvalidOperand",
1909 IssueKind::PossiblyNullOperand { .. } => "PossiblyNullOperand",
1910 IssueKind::DivisionByZero { .. } => "DivisionByZero",
1911 IssueKind::RawObjectIteration { .. } => "RawObjectIteration",
1912 IssueKind::PossiblyRawObjectIteration { .. } => "PossiblyRawObjectIteration",
1913 IssueKind::InvalidGeneratorIteration { .. } => "InvalidGeneratorIteration",
1914 IssueKind::MismatchingDocblockReturnType { .. } => "MismatchingDocblockReturnType",
1915 IssueKind::MismatchingDocblockParamType { .. } => "MismatchingDocblockParamType",
1916 IssueKind::TypeCheckMismatch { .. } => "TypeCheckMismatch",
1917 IssueKind::DocblockTypeContradiction { .. } => "DocblockTypeContradiction",
1918 IssueKind::ImpossibleIdenticalComparison { .. } => "ImpossibleIdenticalComparison",
1919 IssueKind::ImpossibleLooseComparison { .. } => "ImpossibleLooseComparison",
1920 IssueKind::UnevaluatedCode { .. } => "UnevaluatedCode",
1921 IssueKind::IfThisIsMismatch { .. } => "IfThisIsMismatch",
1922 IssueKind::Trace { .. } => "Trace",
1923 IssueKind::InvalidArrayOffset { .. } => "InvalidArrayOffset",
1924 IssueKind::NonExistentArrayOffset { .. } => "NonExistentArrayOffset",
1925 IssueKind::PossiblyInvalidArrayOffset { .. } => "PossiblyInvalidArrayOffset",
1926 IssueKind::DuplicateArrayKey { .. } => "DuplicateArrayKey",
1927 IssueKind::RedundantCondition { .. } => "RedundantCondition",
1928 IssueKind::RedundantCast { .. } => "RedundantCast",
1929 IssueKind::UnnecessaryVarAnnotation { .. } => "UnnecessaryVarAnnotation",
1930 IssueKind::TypeDoesNotContainType { .. } => "TypeDoesNotContainType",
1931 IssueKind::ParadoxicalCondition { .. } => "ParadoxicalCondition",
1932 IssueKind::UnhandledMatchCondition { .. } => "UnhandledMatchCondition",
1933 IssueKind::UnusedVariable { .. } => "UnusedVariable",
1934 IssueKind::UnusedParam { .. } => "UnusedParam",
1935 IssueKind::UnreachableCode => "UnreachableCode",
1936 IssueKind::UnusedMethod { .. } => "UnusedMethod",
1937 IssueKind::UnusedProperty { .. } => "UnusedProperty",
1938 IssueKind::UnusedFunction { .. } => "UnusedFunction",
1939 IssueKind::UnusedForeachValue { .. } => "UnusedForeachValue",
1940 IssueKind::UnusedClass { .. } => "UnusedClass",
1941 IssueKind::UnusedConstant { .. } => "UnusedConstant",
1942 IssueKind::UnusedSuppress { .. } => "UnusedSuppress",
1943 IssueKind::ArgumentTypeCoercion { .. } => "ArgumentTypeCoercion",
1944 IssueKind::PropertyTypeCoercion { .. } => "PropertyTypeCoercion",
1945 IssueKind::ImpurePropertyAssignment { .. } => "ImpurePropertyAssignment",
1946 IssueKind::ImpureMethodCall { .. } => "ImpureMethodCall",
1947 IssueKind::ImpureGlobalVariable { .. } => "ImpureGlobalVariable",
1948 IssueKind::ImpureStaticVariable { .. } => "ImpureStaticVariable",
1949 IssueKind::ImpureByRefAssignment { .. } => "ImpureByRefAssignment",
1950 IssueKind::ImpureStaticPropertyAssignment { .. } => "ImpureStaticPropertyAssignment",
1951 IssueKind::ImpureStaticPropertyAccess { .. } => "ImpureStaticPropertyAccess",
1952 IssueKind::ImpureFunctionCall { .. } => "ImpureFunctionCall",
1953 IssueKind::ImmutablePropertyModification { .. } => "ImmutablePropertyModification",
1954 IssueKind::UnsupportedReferenceUsage => "UnsupportedReferenceUsage",
1955 IssueKind::NoInterfaceProperties { .. } => "NoInterfaceProperties",
1956 IssueKind::UndefinedDocblockClass { .. } => "UndefinedDocblockClass",
1957 IssueKind::MissingConstructor { .. } => "MissingConstructor",
1958 IssueKind::PropertyPossiblyUninitialized { .. } => "PropertyPossiblyUninitialized",
1959 IssueKind::MixedFunctionCall => "MixedFunctionCall",
1960 IssueKind::MixedReturnStatement { .. } => "MixedReturnStatement",
1961 IssueKind::UnimplementedAbstractMethod { .. } => "UnimplementedAbstractMethod",
1962 IssueKind::UnimplementedInterfaceMethod { .. } => "UnimplementedInterfaceMethod",
1963 IssueKind::MethodSignatureMismatch { .. } => "MethodSignatureMismatch",
1964 IssueKind::OverriddenMethodAccess { .. } => "OverriddenMethodAccess",
1965 IssueKind::OverriddenPropertyAccess { .. } => "OverriddenPropertyAccess",
1966 IssueKind::PropertyTypeRedeclarationMismatch { .. } => {
1967 "PropertyTypeRedeclarationMismatch"
1968 }
1969 IssueKind::NonInvariantDocblockPropertyType { .. } => {
1970 "NonInvariantDocblockPropertyType"
1971 }
1972 IssueKind::ReadonlyPropertyRedeclarationMismatch { .. } => {
1973 "ReadonlyPropertyRedeclarationMismatch"
1974 }
1975 IssueKind::StaticPropertyRedeclarationMismatch { .. } => {
1976 "StaticPropertyRedeclarationMismatch"
1977 }
1978 IssueKind::ReadonlyClassExtendsMismatch { .. } => "ReadonlyClassExtendsMismatch",
1979 IssueKind::InvalidReadonlyPropertyDeclaration { .. } => {
1980 "InvalidReadonlyPropertyDeclaration"
1981 }
1982 IssueKind::BackedEnumCaseTypeMismatch { .. } => "BackedEnumCaseTypeMismatch",
1983 IssueKind::DuplicateEnumCaseValue { .. } => "DuplicateEnumCaseValue",
1984 IssueKind::InvalidExtendClass { .. } => "InvalidExtendClass",
1985 IssueKind::FinalMethodOverridden { .. } => "FinalMethodOverridden",
1986 IssueKind::AbstractInstantiation { .. } => "AbstractInstantiation",
1987 IssueKind::AbstractMethodCall { .. } => "AbstractMethodCall",
1988 IssueKind::InterfaceInstantiation { .. } => "InterfaceInstantiation",
1989 IssueKind::EnumInstantiation { .. } => "EnumInstantiation",
1990 IssueKind::TraitInstantiation { .. } => "TraitInstantiation",
1991 IssueKind::InvalidDynamicProperty { .. } => "InvalidDynamicProperty",
1992 IssueKind::InvalidOverride { .. } => "InvalidOverride",
1993 IssueKind::ReadonlyPropertyAssignment { .. } => "ReadonlyPropertyAssignment",
1994 IssueKind::ReadonlyPropertyAlreadyInitialized { .. } => {
1995 "ReadonlyPropertyAlreadyInitialized"
1996 }
1997 IssueKind::InvalidTemplateParam { .. } => "InvalidTemplateParam",
1998 IssueKind::ShadowedTemplateParam { .. } => "ShadowedTemplateParam",
1999 IssueKind::TaintedInput { .. } => "TaintedInput",
2000 IssueKind::TaintedHtml => "TaintedHtml",
2001 IssueKind::TaintedSql => "TaintedSql",
2002 IssueKind::TaintedShell => "TaintedShell",
2003 IssueKind::TaintedLlmPrompt => "TaintedLlmPrompt",
2004 IssueKind::TaintedHeader => "TaintedHeader",
2005 IssueKind::TaintedCookie => "TaintedCookie",
2006 IssueKind::TaintedSsrf => "TaintedSsrf",
2007 IssueKind::TaintedLdap => "TaintedLdap",
2008 IssueKind::TaintedXpath => "TaintedXpath",
2009 IssueKind::TaintedCallable => "TaintedCallable",
2010 IssueKind::TaintedFile => "TaintedFile",
2011 IssueKind::TaintedInclude => "TaintedInclude",
2012 IssueKind::TaintedEval => "TaintedEval",
2013 IssueKind::TaintedUnserialize => "TaintedUnserialize",
2014 IssueKind::TaintedMassAssignment { .. } => "TaintedMassAssignment",
2015 IssueKind::TaintedCommandArgument => "TaintedCommandArgument",
2016 IssueKind::QuotedShellEscape => "QuotedShellEscape",
2017 IssueKind::UnrestrictedFileUpload => "UnrestrictedFileUpload",
2018 IssueKind::HostHeaderInjection { .. } => "HostHeaderInjection",
2019 IssueKind::TaintedNoSql => "TaintedNoSql",
2020 IssueKind::TaintedRegex => "TaintedRegex",
2021 IssueKind::TaintedEnvironment => "TaintedEnvironment",
2022 IssueKind::UnescapedLikeWildcard => "UnescapedLikeWildcard",
2023 IssueKind::UnquotedSqlEscape => "UnquotedSqlEscape",
2024 IssueKind::InsufficientHtmlEscape => "InsufficientHtmlEscape",
2025 IssueKind::MissingAuthorizationCheck { .. } => "MissingAuthorizationCheck",
2026 IssueKind::UntracedTaint { .. } => "UntracedTaint",
2027 IssueKind::TaintedCsv => "TaintedCsv",
2028 IssueKind::TaintedLog => "TaintedLog",
2029 IssueKind::ResourceExhaustion { .. } => "ResourceExhaustion",
2030 IssueKind::SpoofableClientIp => "SpoofableClientIp",
2031 IssueKind::CodeAfterRedirect => "CodeAfterRedirect",
2032 IssueKind::InsecureCheckResult { .. } => "InsecureCheckResult",
2033 IssueKind::LdapAnonymousBind => "LdapAnonymousBind",
2034 IssueKind::InsecureFilePermissions { .. } => "InsecureFilePermissions",
2035 IssueKind::HardcodedCredential { .. } => "HardcodedCredential",
2036 IssueKind::InsecureCors => "InsecureCors",
2037 IssueKind::PredictableSeed { .. } => "PredictableSeed",
2038 IssueKind::ObfuscatedCode => "ObfuscatedCode",
2039 IssueKind::InsecureTls { .. } => "InsecureTls",
2040 IssueKind::TimingUnsafeComparison { .. } => "TimingUnsafeComparison",
2041 IssueKind::MissingSensitiveParameter { .. } => "MissingSensitiveParameter",
2042 IssueKind::UnserializeGadget { .. } => "UnserializeGadget",
2043 IssueKind::UnsafeUnserialize => "UnsafeUnserialize",
2044 IssueKind::TaintedXml => "TaintedXml",
2045 IssueKind::InsecureRandomness { .. } => "InsecureRandomness",
2046 IssueKind::InsecureSessionConfig { .. } => "InsecureSessionConfig",
2047 IssueKind::WeakCryptography { .. } => "WeakCryptography",
2048 IssueKind::InsecurePasswordHash { .. } => "InsecurePasswordHash",
2049 IssueKind::DeprecatedCall { .. } => "DeprecatedCall",
2050 IssueKind::DeprecatedProperty { .. } => "DeprecatedProperty",
2051 IssueKind::DeprecatedConstant { .. } => "DeprecatedConstant",
2052 IssueKind::DeprecatedInterface { .. } => "DeprecatedInterface",
2053 IssueKind::DeprecatedTrait { .. } => "DeprecatedTrait",
2054 IssueKind::DeprecatedMethodCall { .. } => "DeprecatedMethodCall",
2055 IssueKind::DeprecatedMethod { .. } => "DeprecatedMethod",
2056 IssueKind::DeprecatedClass { .. } => "DeprecatedClass",
2057 IssueKind::InternalMethod { .. } => "InternalMethod",
2058 IssueKind::OptionalParameterBeforeRequired { .. } => "OptionalParameterBeforeRequired",
2059 IssueKind::ImplicitlyNullableParameter { .. } => "ImplicitlyNullableParameter",
2060 IssueKind::DeprecatedSyntax { .. } => "DeprecatedSyntax",
2061 IssueKind::DynamicPropertyCreation { .. } => "DynamicPropertyCreation",
2062 IssueKind::MissingReturnType { .. } => "MissingReturnType",
2063 IssueKind::MissingClosureReturnType => "MissingClosureReturnType",
2064 IssueKind::MissingParamType { .. } => "MissingParamType",
2065 IssueKind::MissingPropertyType { .. } => "MissingPropertyType",
2066 IssueKind::InvalidThrow { .. } => "InvalidThrow",
2067 IssueKind::InvalidCatch { .. } => "InvalidCatch",
2068 IssueKind::UnreachableCatch { .. } => "UnreachableCatch",
2069 IssueKind::MissingThrowsDocblock { .. } => "MissingThrowsDocblock",
2070 IssueKind::ImplicitToStringCast { .. } => "ImplicitToStringCast",
2071 IssueKind::ImplicitFloatToIntCast { .. } => "ImplicitFloatToIntCast",
2072 IssueKind::ParseError { .. } => "ParseError",
2073 IssueKind::CompileError { .. } => "CompileError",
2074 IssueKind::InvalidDocblock { .. } => "InvalidDocblock",
2075 IssueKind::UndefinedThrowsDocblock { .. } => "UndefinedThrowsDocblock",
2076 IssueKind::InvalidDocblockType { .. } => "InvalidDocblockType",
2077 IssueKind::MixedArgument { .. } => "MixedArgument",
2078 IssueKind::MixedAssignment { .. } => "MixedAssignment",
2079 IssueKind::MixedMethodCall { .. } => "MixedMethodCall",
2080 IssueKind::MixedPropertyFetch { .. } => "MixedPropertyFetch",
2081 IssueKind::MixedPropertyAssignment { .. } => "MixedPropertyAssignment",
2082 IssueKind::MixedArrayAccess => "MixedArrayAccess",
2083 IssueKind::MixedArrayOffset => "MixedArrayOffset",
2084 IssueKind::MixedClone => "MixedClone",
2085 IssueKind::InvalidClone { .. } => "InvalidClone",
2086 IssueKind::PossiblyInvalidClone { .. } => "PossiblyInvalidClone",
2087 IssueKind::InvalidToString { .. } => "InvalidToString",
2088 IssueKind::CircularInheritance { .. } => "CircularInheritance",
2089 IssueKind::InvalidTraitUse { .. } => "InvalidTraitUse",
2090 IssueKind::ForbiddenCode { .. } => "ForbiddenCode",
2091 IssueKind::WrongCaseFunction { .. } => "WrongCaseFunction",
2092 IssueKind::WrongCaseMethod { .. } => "WrongCaseMethod",
2093 IssueKind::WrongCaseClass { .. } => "WrongCaseClass",
2094 IssueKind::InvalidAttribute { .. } => "InvalidAttribute",
2095 IssueKind::UndefinedAttributeClass { .. } => "UndefinedAttributeClass",
2096 IssueKind::DuplicateClass { .. } => "DuplicateClass",
2097 IssueKind::DuplicateInterface { .. } => "DuplicateInterface",
2098 IssueKind::DuplicateTrait { .. } => "DuplicateTrait",
2099 IssueKind::DuplicateEnum { .. } => "DuplicateEnum",
2100 IssueKind::DuplicateFunction { .. } => "DuplicateFunction",
2101 IssueKind::UseStatementHasNoEffect { .. } => "UseStatementHasNoEffect",
2102 IssueKind::PrivateFinalMethod { .. } => "PrivateFinalMethod",
2103 IssueKind::NonPublicMagicMethod { .. } => "NonPublicMagicMethod",
2104 IssueKind::NoDiscardReturnIgnored { .. } => "NoDiscardReturnIgnored",
2105 IssueKind::AnalyzerError { .. } => "AnalyzerError",
2106 IssueKind::PluginIssue { .. } => "PluginIssue",
2107 }
2108 }
2109
2110 pub fn referenced_symbol(&self) -> Option<String> {
2112 use IssueKind::*;
2113 Some(match self {
2114 UndefinedClass { name }
2115 | UndefinedFunction { name }
2116 | UndefinedConstant { name }
2117 | UndefinedTrait { name }
2118 | UnusedFunction { name }
2119 | DeprecatedCall { name, .. }
2120 | DeprecatedClass { name, .. }
2121 | DeprecatedInterface { name, .. }
2122 | DeprecatedTrait { name, .. } => name.clone(),
2123 UnusedClass { class } => class.clone(),
2124 UndefinedMethod { class, method }
2125 | PossiblyUndefinedMethod { class, method }
2126 | UnusedMethod { class, method }
2127 | InternalMethod { class, method }
2128 | DeprecatedMethod { class, method, .. }
2129 | DeprecatedMethodCall { class, method, .. } => format!("{class}::{method}"),
2130 UndefinedProperty { class, property }
2131 | InaccessibleProperty { class, property }
2132 | UnusedProperty { class, property }
2133 | DeprecatedProperty {
2134 class, property, ..
2135 } => format!("{class}::${property}"),
2136 InaccessibleClassConstant { class, constant }
2137 | UnusedConstant { class, constant }
2138 | DeprecatedConstant {
2139 class, constant, ..
2140 } => format!("{class}::{constant}"),
2141 UndefinedVariable { name }
2142 | PossiblyUndefinedVariable { name }
2143 | UnusedVariable { name } => format!("${name}"),
2144 _ => return None,
2145 })
2146 }
2147
2148 pub fn display_name(&self) -> &str {
2152 match self {
2153 IssueKind::PluginIssue { name, .. } => name,
2154 other => other.name(),
2155 }
2156 }
2157
2158 pub fn message(&self) -> String {
2160 match self {
2161 IssueKind::NonStaticSelfCall { class, method } => {
2162 format!("Non-static method {class}::{method}() cannot be called statically")
2163 }
2164 IssueKind::DirectConstructorCall { class } => {
2165 format!("Cannot call constructor of {class} directly")
2166 }
2167 IssueKind::InvalidScope { in_class } => {
2168 if *in_class {
2169 "$this cannot be used in a static method".to_string()
2170 } else {
2171 "$this cannot be used outside of a class".to_string()
2172 }
2173 }
2174 IssueKind::UndefinedVariable { name } => format!("Variable ${name} is not defined"),
2175 IssueKind::UndefinedFunction { name } => format!("Function {name}() is not defined"),
2176 IssueKind::UndefinedMethod { class, method } => {
2177 format!("Method {class}::{method}() does not exist")
2178 }
2179 IssueKind::PossiblyUndefinedMethod { class, method } => {
2180 format!("Method {class}::{method}() might not exist")
2181 }
2182 IssueKind::UndefinedClass { name } => format!("Class {name} does not exist"),
2183 IssueKind::UndefinedProperty { class, property } => {
2184 format!("Property {class}::${property} does not exist")
2185 }
2186 IssueKind::UndefinedConstant { name } => format!("Constant {name} is not defined"),
2187 IssueKind::InaccessibleClassConstant { class, constant } => {
2188 format!("Cannot access constant {class}::{constant}")
2189 }
2190 IssueKind::InaccessibleProperty { class, property } => {
2191 format!("Cannot access property {class}::${property}")
2192 }
2193 IssueKind::PossiblyUndefinedVariable { name } => {
2194 format!("Variable ${name} might not be defined")
2195 }
2196 IssueKind::UndefinedTrait { name } => format!("Trait {name} does not exist"),
2197 IssueKind::TraitConstantAccessedDirectly {
2198 trait_name,
2199 constant,
2200 } => {
2201 format!("Cannot access trait constant {trait_name}::{constant} directly")
2202 }
2203 IssueKind::UndefinedTraitAliasMethod { trait_name, method } => match trait_name {
2204 Some(t) => {
2205 format!("An alias was defined for {t}::{method} but this method does not exist")
2206 }
2207 None => format!("An alias was defined for {method} but this method does not exist"),
2208 },
2209 IssueKind::ParentNotFound => {
2210 "Cannot use parent:: when current class has no parent".to_string()
2211 }
2212 IssueKind::InvalidStringClass { actual } => {
2213 format!("Dynamic class instantiation requires string or class-string type, got '{actual}'")
2214 }
2215 IssueKind::NotAnInterface { name } => {
2216 format!("{name} is not an interface")
2217 }
2218
2219 IssueKind::NullArgument { param, fn_name } => {
2220 format!("Argument ${param} of {fn_name}() cannot be null")
2221 }
2222 IssueKind::NullPropertyFetch { property } => {
2223 format!("Cannot access property ${property} on null")
2224 }
2225 IssueKind::NullMethodCall { method } => {
2226 format!("Cannot call method {method}() on null")
2227 }
2228 IssueKind::NullArrayAccess => "Cannot access array on null".to_string(),
2229 IssueKind::PossiblyNullArgument { param, fn_name } => {
2230 format!("Argument ${param} of {fn_name}() might be null")
2231 }
2232 IssueKind::PossiblyInvalidArgument {
2233 param,
2234 fn_name,
2235 expected,
2236 actual,
2237 } => {
2238 format!("Argument ${param} of {fn_name}() expects '{expected}', possibly different type '{actual}' provided")
2239 }
2240 IssueKind::PossiblyNullPropertyFetch { property } => {
2241 format!("Cannot access property ${property} on possibly null value")
2242 }
2243 IssueKind::PossiblyNullMethodCall { method } => {
2244 format!("Cannot call method {method}() on possibly null value")
2245 }
2246 IssueKind::PossiblyNullArrayAccess => {
2247 "Cannot access array on possibly null value".to_string()
2248 }
2249 IssueKind::NullableReturnStatement { expected, actual } => {
2250 format!("Return type '{actual}' is not compatible with declared '{expected}'")
2251 }
2252
2253 IssueKind::InvalidReturnType { expected, actual } => {
2254 format!("Return type '{actual}' is not compatible with declared '{expected}'")
2255 }
2256 IssueKind::LessSpecificReturnStatement { expected, actual } => {
2257 format!("Return type '{actual}' is less specific than declared '{expected}'")
2258 }
2259 IssueKind::InvalidScalarArgument {
2260 param,
2261 fn_name,
2262 expected,
2263 actual,
2264 } => {
2265 format!("Argument ${param} of {fn_name}() expects '{expected}', got scalar '{actual}'")
2266 }
2267 IssueKind::InvalidArgument {
2268 param,
2269 fn_name,
2270 expected,
2271 actual,
2272 } => {
2273 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}'")
2274 }
2275 IssueKind::TooFewArguments {
2276 fn_name,
2277 expected,
2278 actual,
2279 } => {
2280 format!(
2281 "Too few arguments for {}(): expected {}, got {}",
2282 fn_name, expected, actual
2283 )
2284 }
2285 IssueKind::TooManyArguments {
2286 fn_name,
2287 expected,
2288 actual,
2289 } => {
2290 format!(
2291 "Too many arguments for {}(): expected {}, got {}",
2292 fn_name, expected, actual
2293 )
2294 }
2295 IssueKind::InvalidNamedArgument {
2296 fn_name,
2297 name,
2298 overwrites: true,
2299 } => {
2300 format!(
2301 "{}() argument ${} overwrites a previous argument",
2302 fn_name, name
2303 )
2304 }
2305 IssueKind::InvalidNamedArgument { fn_name, name, .. } => {
2306 format!("{}() has no parameter named ${}", fn_name, name)
2307 }
2308 IssueKind::InvalidNamedArguments { fn_name } => {
2309 format!("{}() does not accept named arguments", fn_name)
2310 }
2311 IssueKind::InvalidPassByReference { fn_name, param } => {
2312 format!(
2313 "Argument ${} of {}() must be passed by reference",
2314 param, fn_name
2315 )
2316 }
2317 IssueKind::InvalidPropertyFetch { ty } => {
2318 format!("Cannot fetch property on non-object type '{ty}'")
2319 }
2320 IssueKind::InvalidMethodCall { method, ty } => {
2321 format!("Cannot call method {method}() on non-object type '{ty}'")
2322 }
2323 IssueKind::InvalidMemberName { member, ty } if member == "method" => {
2324 format!("Method name must be a string, '{ty}' given")
2325 }
2326 IssueKind::InvalidMemberName { member, ty } => {
2327 format!("Object of type '{ty}' cannot be converted to a {member} name")
2328 }
2329 IssueKind::NativeResourceType { class } => {
2330 format!("'resource' is not a native type; PHP reads it as class '{class}', which no resource satisfies")
2331 }
2332 IssueKind::InvalidUnpack { ty } if ty.is_empty() => {
2333 "Only arrays and Traversables can be unpacked".to_string()
2334 }
2335 IssueKind::InvalidUnpack { ty } => {
2336 format!("Only arrays and Traversables can be unpacked, {ty} given")
2337 }
2338 IssueKind::InvalidArrayAccess { ty } => {
2339 format!("Cannot use [] operator on non-array type '{ty}'")
2340 }
2341 IssueKind::PossiblyInvalidArrayAccess { ty } => {
2342 format!("Possibly invalid array access: '{ty}' might not support []")
2343 }
2344 IssueKind::InvalidArrayAssignment { ty } => {
2345 format!("Cannot use [] assignment on non-array type '{ty}'")
2346 }
2347 IssueKind::InvalidPropertyAssignment {
2348 property,
2349 expected,
2350 actual,
2351 } => {
2352 format!("Property ${property} expects '{expected}', cannot assign '{actual}'")
2353 }
2354 IssueKind::PossiblyNullPropertyAssignmentValue {
2355 property,
2356 expected,
2357 actual,
2358 } => {
2359 format!("Property ${property} expects '{expected}', the assigned '{actual}' might be null")
2360 }
2361 IssueKind::PossiblyFalsePropertyAssignmentValue {
2362 property,
2363 expected,
2364 actual,
2365 } => {
2366 format!("Property ${property} expects '{expected}', the assigned '{actual}' might be false")
2367 }
2368 IssueKind::PossiblyInvalidPropertyAssignmentValue {
2369 property,
2370 expected,
2371 actual,
2372 } => {
2373 format!("Property ${property} expects '{expected}', the assigned '{actual}' might not match")
2374 }
2375 IssueKind::InvalidCast { from, to } => {
2376 format!("Cannot cast '{from}' to '{to}'")
2377 }
2378 IssueKind::InvalidStaticInvocation { class, method } => {
2379 format!("Non-static method {class}::{method}() cannot be called statically")
2380 }
2381 IssueKind::InvalidOperand { op, left, right } => {
2382 if right.is_empty() {
2383 format!("Operator '{op}' not supported for operand of type '{left}'")
2384 } else {
2385 format!("Operator '{op}' not supported between '{left}' and '{right}'")
2386 }
2387 }
2388 IssueKind::PossiblyInvalidOperand { op, left, right } => {
2389 format!("Operator '{op}' might not be supported between '{left}' and '{right}'")
2390 }
2391 IssueKind::PossiblyNullOperand { op, ty } => {
2392 format!("Operator '{op}' operand '{ty}' might be null")
2393 }
2394 IssueKind::DivisionByZero { op } => {
2395 format!("Division by zero: right operand of '{op}' is always 0")
2396 }
2397 IssueKind::RawObjectIteration { ty } => {
2398 format!("Cannot iterate over non-iterable object '{ty}'")
2399 }
2400 IssueKind::PossiblyRawObjectIteration { ty } => {
2401 format!("Cannot iterate over possibly non-iterable object '{ty}'")
2402 }
2403 IssueKind::InvalidGeneratorIteration { ty, send } => {
2404 format!("foreach sends null to '{ty}', but its send type is '{send}'")
2405 }
2406 IssueKind::MismatchingDocblockReturnType { declared, inferred } => {
2407 format!("Docblock return type '{declared}' does not match inferred '{inferred}'")
2408 }
2409 IssueKind::MismatchingDocblockParamType {
2410 param,
2411 declared,
2412 inferred,
2413 } => {
2414 format!(
2415 "Docblock type '{declared}' for ${param} does not match inferred '{inferred}'"
2416 )
2417 }
2418 IssueKind::TypeCheckMismatch {
2419 var,
2420 expected,
2421 actual,
2422 } => {
2423 format!("Type of {var} is expected to be {expected}, got {actual}")
2424 }
2425 IssueKind::Trace {
2426 variable,
2427 type_info,
2428 } => {
2429 format!("Type of ${variable} is {type_info}")
2430 }
2431
2432 IssueKind::InvalidArrayOffset { expected, actual } => {
2433 format!("Array offset expects '{expected}', got '{actual}'")
2434 }
2435 IssueKind::NonExistentArrayOffset { key } => {
2436 format!("Array offset '{key}' does not exist")
2437 }
2438 IssueKind::PossiblyInvalidArrayOffset { expected, actual } => {
2439 format!("Array offset might be invalid: expects '{expected}', got '{actual}'")
2440 }
2441 IssueKind::DuplicateArrayKey { key } => {
2442 format!("Array key {key} is duplicated — the earlier entry is silently overwritten")
2443 }
2444
2445 IssueKind::RedundantCondition {
2446 always_true,
2447 unreachable,
2448 } => match unreachable {
2449 Some(branch) => {
2450 format!("Condition is always {always_true}, so the {branch} is never reached")
2451 }
2452 None => format!("Condition is always {always_true}, so the check is redundant"),
2453 },
2454 IssueKind::RedundantCast { from, to } => {
2455 format!("Casting '{from}' to '{to}' is redundant")
2456 }
2457 IssueKind::UnnecessaryVarAnnotation { var } => {
2458 format!("@var annotation for ${var} is unnecessary")
2459 }
2460 IssueKind::TypeDoesNotContainType { left, right } => {
2461 format!("Type '{left}' can never contain type '{right}'")
2462 }
2463 IssueKind::ParadoxicalCondition { value } => {
2464 format!("Value {value} is duplicated; this branch can never be reached")
2465 }
2466 IssueKind::UnhandledMatchCondition { detail } => {
2467 format!("Unhandled match condition: {detail}")
2468 }
2469 IssueKind::DocblockTypeContradiction { expr, declared } => {
2470 format!("Type '{declared}' makes '{expr}' impossible — this can never hold")
2471 }
2472 IssueKind::ImpossibleIdenticalComparison { op, left, right } => {
2473 let result = if op == "===" { "false" } else { "true" };
2474 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be identical")
2475 }
2476 IssueKind::ImpossibleLooseComparison { op, left, right } => {
2477 let result = if op == "==" { "false" } else { "true" };
2478 format!("'{op}' between '{left}' and '{right}' is always {result} — these types can never be loosely equal")
2479 }
2480 IssueKind::UnevaluatedCode { reason } => reason.clone(),
2481 IssueKind::IfThisIsMismatch {
2482 class,
2483 method,
2484 expected,
2485 actual,
2486 } => {
2487 format!(
2488 "Cannot call {class}::{method}() — @if-this-is requires $this to be '{expected}', but it is '{actual}'"
2489 )
2490 }
2491
2492 IssueKind::UnusedVariable { name } => format!("Variable ${name} is never read"),
2493 IssueKind::UnusedParam { name } => format!("Parameter ${name} is never used"),
2494 IssueKind::UnreachableCode => "Unreachable code detected".to_string(),
2495 IssueKind::UnusedMethod { class, method } => {
2496 format!("Private method {class}::{method}() is never called")
2497 }
2498 IssueKind::UnusedProperty { class, property } => {
2499 format!("Private property {class}::${property} is never read")
2500 }
2501 IssueKind::UnusedFunction { name } => {
2502 format!("Function {name}() is never called")
2503 }
2504 IssueKind::UnusedForeachValue { name } => {
2505 format!("Foreach value ${name} is never read")
2506 }
2507 IssueKind::UnusedClass { class } => {
2508 format!("Class {class} is never referenced")
2509 }
2510 IssueKind::UnusedConstant { class, constant } => {
2511 format!("Private constant {class}::{constant} is never used")
2512 }
2513 IssueKind::UnusedSuppress { kind } => {
2514 format!("Suppress annotation for '{kind}' is never used")
2515 }
2516 IssueKind::ArgumentTypeCoercion {
2517 param,
2518 fn_name,
2519 expected,
2520 actual,
2521 } => {
2522 format!("Argument ${param} of {fn_name}() expects '{expected}', got '{actual}' — coercion may fail at runtime")
2523 }
2524 IssueKind::PropertyTypeCoercion {
2525 property,
2526 expected,
2527 actual,
2528 } => {
2529 format!("Property ${property} expects '{expected}', cannot assign '{actual}' — coercion may fail at runtime")
2530 }
2531 IssueKind::ImpurePropertyAssignment { property } => {
2532 format!("Assigning to property {property} of a parameter in a pure or external-mutation-free context")
2533 }
2534 IssueKind::ImpureMethodCall { method } => {
2535 format!("Calling impure method {method}() in a pure or immutable context")
2536 }
2537 IssueKind::ImpureGlobalVariable { variable } => {
2538 format!("Using global variable ${variable} in a @pure function")
2539 }
2540 IssueKind::ImpureStaticVariable { variable } => {
2541 format!("Using static variable ${variable} in a @pure function")
2542 }
2543 IssueKind::ImpureByRefAssignment { variable } => {
2544 format!("Assigning to by-reference parameter ${variable} in a @pure function")
2545 }
2546 IssueKind::ImpureStaticPropertyAssignment { class, property } => {
2547 format!("Assigning to static property {class}::${property} in a @pure function")
2548 }
2549 IssueKind::ImpureStaticPropertyAccess { class, property } => {
2550 format!("Reading static property {class}::${property} in a @pure function")
2551 }
2552 IssueKind::ImpureFunctionCall { fn_name } => {
2553 format!("Calling impure function {fn_name}() in a @pure function")
2554 }
2555 IssueKind::ImmutablePropertyModification { receiver, property } => {
2556 format!("Assigning to property {property} of {receiver} in an immutable context (@psalm-immutable class or @psalm-mutation-free method)")
2557 }
2558
2559 IssueKind::UnimplementedAbstractMethod { class, method } => {
2560 format!("Class {class} must implement abstract method {method}()")
2561 }
2562 IssueKind::UnimplementedInterfaceMethod {
2563 class,
2564 interface,
2565 method,
2566 } => {
2567 format!("Class {class} must implement {interface}::{method}() from interface")
2568 }
2569 IssueKind::MethodSignatureMismatch {
2570 class,
2571 method,
2572 detail,
2573 } => {
2574 format!("Method {class}::{method}() signature mismatch: {detail}")
2575 }
2576 IssueKind::OverriddenMethodAccess {
2577 class,
2578 method,
2579 parent,
2580 visibility,
2581 } => {
2582 let weaker = if visibility == "public" {
2583 ""
2584 } else {
2585 " or weaker"
2586 };
2587 format!("Access level to {class}::{method}() must be {visibility} (as in class {parent}){weaker}")
2588 }
2589 IssueKind::OverriddenPropertyAccess {
2590 class,
2591 property,
2592 parent,
2593 visibility,
2594 } => {
2595 let weaker = if visibility == "public" {
2596 ""
2597 } else {
2598 " or weaker"
2599 };
2600 format!("Access level to {class}::${property} must be {visibility} (as in class {parent}){weaker}")
2601 }
2602 IssueKind::PropertyTypeRedeclarationMismatch {
2603 class,
2604 property,
2605 parent,
2606 expected,
2607 covariant,
2608 before_php85,
2609 } => {
2610 if expected.is_empty() && *before_php85 {
2611 format!(
2612 "Type of {class}::${property} must not be defined (as in class {parent})"
2613 )
2614 } else if expected.is_empty() {
2615 format!(
2616 "Type of {class}::${property} must be omitted to match the parent definition in class {parent}"
2617 )
2618 } else {
2619 let subtype = if *covariant { "subtype of " } else { "" };
2620 format!(
2621 "Type of {class}::${property} must be {subtype}{expected} (as in class {parent})"
2622 )
2623 }
2624 }
2625 IssueKind::NonInvariantDocblockPropertyType {
2626 class,
2627 property,
2628 parent,
2629 expected,
2630 actual,
2631 } => format!(
2632 "Docblock type '{actual}' of {class}::${property} is not invariant with '{expected}' in class {parent}"
2633 ),
2634 IssueKind::ReadonlyPropertyRedeclarationMismatch {
2635 parent_class,
2636 class,
2637 property,
2638 parent_readonly,
2639 } => {
2640 if *parent_readonly {
2641 format!(
2642 "Cannot redeclare readonly property {parent_class}::${property} as non-readonly {class}::${property}"
2643 )
2644 } else {
2645 format!(
2646 "Cannot redeclare non-readonly property {parent_class}::${property} as readonly {class}::${property}"
2647 )
2648 }
2649 }
2650 IssueKind::StaticPropertyRedeclarationMismatch {
2651 parent_class,
2652 class,
2653 property,
2654 parent_static,
2655 } => {
2656 if *parent_static {
2657 format!(
2658 "Cannot redeclare static property {parent_class}::${property} as non-static {class}::${property}"
2659 )
2660 } else {
2661 format!(
2662 "Cannot redeclare non-static property {parent_class}::${property} as static {class}::${property}"
2663 )
2664 }
2665 }
2666 IssueKind::BackedEnumCaseTypeMismatch {
2667 expected, actual, ..
2668 } => format!("Enum case type {actual} does not match enum backing type {expected}"),
2669 IssueKind::DuplicateEnumCaseValue {
2670 enum_name,
2671 first_case,
2672 case_name,
2673 } => {
2674 format!(
2675 "Duplicate value in enum {enum_name} for cases {first_case} and {case_name}"
2676 )
2677 }
2678 IssueKind::ReadonlyClassExtendsMismatch {
2679 parent,
2680 child,
2681 parent_readonly,
2682 } => {
2683 if *parent_readonly {
2684 format!("Non-readonly class {child} cannot extend readonly class {parent}")
2685 } else {
2686 format!("Readonly class {child} cannot extend non-readonly class {parent}")
2687 }
2688 }
2689 IssueKind::InvalidReadonlyPropertyDeclaration { class, property } => {
2690 format!("Readonly property {class}::${property} cannot have default value")
2691 }
2692 IssueKind::ReadonlyPropertyAssignment {
2693 class,
2694 property,
2695 unset: true,
2696 } => format!("Cannot unset readonly property {class}::${property}"),
2697 IssueKind::ReadonlyPropertyAssignment {
2698 class, property, ..
2699 } => {
2700 format!(
2701 "Cannot assign to readonly property {class}::${property} outside of constructor"
2702 )
2703 }
2704 IssueKind::ReadonlyPropertyAlreadyInitialized { class, property } => {
2705 format!(
2706 "Cannot modify readonly property {class}::${property} — already initialized"
2707 )
2708 }
2709 IssueKind::InvalidExtendClass {
2710 parent,
2711 child,
2712 reason,
2713 } => match reason {
2714 Some(reason) => reason.clone(),
2715 None => format!("Class {child} cannot extend final class {parent}"),
2716 },
2717 IssueKind::InvalidTemplateParam {
2718 name,
2719 expected_bound,
2720 actual,
2721 } => {
2722 if actual.split('|').any(|part| part == "false") {
2723 format!(
2724 "Template type '{name}' inferred as '{actual}' can be false and therefore does not satisfy bound '{expected_bound}'"
2725 )
2726 } else {
2727 format!(
2728 "Template type '{name}' inferred as '{actual}' does not satisfy bound '{expected_bound}'"
2729 )
2730 }
2731 }
2732 IssueKind::ShadowedTemplateParam { name } => {
2733 format!(
2734 "Method template parameter '{name}' shadows class-level template parameter with the same name"
2735 )
2736 }
2737 IssueKind::FinalMethodOverridden {
2738 class,
2739 method,
2740 parent,
2741 } => {
2742 format!("Method {class}::{method}() cannot override final method from {parent}")
2743 }
2744 IssueKind::AbstractInstantiation { class } => {
2745 format!("Cannot instantiate abstract class {class}")
2746 }
2747 IssueKind::AbstractMethodCall { class, method } => {
2748 format!("Cannot call abstract method {class}::{method}()")
2749 }
2750 IssueKind::InterfaceInstantiation { class } => {
2751 format!("Cannot instantiate interface {class}")
2752 }
2753 IssueKind::EnumInstantiation { class } => format!("Cannot instantiate enum {class}"),
2754 IssueKind::TraitInstantiation { class } => format!("Cannot instantiate trait {class}"),
2755 IssueKind::InvalidDynamicProperty { class, property } => {
2756 format!("Cannot create dynamic property {class}::${property}")
2757 }
2758 IssueKind::DynamicPropertyCreation { class, property } => {
2759 format!("Creation of dynamic property {class}::${property} is deprecated")
2760 }
2761 IssueKind::InvalidOverride { class, member } => {
2762 let kind = if member.starts_with('$') {
2763 "property"
2764 } else if member.ends_with("()") {
2765 "method"
2766 } else {
2767 "constant"
2768 };
2769 format!(
2770 "{class}::{member} has #[\\Override] attribute, but no matching parent {kind} exists"
2771 )
2772 }
2773
2774 IssueKind::TaintedInput { sink } => format!("Tainted input reaching sink '{sink}'"),
2775 IssueKind::TaintedHtml => "Tainted HTML output — possible XSS".to_string(),
2776 IssueKind::TaintedSql => "Tainted SQL query — possible SQL injection".to_string(),
2777 IssueKind::TaintedShell => {
2778 "Tainted shell command — possible command injection".to_string()
2779 }
2780 IssueKind::TaintedLlmPrompt => {
2781 "Tainted LLM prompt — possible prompt injection".to_string()
2782 }
2783 IssueKind::TaintedHeader => {
2784 "Tainted HTTP header — possible header injection or open redirect".to_string()
2785 }
2786 IssueKind::TaintedCookie => "Tainted cookie — possible cookie injection".to_string(),
2787 IssueKind::TaintedSsrf => {
2788 "Tainted URL — possible server-side request forgery".to_string()
2789 }
2790 IssueKind::TaintedLdap => "Tainted LDAP query — possible LDAP injection".to_string(),
2791 IssueKind::TaintedXpath => "Tainted XPath query — possible XPath injection".to_string(),
2792 IssueKind::TaintedCallable => {
2793 "Tainted callable — user input chooses the code that runs".to_string()
2794 }
2795 IssueKind::TaintedFile => "Tainted file path — possible path traversal".to_string(),
2796 IssueKind::TaintedInclude => {
2797 "Tainted include path — possible file inclusion".to_string()
2798 }
2799 IssueKind::TaintedEval => "Tainted code — possible code injection".to_string(),
2800 IssueKind::TaintedUnserialize => {
2801 "Tainted unserialize() payload — possible object injection".to_string()
2802 }
2803 IssueKind::TaintedMassAssignment { target } => format!("Tainted {target} — user input chooses what gets overwritten (mass assignment)"),
2804 IssueKind::TaintedCommandArgument => "Tainted command argument can start with '-' — possible argument injection".to_string(),
2805 IssueKind::QuotedShellEscape => "escapeshellarg() result placed inside quotes — its own quotes close them, so the value runs unquoted".to_string(),
2806 IssueKind::UnrestrictedFileUpload => "Uploaded file saved under the client's file name with no extension check — possible web shell upload".to_string(),
2807 IssueKind::HostHeaderInjection { target } => format!("{target} built from the request's Host header — the client can point it at their own server"),
2808 IssueKind::TaintedNoSql => "Tainted NoSQL query — possible NoSQL injection".to_string(),
2809 IssueKind::TaintedRegex => "Tainted regular expression — possible ReDoS or regex injection".to_string(),
2810 IssueKind::TaintedEnvironment => "Tainted environment or PHP setting — the client can switch the app's environment, inject LD_PRELOAD or change PHP's configuration".to_string(),
2811 IssueKind::UnescapedLikeWildcard => "Request data in a LIKE pattern without escaping % and _ — the client can match every row or force a slow scan".to_string(),
2812 IssueKind::UnquotedSqlEscape => "Quote-escaped request data placed in SQL outside quotes — escaping quotes doesn't stop injection there".to_string(),
2813 IssueKind::InsufficientHtmlEscape => "HTML-escaped request data placed where the escaping doesn't protect it — possible XSS".to_string(),
2814 IssueKind::MissingAuthorizationCheck { handler, missing, who } => format!("{handler} changes site state without {missing} — {who} can trigger it"),
2815 IssueKind::UntracedTaint { call, reason } => format!("Tainted data is passed to {call}, which can't be resolved because {reason}, so the sinks behind it aren't checked"),
2816 IssueKind::TaintedCsv => "Tainted CSV field — possible spreadsheet formula injection".to_string(),
2817 IssueKind::TaintedLog => "Tainted log message — possible log injection".to_string(),
2818 IssueKind::ResourceExhaustion { function } => format!("{function}() takes its size, count or duration straight from the request — possible denial of service"),
2819 IssueKind::SpoofableClientIp => "Client IP from a header the client can forge decides a check — possible IP allowlist bypass".to_string(),
2820 IssueKind::CodeAfterRedirect => "Location redirect isn't followed by exit — the code after it still runs".to_string(),
2821 IssueKind::InsecureCheckResult { reason } => format!("Insecure check: {reason}"),
2822 IssueKind::LdapAnonymousBind => "ldap_bind() with a request password that may be empty — an empty password is an anonymous bind, which succeeds".to_string(),
2823 IssueKind::InsecureFilePermissions { reason } => format!("Insecure file permissions: {reason}"),
2824 IssueKind::HardcodedCredential { what } => format!("Hard-coded credential: {what} is written in the source"),
2825 IssueKind::InsecureCors => "CORS reflects the request's Origin while allowing credentials — any site can read authenticated responses".to_string(),
2826 IssueKind::PredictableSeed { function } => format!("{function}() seeds the generator with a guessable value, so every mt_rand() and rand() result after it is predictable"),
2827 IssueKind::ObfuscatedCode => "Code run from decoded data — the shape of a web shell or backdoor".to_string(),
2828 IssueKind::InsecureTls { reason } => format!("TLS verification disabled: {reason} and anyone on the network can intercept the connection"),
2829 IssueKind::TimingUnsafeComparison { what } => format!("{what}, which returns sooner the fewer leading characters match; use hash_equals()"),
2830 IssueKind::MissingSensitiveParameter { param } => format!("Parameter ${param} looks like a secret but lacks #[\\SensitiveParameter], so its value can appear in stack traces and logs"),
2831 IssueKind::UnserializeGadget { class, method } => format!("{class}::{method}() makes a call an unserialized object controls: a dangerous call on its property, a method of any class, or any function"),
2832 IssueKind::UnsafeUnserialize => "unserialize() of non-literal data without allowed_classes can instantiate any class".to_string(),
2833 IssueKind::TaintedXml => "Tainted XML parsed with entity expansion, DTD loading or huge documents enabled — possible XXE or XML denial of service".to_string(),
2834 IssueKind::InsecureRandomness { context } => format!("Insecure randomness: {context} comes from a non-cryptographic generator; use random_bytes() or random_int()"),
2835 IssueKind::InsecureSessionConfig { reason } => format!("Insecure session handling: {reason}"),
2836 IssueKind::WeakCryptography { reason } => format!("Weak cryptography: {reason}"),
2837 IssueKind::InsecurePasswordHash { reason } => format!("Insecure password hashing: {reason}"),
2838
2839 IssueKind::DeprecatedCall { name, message } => {
2840 let base = format!("Call to deprecated function {name}");
2841 append_deprecation_message(base, message)
2842 }
2843 IssueKind::DeprecatedProperty {
2844 class,
2845 property,
2846 message,
2847 } => {
2848 let base = format!("Property {class}::${property} is deprecated");
2849 append_deprecation_message(base, message)
2850 }
2851 IssueKind::DeprecatedConstant {
2852 class,
2853 constant,
2854 message,
2855 } => {
2856 let base = format!("Constant {class}::{constant} is deprecated");
2857 append_deprecation_message(base, message)
2858 }
2859 IssueKind::OptionalParameterBeforeRequired { message }
2860 | IssueKind::ImplicitlyNullableParameter { message }
2861 | IssueKind::DeprecatedSyntax { message } => message.clone(),
2862 IssueKind::DeprecatedInterface { name, message } => {
2863 let base = format!("Interface {name} is deprecated");
2864 append_deprecation_message(base, message)
2865 }
2866 IssueKind::DeprecatedTrait { name, message } => {
2867 let base = format!("Trait {name} is deprecated");
2868 append_deprecation_message(base, message)
2869 }
2870 IssueKind::DeprecatedMethodCall {
2871 class,
2872 method,
2873 message,
2874 } => {
2875 let base = format!("Call to deprecated method {class}::{method}");
2876 append_deprecation_message(base, message)
2877 }
2878 IssueKind::DeprecatedMethod {
2879 class,
2880 method,
2881 message,
2882 } => {
2883 let base = format!("Method {class}::{method}() is deprecated");
2884 append_deprecation_message(base, message)
2885 }
2886 IssueKind::DeprecatedClass { name, message } => {
2887 let base = format!("Class {name} is deprecated");
2888 append_deprecation_message(base, message)
2889 }
2890 IssueKind::InternalMethod { class, method } => {
2891 format!("Method {class}::{method}() is marked @internal")
2892 }
2893 IssueKind::MissingReturnType { fn_name } => {
2894 format!("Function {fn_name}() has no return type annotation")
2895 }
2896 IssueKind::MissingClosureReturnType => {
2897 "Closure has no return type annotation".to_string()
2898 }
2899 IssueKind::MissingParamType { fn_name, param } => {
2900 format!("Parameter ${param} of {fn_name}() has no type annotation")
2901 }
2902 IssueKind::MissingPropertyType { class, property } => {
2903 format!("Property {class}::${property} has no type annotation")
2904 }
2905 IssueKind::InvalidThrow { ty } => {
2906 format!("Thrown type '{ty}' does not extend Throwable")
2907 }
2908 IssueKind::InvalidCatch { ty } => {
2909 format!("Caught type '{ty}' does not extend Throwable")
2910 }
2911 IssueKind::UnreachableCatch { ty, shadowed_by } => {
2912 format!("Catch block for '{ty}' is unreachable — already caught by '{shadowed_by}'")
2913 }
2914 IssueKind::MissingThrowsDocblock { class } => {
2915 format!("Exception {class} is thrown but not declared in @throws")
2916 }
2917 IssueKind::ImplicitToStringCast { class } => {
2918 format!("Class {class} is implicitly cast to string")
2919 }
2920 IssueKind::ImplicitFloatToIntCast { from } => {
2921 format!("Implicit cast from {from} to int truncates the fractional part")
2922 }
2923 IssueKind::ParseError { message, code } => format!("{message} [{code}]"),
2924 IssueKind::CompileError { message, code } => {
2925 format!("{message} [{code}]")
2926 }
2927 IssueKind::InvalidDocblock { message } => message.clone(),
2928 IssueKind::UndefinedThrowsDocblock { name } => {
2929 format!("@throws class '{name}' does not exist")
2930 }
2931 IssueKind::InvalidDocblockType { message } => message.clone(),
2932 IssueKind::MixedArgument { param, fn_name } => {
2933 format!("Argument ${param} of {fn_name}() is mixed")
2934 }
2935 IssueKind::MixedAssignment { var } => {
2936 format!("Variable ${var} is assigned a mixed type")
2937 }
2938 IssueKind::MixedMethodCall { method } => {
2939 format!("Method {method}() called on mixed type")
2940 }
2941 IssueKind::UnsupportedReferenceUsage => {
2942 "Reference assignment is not supported".to_string()
2943 }
2944 IssueKind::NoInterfaceProperties { property } => {
2945 format!("Property ${property} is not defined on this interface")
2946 }
2947 IssueKind::UndefinedDocblockClass { name } => {
2948 format!("Docblock type '{name}' does not exist")
2949 }
2950 IssueKind::MissingConstructor { class } => {
2951 format!("Class {class} has uninitialized properties but no constructor")
2952 }
2953 IssueKind::PropertyPossiblyUninitialized { class, property } => {
2954 format!(
2955 "Property {class}::${property} may be left uninitialized by the constructor"
2956 )
2957 }
2958 IssueKind::MixedFunctionCall => "Cannot call mixed type as a function".to_string(),
2959 IssueKind::MixedReturnStatement { declared } => {
2960 format!("Cannot return a mixed type from function with declared return type '{declared}'")
2961 }
2962 IssueKind::MixedPropertyFetch { property } => {
2963 format!("Property ${property} fetched on mixed type")
2964 }
2965 IssueKind::MixedPropertyAssignment { property } => {
2966 format!("Property ${property} assigned on mixed type")
2967 }
2968 IssueKind::MixedArrayAccess => "Array access on mixed type".to_string(),
2969 IssueKind::MixedArrayOffset => "Mixed type used as array offset".to_string(),
2970 IssueKind::MixedClone => "cannot clone mixed".to_string(),
2971 IssueKind::InvalidClone { ty, reason } => match reason {
2972 CloneFailure::NonObject => format!("cannot clone non-object {ty}"),
2973 CloneFailure::Enum => {
2974 format!("Trying to clone an uncloneable object of class {ty}")
2975 }
2976 CloneFailure::PrivateMethod { owner, scope } => match scope {
2977 Some(scope) => {
2978 format!("Call to private method {owner}::__clone() from scope {scope}")
2979 }
2980 None => format!("Call to private method {owner}::__clone() from global scope"),
2981 },
2982 },
2983 IssueKind::PossiblyInvalidClone { ty } => {
2984 format!("cannot clone possibly non-object {ty}")
2985 }
2986 IssueKind::InvalidToString { class } => {
2987 format!("Method {class}::__toString() must return a string")
2988 }
2989 IssueKind::CircularInheritance { class } => {
2990 format!("Class {class} has a circular inheritance chain")
2991 }
2992 IssueKind::InvalidTraitUse { trait_name, reason } => {
2993 format!("Trait {trait_name} used incorrectly: {reason}")
2994 }
2995 IssueKind::WrongCaseFunction { used, canonical } => {
2996 format!("Function name '{used}' has incorrect casing; use '{canonical}'")
2997 }
2998 IssueKind::WrongCaseMethod {
2999 class,
3000 used,
3001 canonical,
3002 } => {
3003 format!("Method name '{class}::{used}' has incorrect casing; use '{canonical}'")
3004 }
3005 IssueKind::WrongCaseClass { used, canonical } => {
3006 format!("Class name '{used}' has incorrect casing; use '{canonical}'")
3007 }
3008 IssueKind::InvalidAttribute { message } => message.clone(),
3009 IssueKind::UndefinedAttributeClass { name } => {
3010 format!("Attribute class {name} does not exist")
3011 }
3012 IssueKind::ForbiddenCode { message } => message.clone(),
3013 IssueKind::DuplicateClass { name } => {
3014 format!("Class {name} has already been defined")
3015 }
3016 IssueKind::DuplicateInterface { name } => {
3017 format!("Interface {name} has already been defined")
3018 }
3019 IssueKind::DuplicateTrait { name } => {
3020 format!("Trait {name} has already been defined")
3021 }
3022 IssueKind::DuplicateEnum { name } => {
3023 format!("Enum {name} has already been defined")
3024 }
3025 IssueKind::DuplicateFunction { name } => {
3026 format!("Function {name}() has already been defined")
3027 }
3028 IssueKind::UseStatementHasNoEffect { name } => {
3029 format!("The use statement with non-compound name '{name}' has no effect")
3030 }
3031 IssueKind::PrivateFinalMethod { class, method } => {
3032 format!("Private method {class}::{method}() cannot be final as it is never overridden by other classes")
3033 }
3034 IssueKind::NoDiscardReturnIgnored { callee, message } => {
3035 let reason = message.as_deref().map(|m| format!(", {m}")).unwrap_or_default();
3036 format!("The return value of {callee}() should either be used or intentionally ignored by casting it as (void){reason}")
3037 }
3038 IssueKind::NonPublicMagicMethod { class, method } => {
3039 format!("The magic method {class}::{method}() must have public visibility")
3040 }
3041 IssueKind::AnalyzerError { message } => {
3042 format!("mir failed to analyze this file ({message}); please report it")
3043 }
3044 IssueKind::PluginIssue { message, .. } => message.clone(),
3045 }
3046 }
3047}
3048
3049#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3055pub struct TaintStep {
3056 pub label: String,
3058 pub location: Location,
3059}
3060
3061#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3062pub struct Issue {
3063 pub kind: IssueKind,
3064 pub severity: Severity,
3065 pub location: Location,
3066 pub snippet: Option<String>,
3067 pub suppressed: bool,
3068 #[serde(default)]
3070 pub taint_trace: Option<Box<[TaintStep]>>,
3071}
3072
3073impl Issue {
3074 pub fn new(kind: IssueKind, location: Location) -> Self {
3075 let severity = kind.default_severity();
3076 Self {
3077 severity,
3078 kind,
3079 location,
3080 snippet: None,
3081 suppressed: false,
3082 taint_trace: None,
3083 }
3084 }
3085
3086 pub fn with_snippet(mut self, snippet: impl Into<String>) -> Self {
3087 self.snippet = Some(snippet.into());
3088 self
3089 }
3090
3091 pub fn suppress(mut self) -> Self {
3092 self.suppressed = true;
3093 self
3094 }
3095}
3096
3097#[derive(Debug, Default)]
3102pub struct IssueBuffer {
3103 issues: Vec<Issue>,
3104 seen: HashSet<(&'static str, Arc<str>, u32, u16)>,
3105 file_suppressions: Vec<String>,
3107 discard: bool,
3108}
3109
3110impl IssueBuffer {
3111 pub fn new() -> Self {
3112 Self::default()
3113 }
3114
3115 pub fn discarding(mut self) -> Self {
3116 self.discard = true;
3117 self
3118 }
3119
3120 pub fn is_discarding(&self) -> bool {
3121 self.discard
3122 }
3123
3124 pub fn add(&mut self, issue: Issue) {
3125 if self.discard {
3126 return;
3127 }
3128 let key = (
3129 issue.kind.name(),
3130 issue.location.file.clone(),
3131 issue.location.line,
3132 issue.location.col_start,
3133 );
3134 if self.seen.insert(key) {
3135 self.issues.push(issue);
3136 }
3137 }
3138
3139 pub fn any(&self, pred: impl Fn(&Issue) -> bool) -> bool {
3141 self.issues.iter().any(pred)
3142 }
3143
3144 pub fn has_impossible_comparison_within(&self, span: &Location) -> bool {
3147 self.issues.iter().any(|i| {
3148 matches!(
3149 i.kind,
3150 IssueKind::ImpossibleIdenticalComparison { .. }
3151 | IssueKind::ImpossibleLooseComparison { .. }
3152 | IssueKind::DocblockTypeContradiction { .. }
3153 | IssueKind::TypeDoesNotContainType { .. }
3154 ) && i.location.file == span.file
3155 && (i.location.line, i.location.col_start) >= (span.line, span.col_start)
3156 && (i.location.line, i.location.col_start) < (span.line_end, span.col_end)
3157 })
3158 }
3159
3160 pub fn add_suppression(&mut self, name: impl Into<String>) {
3161 self.file_suppressions.push(name.into());
3162 }
3163
3164 pub fn into_issues(self) -> Vec<Issue> {
3166 self.issues
3167 .into_iter()
3168 .filter(|i| !i.suppressed)
3169 .filter(|i| {
3170 !self
3171 .file_suppressions
3172 .iter()
3173 .any(|s| s == i.kind.display_name())
3174 })
3175 .collect()
3176 }
3177
3178 pub fn into_all_issues(self) -> Vec<Issue> {
3183 self.issues
3184 .into_iter()
3185 .map(|mut i| {
3186 if self
3187 .file_suppressions
3188 .iter()
3189 .any(|s| s == i.kind.display_name())
3190 {
3191 i.suppressed = true;
3192 }
3193 i
3194 })
3195 .collect()
3196 }
3197
3198 pub fn suppress_range(&mut self, from: usize, suppressions: &[String]) {
3201 if suppressions.is_empty() {
3202 return;
3203 }
3204 for issue in self.issues[from..].iter_mut() {
3205 if suppressions.iter().any(|s| s == issue.kind.display_name()) {
3206 issue.suppressed = true;
3207 }
3208 }
3209 }
3210
3211 pub fn suppress_range_where(&mut self, from: usize, pred: impl Fn(&Issue) -> bool) {
3213 for issue in self.issues[from..].iter_mut().filter(|i| pred(i)) {
3214 issue.suppressed = true;
3215 }
3216 }
3217
3218 pub fn issue_count(&self) -> usize {
3221 self.issues.len()
3222 }
3223
3224 pub fn truncate_to(&mut self, mark: usize) {
3230 for issue in self.issues.drain(mark..) {
3231 let key = (
3232 issue.kind.name(),
3233 issue.location.file.clone(),
3234 issue.location.line,
3235 issue.location.col_start,
3236 );
3237 self.seen.remove(&key);
3238 }
3239 }
3240
3241 pub fn take_since(&mut self, mark: usize, pred: impl Fn(&IssueKind) -> bool) -> Vec<Issue> {
3243 self.take_range(mark, self.issues.len(), pred)
3244 }
3245
3246 pub fn take_range(
3248 &mut self,
3249 mark: usize,
3250 mut end: usize,
3251 pred: impl Fn(&IssueKind) -> bool,
3252 ) -> Vec<Issue> {
3253 let mut taken = Vec::new();
3254 let mut i = mark;
3255 while i < end {
3256 if pred(&self.issues[i].kind) {
3257 let issue = self.issues.remove(i);
3258 self.seen.remove(&(
3259 issue.kind.name(),
3260 issue.location.file.clone(),
3261 issue.location.line,
3262 issue.location.col_start,
3263 ));
3264 end -= 1;
3265 taken.push(issue);
3266 } else {
3267 i += 1;
3268 }
3269 }
3270 taken
3271 }
3272
3273 pub fn is_empty(&self) -> bool {
3274 self.issues.is_empty()
3275 }
3276
3277 pub fn len(&self) -> usize {
3278 self.issues.len()
3279 }
3280
3281 pub fn error_count(&self) -> usize {
3282 self.issues
3283 .iter()
3284 .filter(|i| !i.suppressed && i.severity == Severity::Error)
3285 .count()
3286 }
3287
3288 pub fn warning_count(&self) -> usize {
3289 self.issues
3290 .iter()
3291 .filter(|i| !i.suppressed && i.severity == Severity::Warning)
3292 .count()
3293 }
3294}
3295
3296#[cfg(test)]
3297mod code_tests {
3298 use super::*;
3299 use std::collections::HashSet;
3300
3301 fn one_of_each() -> Vec<IssueKind> {
3307 let s = || String::new();
3308 vec![
3309 IssueKind::InvalidScope { in_class: false },
3310 IssueKind::NonStaticSelfCall {
3311 class: s(),
3312 method: s(),
3313 },
3314 IssueKind::DirectConstructorCall { class: s() },
3315 IssueKind::UndefinedVariable { name: s() },
3316 IssueKind::UndefinedFunction { name: s() },
3317 IssueKind::UndefinedMethod {
3318 class: s(),
3319 method: s(),
3320 },
3321 IssueKind::PossiblyUndefinedMethod {
3322 class: s(),
3323 method: s(),
3324 },
3325 IssueKind::UndefinedClass { name: s() },
3326 IssueKind::NotAnInterface { name: s() },
3327 IssueKind::UndefinedProperty {
3328 class: s(),
3329 property: s(),
3330 },
3331 IssueKind::UndefinedConstant { name: s() },
3332 IssueKind::InaccessibleClassConstant {
3333 class: s(),
3334 constant: s(),
3335 },
3336 IssueKind::InaccessibleProperty {
3337 class: s(),
3338 property: s(),
3339 },
3340 IssueKind::PossiblyUndefinedVariable { name: s() },
3341 IssueKind::UndefinedTrait { name: s() },
3342 IssueKind::TraitConstantAccessedDirectly {
3343 trait_name: s(),
3344 constant: s(),
3345 },
3346 IssueKind::UndefinedTraitAliasMethod {
3347 trait_name: Some(s()),
3348 method: s(),
3349 },
3350 IssueKind::ParentNotFound,
3351 IssueKind::NullArgument {
3352 param: s(),
3353 fn_name: s(),
3354 },
3355 IssueKind::NullPropertyFetch { property: s() },
3356 IssueKind::NullMethodCall { method: s() },
3357 IssueKind::NullArrayAccess,
3358 IssueKind::PossiblyNullArgument {
3359 param: s(),
3360 fn_name: s(),
3361 },
3362 IssueKind::PossiblyInvalidArgument {
3363 param: s(),
3364 fn_name: s(),
3365 expected: s(),
3366 actual: s(),
3367 },
3368 IssueKind::PossiblyNullPropertyFetch { property: s() },
3369 IssueKind::PossiblyNullMethodCall { method: s() },
3370 IssueKind::PossiblyNullArrayAccess,
3371 IssueKind::NullableReturnStatement {
3372 expected: s(),
3373 actual: s(),
3374 },
3375 IssueKind::InvalidReturnType {
3376 expected: s(),
3377 actual: s(),
3378 },
3379 IssueKind::LessSpecificReturnStatement {
3380 expected: s(),
3381 actual: s(),
3382 },
3383 IssueKind::InvalidArgument {
3384 param: s(),
3385 fn_name: s(),
3386 expected: s(),
3387 actual: s(),
3388 },
3389 IssueKind::InvalidScalarArgument {
3390 param: s(),
3391 fn_name: s(),
3392 expected: s(),
3393 actual: s(),
3394 },
3395 IssueKind::TooFewArguments {
3396 fn_name: s(),
3397 expected: 0,
3398 actual: 0,
3399 },
3400 IssueKind::TooManyArguments {
3401 fn_name: s(),
3402 expected: 0,
3403 actual: 0,
3404 },
3405 IssueKind::InvalidNamedArgument {
3406 fn_name: s(),
3407 name: s(),
3408 overwrites: false,
3409 },
3410 IssueKind::InvalidNamedArguments { fn_name: s() },
3411 IssueKind::InvalidPassByReference {
3412 fn_name: s(),
3413 param: s(),
3414 },
3415 IssueKind::InvalidPropertyFetch { ty: s() },
3416 IssueKind::InvalidMethodCall {
3417 method: s(),
3418 ty: s(),
3419 },
3420 IssueKind::InvalidMemberName {
3421 member: s(),
3422 ty: s(),
3423 },
3424 IssueKind::NativeResourceType { class: s() },
3425 IssueKind::InvalidUnpack { ty: s() },
3426 IssueKind::InvalidArrayAccess { ty: s() },
3427 IssueKind::PossiblyInvalidArrayAccess { ty: s() },
3428 IssueKind::InvalidArrayAssignment { ty: s() },
3429 IssueKind::InvalidPropertyAssignment {
3430 property: s(),
3431 expected: s(),
3432 actual: s(),
3433 },
3434 IssueKind::PossiblyNullPropertyAssignmentValue {
3435 property: s(),
3436 expected: s(),
3437 actual: s(),
3438 },
3439 IssueKind::PossiblyFalsePropertyAssignmentValue {
3440 property: s(),
3441 expected: s(),
3442 actual: s(),
3443 },
3444 IssueKind::PossiblyInvalidPropertyAssignmentValue {
3445 property: s(),
3446 expected: s(),
3447 actual: s(),
3448 },
3449 IssueKind::InvalidCast { from: s(), to: s() },
3450 IssueKind::InvalidStaticInvocation {
3451 class: s(),
3452 method: s(),
3453 },
3454 IssueKind::InvalidOperand {
3455 op: s(),
3456 left: s(),
3457 right: s(),
3458 },
3459 IssueKind::PossiblyInvalidOperand {
3460 op: s(),
3461 left: s(),
3462 right: s(),
3463 },
3464 IssueKind::PossiblyNullOperand { op: s(), ty: s() },
3465 IssueKind::DivisionByZero { op: s() },
3466 IssueKind::RawObjectIteration { ty: s() },
3467 IssueKind::PossiblyRawObjectIteration { ty: s() },
3468 IssueKind::InvalidGeneratorIteration { ty: s(), send: s() },
3469 IssueKind::MismatchingDocblockReturnType {
3470 declared: s(),
3471 inferred: s(),
3472 },
3473 IssueKind::MismatchingDocblockParamType {
3474 param: s(),
3475 declared: s(),
3476 inferred: s(),
3477 },
3478 IssueKind::TypeCheckMismatch {
3479 var: s(),
3480 expected: s(),
3481 actual: s(),
3482 },
3483 IssueKind::Trace {
3484 variable: s(),
3485 type_info: s(),
3486 },
3487 IssueKind::InvalidArrayOffset {
3488 expected: s(),
3489 actual: s(),
3490 },
3491 IssueKind::NonExistentArrayOffset { key: s() },
3492 IssueKind::PossiblyInvalidArrayOffset {
3493 expected: s(),
3494 actual: s(),
3495 },
3496 IssueKind::DuplicateArrayKey { key: s() },
3497 IssueKind::RedundantCondition {
3498 always_true: true,
3499 unreachable: None,
3500 },
3501 IssueKind::RedundantCast { from: s(), to: s() },
3502 IssueKind::UnnecessaryVarAnnotation { var: s() },
3503 IssueKind::TypeDoesNotContainType {
3504 left: s(),
3505 right: s(),
3506 },
3507 IssueKind::UnusedVariable { name: s() },
3508 IssueKind::UnusedParam { name: s() },
3509 IssueKind::UnreachableCode,
3510 IssueKind::UnhandledMatchCondition { detail: s() },
3511 IssueKind::UnusedMethod {
3512 class: s(),
3513 method: s(),
3514 },
3515 IssueKind::UnusedProperty {
3516 class: s(),
3517 property: s(),
3518 },
3519 IssueKind::UnusedFunction { name: s() },
3520 IssueKind::UnusedForeachValue { name: s() },
3521 IssueKind::UnusedClass { class: s() },
3522 IssueKind::UnusedConstant {
3523 class: s(),
3524 constant: s(),
3525 },
3526 IssueKind::UnusedSuppress { kind: s() },
3527 IssueKind::ArgumentTypeCoercion {
3528 param: s(),
3529 fn_name: s(),
3530 expected: s(),
3531 actual: s(),
3532 },
3533 IssueKind::PropertyTypeCoercion {
3534 property: s(),
3535 expected: s(),
3536 actual: s(),
3537 },
3538 IssueKind::ImpurePropertyAssignment { property: s() },
3539 IssueKind::ImpureMethodCall { method: s() },
3540 IssueKind::ImpureGlobalVariable { variable: s() },
3541 IssueKind::ImpureStaticVariable { variable: s() },
3542 IssueKind::ImpureByRefAssignment { variable: s() },
3543 IssueKind::ImpureStaticPropertyAssignment {
3544 class: s(),
3545 property: s(),
3546 },
3547 IssueKind::ImpureStaticPropertyAccess {
3548 class: s(),
3549 property: s(),
3550 },
3551 IssueKind::ImpureFunctionCall { fn_name: s() },
3552 IssueKind::ImmutablePropertyModification {
3553 receiver: s(),
3554 property: s(),
3555 },
3556 IssueKind::ReadonlyPropertyAssignment {
3557 class: s(),
3558 property: s(),
3559 unset: false,
3560 },
3561 IssueKind::ReadonlyPropertyAlreadyInitialized {
3562 class: s(),
3563 property: s(),
3564 },
3565 IssueKind::UnimplementedAbstractMethod {
3566 class: s(),
3567 method: s(),
3568 },
3569 IssueKind::UnimplementedInterfaceMethod {
3570 class: s(),
3571 interface: s(),
3572 method: s(),
3573 },
3574 IssueKind::MethodSignatureMismatch {
3575 class: s(),
3576 method: s(),
3577 detail: s(),
3578 },
3579 IssueKind::OverriddenMethodAccess {
3580 class: s(),
3581 method: s(),
3582 parent: s(),
3583 visibility: s(),
3584 },
3585 IssueKind::OverriddenPropertyAccess {
3586 class: s(),
3587 property: s(),
3588 parent: s(),
3589 visibility: s(),
3590 },
3591 IssueKind::PropertyTypeRedeclarationMismatch {
3592 class: s(),
3593 property: s(),
3594 parent: s(),
3595 expected: s(),
3596 covariant: false,
3597 before_php85: false,
3598 },
3599 IssueKind::NonInvariantDocblockPropertyType {
3600 class: s(),
3601 property: s(),
3602 parent: s(),
3603 expected: s(),
3604 actual: s(),
3605 },
3606 IssueKind::ReadonlyPropertyRedeclarationMismatch {
3607 parent_class: s(),
3608 class: s(),
3609 property: s(),
3610 parent_readonly: true,
3611 },
3612 IssueKind::StaticPropertyRedeclarationMismatch {
3613 parent_class: s(),
3614 class: s(),
3615 property: s(),
3616 parent_static: true,
3617 },
3618 IssueKind::ReadonlyClassExtendsMismatch {
3619 parent: s(),
3620 child: s(),
3621 parent_readonly: true,
3622 },
3623 IssueKind::InvalidReadonlyPropertyDeclaration {
3624 class: s(),
3625 property: s(),
3626 },
3627 IssueKind::BackedEnumCaseTypeMismatch {
3628 enum_name: s(),
3629 case_name: s(),
3630 expected: s(),
3631 actual: s(),
3632 },
3633 IssueKind::DuplicateEnumCaseValue {
3634 enum_name: s(),
3635 first_case: s(),
3636 case_name: s(),
3637 },
3638 IssueKind::InvalidExtendClass {
3639 parent: s(),
3640 child: s(),
3641 reason: None,
3642 },
3643 IssueKind::FinalMethodOverridden {
3644 class: s(),
3645 method: s(),
3646 parent: s(),
3647 },
3648 IssueKind::AbstractInstantiation { class: s() },
3649 IssueKind::AbstractMethodCall {
3650 class: s(),
3651 method: s(),
3652 },
3653 IssueKind::InterfaceInstantiation { class: s() },
3654 IssueKind::EnumInstantiation { class: s() },
3655 IssueKind::TraitInstantiation { class: s() },
3656 IssueKind::InvalidDynamicProperty {
3657 class: s(),
3658 property: s(),
3659 },
3660 IssueKind::DynamicPropertyCreation {
3661 class: s(),
3662 property: s(),
3663 },
3664 IssueKind::InvalidOverride {
3665 class: s(),
3666 member: s(),
3667 },
3668 IssueKind::CircularInheritance { class: s() },
3669 IssueKind::TaintedInput { sink: s() },
3670 IssueKind::TaintedHtml,
3671 IssueKind::TaintedSql,
3672 IssueKind::TaintedShell,
3673 IssueKind::TaintedLlmPrompt,
3674 IssueKind::TaintedHeader,
3675 IssueKind::TaintedCookie,
3676 IssueKind::TaintedSsrf,
3677 IssueKind::TaintedLdap,
3678 IssueKind::TaintedXpath,
3679 IssueKind::TaintedCallable,
3680 IssueKind::TaintedFile,
3681 IssueKind::TaintedInclude,
3682 IssueKind::TaintedEval,
3683 IssueKind::TaintedUnserialize,
3684 IssueKind::InsecurePasswordHash { reason: s() },
3685 IssueKind::WeakCryptography { reason: s() },
3686 IssueKind::InsecureSessionConfig { reason: s() },
3687 IssueKind::InsecureRandomness { context: s() },
3688 IssueKind::TaintedXml,
3689 IssueKind::UnsafeUnserialize,
3690 IssueKind::UnserializeGadget {
3691 class: s(),
3692 method: s(),
3693 },
3694 IssueKind::MissingSensitiveParameter { param: s() },
3695 IssueKind::ObfuscatedCode,
3696 IssueKind::InsecureTls { reason: s() },
3697 IssueKind::TimingUnsafeComparison { what: s() },
3698 IssueKind::PredictableSeed { function: s() },
3699 IssueKind::InsecureCors,
3700 IssueKind::HardcodedCredential { what: s() },
3701 IssueKind::InsecureFilePermissions { reason: s() },
3702 IssueKind::LdapAnonymousBind,
3703 IssueKind::InsecureCheckResult { reason: s() },
3704 IssueKind::CodeAfterRedirect,
3705 IssueKind::SpoofableClientIp,
3706 IssueKind::ResourceExhaustion { function: s() },
3707 IssueKind::TaintedLog,
3708 IssueKind::TaintedCsv,
3709 IssueKind::TaintedNoSql,
3710 IssueKind::TaintedRegex,
3711 IssueKind::TaintedEnvironment,
3712 IssueKind::UnescapedLikeWildcard,
3713 IssueKind::UnquotedSqlEscape,
3714 IssueKind::InsufficientHtmlEscape,
3715 IssueKind::MissingAuthorizationCheck {
3716 handler: s(),
3717 missing: s(),
3718 who: s(),
3719 },
3720 IssueKind::UntracedTaint {
3721 call: s(),
3722 reason: s(),
3723 },
3724 IssueKind::HostHeaderInjection { target: s() },
3725 IssueKind::UnrestrictedFileUpload,
3726 IssueKind::QuotedShellEscape,
3727 IssueKind::TaintedCommandArgument,
3728 IssueKind::TaintedMassAssignment { target: s() },
3729 IssueKind::InvalidTemplateParam {
3730 name: s(),
3731 expected_bound: s(),
3732 actual: s(),
3733 },
3734 IssueKind::ShadowedTemplateParam { name: s() },
3735 IssueKind::DeprecatedCall {
3736 name: s(),
3737 message: None,
3738 },
3739 IssueKind::DeprecatedProperty {
3740 class: s(),
3741 property: s(),
3742 message: None,
3743 },
3744 IssueKind::DeprecatedConstant {
3745 class: s(),
3746 constant: s(),
3747 message: None,
3748 },
3749 IssueKind::OptionalParameterBeforeRequired { message: s() },
3750 IssueKind::ImplicitlyNullableParameter { message: s() },
3751 IssueKind::DeprecatedSyntax { message: s() },
3752 IssueKind::DeprecatedInterface {
3753 name: s(),
3754 message: None,
3755 },
3756 IssueKind::DeprecatedTrait {
3757 name: s(),
3758 message: None,
3759 },
3760 IssueKind::DeprecatedMethodCall {
3761 class: s(),
3762 method: s(),
3763 message: None,
3764 },
3765 IssueKind::DeprecatedMethod {
3766 class: s(),
3767 method: s(),
3768 message: None,
3769 },
3770 IssueKind::DeprecatedClass {
3771 name: s(),
3772 message: None,
3773 },
3774 IssueKind::InternalMethod {
3775 class: s(),
3776 method: s(),
3777 },
3778 IssueKind::MissingReturnType { fn_name: s() },
3779 IssueKind::MissingClosureReturnType,
3780 IssueKind::MissingParamType {
3781 fn_name: s(),
3782 param: s(),
3783 },
3784 IssueKind::MissingPropertyType {
3785 class: s(),
3786 property: s(),
3787 },
3788 IssueKind::MissingThrowsDocblock { class: s() },
3789 IssueKind::InvalidDocblock { message: s() },
3790 IssueKind::UndefinedThrowsDocblock { name: s() },
3791 IssueKind::InvalidDocblockType { message: s() },
3792 IssueKind::MixedArgument {
3793 param: s(),
3794 fn_name: s(),
3795 },
3796 IssueKind::MixedAssignment { var: s() },
3797 IssueKind::MixedMethodCall { method: s() },
3798 IssueKind::UnsupportedReferenceUsage,
3799 IssueKind::NoInterfaceProperties { property: s() },
3800 IssueKind::UndefinedDocblockClass { name: s() },
3801 IssueKind::MissingConstructor { class: s() },
3802 IssueKind::PropertyPossiblyUninitialized {
3803 class: s(),
3804 property: s(),
3805 },
3806 IssueKind::MixedFunctionCall,
3807 IssueKind::MixedReturnStatement { declared: s() },
3808 IssueKind::MixedPropertyFetch { property: s() },
3809 IssueKind::MixedPropertyAssignment { property: s() },
3810 IssueKind::MixedArrayAccess,
3811 IssueKind::MixedArrayOffset,
3812 IssueKind::MixedClone,
3813 IssueKind::InvalidClone {
3814 ty: s(),
3815 reason: CloneFailure::NonObject,
3816 },
3817 IssueKind::PossiblyInvalidClone { ty: s() },
3818 IssueKind::InvalidToString { class: s() },
3819 IssueKind::InvalidTraitUse {
3820 trait_name: s(),
3821 reason: s(),
3822 },
3823 IssueKind::ParseError {
3824 message: s(),
3825 code: s(),
3826 },
3827 IssueKind::CompileError {
3828 message: s(),
3829 code: s(),
3830 },
3831 IssueKind::InvalidThrow { ty: s() },
3832 IssueKind::InvalidCatch { ty: s() },
3833 IssueKind::UnreachableCatch {
3834 ty: s(),
3835 shadowed_by: s(),
3836 },
3837 IssueKind::ImplicitToStringCast { class: s() },
3838 IssueKind::ImplicitFloatToIntCast { from: s() },
3839 IssueKind::WrongCaseFunction {
3840 used: s(),
3841 canonical: s(),
3842 },
3843 IssueKind::WrongCaseMethod {
3844 class: s(),
3845 used: s(),
3846 canonical: s(),
3847 },
3848 IssueKind::WrongCaseClass {
3849 used: s(),
3850 canonical: s(),
3851 },
3852 IssueKind::InvalidAttribute { message: s() },
3853 IssueKind::UndefinedAttributeClass { name: s() },
3854 IssueKind::ForbiddenCode { message: s() },
3855 IssueKind::DuplicateClass { name: s() },
3856 IssueKind::DuplicateInterface { name: s() },
3857 IssueKind::DuplicateTrait { name: s() },
3858 IssueKind::DuplicateEnum { name: s() },
3859 IssueKind::DuplicateFunction { name: s() },
3860 IssueKind::UseStatementHasNoEffect { name: s() },
3861 IssueKind::PrivateFinalMethod {
3862 class: s(),
3863 method: s(),
3864 },
3865 IssueKind::NonPublicMagicMethod {
3866 class: s(),
3867 method: s(),
3868 },
3869 IssueKind::NoDiscardReturnIgnored {
3870 callee: s(),
3871 message: None,
3872 },
3873 IssueKind::AnalyzerError { message: s() },
3874 ]
3875 }
3876
3877 #[test]
3878 fn codes_have_expected_shape() {
3879 for kind in one_of_each() {
3880 let code = kind.code();
3881 assert!(
3882 code.len() == 7
3883 && code.starts_with("MIR")
3884 && code[3..].chars().all(|c| c.is_ascii_digit()),
3885 "code {code:?} for {} does not match MIR####",
3886 kind.name(),
3887 );
3888 }
3889 }
3890
3891 #[test]
3892 fn codes_are_unique() {
3893 let kinds = one_of_each();
3894 let mut seen: HashSet<&'static str> = HashSet::new();
3895 for kind in &kinds {
3896 assert!(
3897 seen.insert(kind.code()),
3898 "duplicate code {} (variant {})",
3899 kind.code(),
3900 kind.name(),
3901 );
3902 }
3903 }
3904
3905 #[test]
3906 fn default_severity_for_code_round_trips() {
3907 for kind in one_of_each() {
3908 let code = kind.code();
3909 assert_eq!(
3910 IssueKind::default_severity_for_code(code),
3911 Some(kind.default_severity()),
3912 "severity mismatch for {code} (variant {})",
3913 kind.name(),
3914 );
3915 }
3916 }
3917
3918 #[test]
3919 fn default_severity_for_code_unknown_returns_none() {
3920 assert_eq!(IssueKind::default_severity_for_code("MIR9999"), None);
3921 assert_eq!(IssueKind::default_severity_for_code(""), None);
3922 assert_eq!(IssueKind::default_severity_for_code("mir0001"), None);
3923 }
3924
3925 #[test]
3928 fn one_of_each_has_every_variant() {
3929 assert_eq!(one_of_each().len(), 232);
3932 }
3933}