private static boolean isEmptyArrayConstructor(ExpressionTree arg) { return (arg.is(Tree.Kind.ARRAY_INITIALIZER_FUNCTION, Tree.Kind.ARRAY_INITIALIZER_BRACKET) && ((ArrayInitializerTree) arg).arrayPairs().isEmpty()); }
@Override protected void createIssue(FunctionCallTree tree) { if (!tree.arguments().isEmpty()) { context().newIssue(this, tree, MESSAGE); } }
@Override protected void createIssue(FunctionCallTree tree) { if (!tree.arguments().isEmpty()) { context().newIssue(this, tree, MESSAGE); } }
/** * Raise an issue if the local category is passed as a String. */ private void checkLocalCategoryArgument(SeparatedList<ExpressionTree> arguments) { if (!arguments.isEmpty() && arguments.get(0).is(Kind.REGULAR_STRING_LITERAL)) { String firstArg = ((LiteralTree) arguments.get(0)).value(); String localCategory = firstArg.substring(1, firstArg.length() - 1); if (LOCALE_CATEGORY_CONSTANTS.contains(localCategory)) { context().newIssue(this, arguments.get(0), String.format(MESSAGE_SET_LOCAL_ARG, localCategory)); } } }
/** * Raise an issue if the local category is passed as a String. */ private void checkLocalCategoryArgument(SeparatedList<ExpressionTree> arguments) { if (!arguments.isEmpty() && arguments.get(0).is(Kind.REGULAR_STRING_LITERAL)) { String firstArg = ((LiteralTree) arguments.get(0)).value(); String localCategory = firstArg.substring(1, firstArg.length() - 1); if (LOCALE_CATEGORY_CONSTANTS.contains(localCategory)) { context().newIssue(this, arguments.get(0), String.format(MESSAGE_SET_LOCAL_ARG, localCategory)); } } }
private static boolean isSuspiciousPrepareStatement(FunctionCallTree tree, TreeValues possibleValues) { return PDO_PREPARE_PREDICATE.test(possibleValues) && !tree.arguments().isEmpty() && tree.arguments().get(0).is(Tree.Kind.EXPANDABLE_STRING_LITERAL); }
@Nullable public static ExpressionTree getForCondition(ForStatementTree tree) { if (tree.condition().isEmpty()) { return null; } // in a loop, all conditions are evaluated but only the last one is used as the result return tree.condition().get(tree.condition().size() - 1); }
@Nullable public static ExpressionTree getForCondition(ForStatementTree tree) { if (tree.condition().isEmpty()) { return null; } // in a loop, all conditions are evaluated but only the last one is used as the result return tree.condition().get(tree.condition().size() - 1); }
private static boolean isVariableLengthParameterList(ParameterListTree parameterList) { SeparatedList<ParameterTree> parameters = parameterList.parameters(); if (!parameters.isEmpty()) { ParameterTree lastParameter = parameters.get(parameters.size() - 1); return lastParameter.ellipsisToken() != null; } return false; }
private static boolean isVariableLengthParameterList(ParameterListTree parameterList) { SeparatedList<ParameterTree> parameters = parameterList.parameters(); if (!parameters.isEmpty()) { ParameterTree lastParameter = parameters.get(parameters.size() - 1); return lastParameter.ellipsisToken() != null; } return false; }
@Override protected void createIssue(FunctionCallTree functionCall) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); if (!arguments.isEmpty()) { ExpressionTree firstArgument = arguments.get(0); if (firstArgument.is(Kind.NUMERIC_LITERAL)) { LiteralTree literal = (LiteralTree) firstArgument; if (!"0".equals(literal.value())) { context().newIssue(this, firstArgument, PHP_CODE_MESSAGE); } } } }
@Override protected void createIssue(FunctionCallTree functionCall) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); if (!arguments.isEmpty()) { ExpressionTree firstArgument = arguments.get(0); if (firstArgument.is(Kind.NUMERIC_LITERAL)) { LiteralTree literal = (LiteralTree) firstArgument; if (!"0".equals(literal.value())) { context().newIssue(this, firstArgument, PHP_CODE_MESSAGE); } } } }
private static boolean isSuspiciousGlobalFunction(FunctionCallTree tree) { ExpressionTree callee = tree.callee(); if (callee.is(Tree.Kind.NAMESPACE_NAME)) { String qualifiedNameLowerCase = ((NamespaceNameTree) callee).qualifiedName().toLowerCase(Locale.ENGLISH); if (SUSPICIOUS_GLOBAL_FUNCTIONS.keySet().contains(qualifiedNameLowerCase)) { Integer index = SUSPICIOUS_GLOBAL_FUNCTIONS.get(qualifiedNameLowerCase); return index == null || (tree.arguments().size() > index && !tree.arguments().get(index).is(Tree.Kind.REGULAR_STRING_LITERAL)); } else if ("pg_query".equals(qualifiedNameLowerCase)) { // First argument of function 'pg_query' is optional return !tree.arguments().isEmpty() && !tree.arguments().get(tree.arguments().size() - 1).is(Tree.Kind.REGULAR_STRING_LITERAL); } } return false; }
private void checkPostgresql(FunctionCallTree functionCall) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); if (arguments.isEmpty()) { return; } ExpressionTree connectionString = arguments.get(0); Symbol connectionStringSymbol = context().symbolTable().getSymbol(connectionString); connectionString = assignmentExpressionVisitor .getUniqueAssignedValue(connectionStringSymbol) .orElse(connectionString); checkPostgresqlConnectionString(connectionString); }
private void checkAssertArguments(FunctionCallTree tree) { SeparatedList<ExpressionTree> arguments = tree.arguments(); if (!arguments.isEmpty() && arguments.get(0).is(Kind.REGULAR_STRING_LITERAL, Kind.EXPANDABLE_STRING_LITERAL)) { context().newIssue(this, tree, "Change this call to \"assert\" to not pass a string argument."); } }
private void checkPostgresql(FunctionCallTree functionCall) { SeparatedList<ExpressionTree> arguments = functionCall.arguments(); if (arguments.isEmpty()) { return; } ExpressionTree connectionString = arguments.get(0); Symbol connectionStringSymbol = context().symbolTable().getSymbol(connectionString); connectionString = assignmentExpressionVisitor .getUniqueAssignedValue(connectionStringSymbol) .orElse(connectionString); checkPostgresqlConnectionString(connectionString); }
private void checkAssertArguments(FunctionCallTree tree) { SeparatedList<ExpressionTree> arguments = tree.arguments(); if (!arguments.isEmpty() && arguments.get(0).is(Kind.REGULAR_STRING_LITERAL, Kind.EXPANDABLE_STRING_LITERAL)) { context().newIssue(this, tree, "Change this call to \"assert\" to not pass a string argument."); } }
private void usageForNamespaceName(NamespaceNameTree namespaceName, Symbol.Kind kind) { if (namespaceName.name().is(Tree.Kind.NAME_IDENTIFIER) && namespaceName.namespaces().isEmpty()) { NameIdentifierTree usageIdentifier = (NameIdentifierTree) namespaceName.name(); Symbol symbol = currentScope.getSymbol(usageIdentifier.text(), kind); if (symbol != null) { associateSymbol(usageIdentifier, symbol); } } }