use of com.jetbrains.php.lang.psi.elements.ArrayIndex in project phpinspectionsea by kalessil.
the class ArrayPushMissUseInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpFunctionCall(@NotNull FunctionReference reference) {
final String functionName = reference.getName();
if (functionName != null && functionName.equals("array_push")) {
final PsiElement[] arguments = reference.getParameters();
if (arguments.length == 2 && OpenapiTypesUtil.isStatementImpl(reference.getParent())) {
PsiElement variadicCandidate = arguments[1].getPrevSibling();
if (variadicCandidate instanceof PsiWhiteSpace) {
variadicCandidate = variadicCandidate.getPrevSibling();
}
if (!OpenapiTypesUtil.is(variadicCandidate, PhpTokenTypes.opVARIADIC)) {
final String replacement = String.format("%s[] = %s", arguments[0].getText(), arguments[1].getText());
holder.registerProblem(reference, String.format(MessagesPresentationUtil.prefixWithEa(messageMisuse), replacement), new UseElementPushFix(replacement));
}
}
}
}
@Override
public void visitPhpArrayAccessExpression(@NotNull ArrayAccessExpression expression) {
if (REPORT_EXCESSIVE_COUNT_CALLS) {
final PsiElement parent = expression.getParent();
if (OpenapiTypesUtil.isAssignment(parent)) {
final PsiElement value = ((AssignmentExpression) parent).getValue();
if (value != expression) {
final ArrayIndex index = expression.getIndex();
if (index != null) {
final PsiElement candidate = index.getValue();
if (OpenapiTypesUtil.isFunctionReference(candidate)) {
final FunctionReference reference = (FunctionReference) candidate;
final String functionName = reference.getName();
if (functionName != null && functionName.equals("count")) {
final PsiElement[] arguments = reference.getParameters();
if (arguments.length == 1) {
final PsiElement container = expression.getValue();
if (container != null && OpenapiEquivalenceUtil.areEqual(container, arguments[0])) {
holder.registerProblem(reference, MessagesPresentationUtil.prefixWithEa(messageUnneeded), ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
}
}
}
}
}
}
};
}
Aggregations