void CheckGlobalFunctionCall(BoundGlobalFunctionCall call) { // TODO: regular Roslyn analyzers as part of the referenced assembly if (AnalysisFacts.HasSimpleName(call, out var name) && call.ArgumentsInSourceOrder.Length != 0) { if (name.Equals("printf", StringComparison.OrdinalIgnoreCase) || name.Equals("sprintf", StringComparison.OrdinalIgnoreCase)) { printfCheck(name, call.ArgumentsInSourceOrder); } else if (name.StartsWith("preg_", StringComparison.OrdinalIgnoreCase)) { if (name.Equals("preg_filter", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_grep", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_match_all", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_match", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_replace_callback", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_replace", StringComparison.OrdinalIgnoreCase) || name.Equals("preg_split", StringComparison.OrdinalIgnoreCase)) { // NOTE: `$pattern` is always the 1st argument pcrePatternCheck(name, call.ArgumentsInSourceOrder[0].Value); } } } }
public override T VisitArray(BoundArrayEx x) { if (x.Access.IsNone) { // The expression is not being read. Did you mean to assign it somewhere? _diagnostics.Add(_routine, x.PhpSyntax, ErrorCode.WRN_ExpressionNotRead); } // Check valid types and uniqueness of the keys HashSet <(string, long)> lazyKeyConstSet = null; // Stores canonic string representations of the keys to check for duplicates for (int i = 0; i < x.Items.Length; i++) { var item = x.Items[i]; if (item.Key == null) { continue; } var keyTypeMask = item.Key.TypeRefMask; if (!keyTypeMask.IsAnyType && !keyTypeMask.IsRef) // Disallowing 'mixed' for key type would have caused too many false positives { var valid = !keyTypeMask.IsVoid; foreach (var t in TypeCtx.GetTypes(keyTypeMask)) { valid &= AnalysisFacts.IsValidKeyType(t); } if (!valid) { string keyTypeStr = TypeCtx.ToString(keyTypeMask); _diagnostics.Add(_routine, item.Key.PhpSyntax, ErrorCode.WRN_InvalidArrayKeyType, keyTypeStr); } } if (AnalysisFacts.TryGetCanonicKeyStringConstant(item.Key.ConstantValue, out var keyConst)) { if (lazyKeyConstSet == null) { lazyKeyConstSet = new HashSet <(string, long)>(); } if (!lazyKeyConstSet.Add(keyConst)) { // Duplicate array key: '{0}' _diagnostics.Add( _routine, item.Key.PhpSyntax ?? item.Value.PhpSyntax, ErrorCode.WRN_DuplicateArrayKey, keyConst.Item1 ?? keyConst.Item2.ToString()); } } } return(base.VisitArray(x)); }
public override void GetDiagnostics(DiagnosticBag diagnostic) { if (this.QualifiedName == new QualifiedName(Devsense.PHP.Syntax.Name.AutoloadName)) { if (AnalysisFacts.IsAutoloadDeprecated(this.DeclaringCompilation.Options.LanguageVersion)) { // __autoload is deprecated diagnostic.Add(this, _syntax, Errors.ErrorCode.WRN_SymbolDeprecated, string.Empty, this.QualifiedName, Peachpie.CodeAnalysis.Errors.ErrorStrings.AutoloadDeprecatedMessage); } // __autoload must have exactly one parameter if (_syntax.Signature.FormalParams.Length != 1) { diagnostic.Add(this, _syntax.Signature.Span.ToTextSpan(), Errors.ErrorCode.ERR_MustTakeArgs, "Function", this.QualifiedName.ToString(), 1); } } // base.GetDiagnostics(diagnostic); }