use of com.jetbrains.php.lang.psi.elements.AssignmentExpression in project phpinspectionsea by kalessil.
the class QueryUsageStrategy method apply.
public static void apply(@NotNull MethodReference reference, @NotNull ProblemsHolder holder) {
final String methodName = reference.getName();
if (methodName == null || !methodName.equals("execute")) {
return;
}
final PsiElement[] arguments = reference.getParameters();
if (arguments.length > 0) {
return;
}
/* inspect preceding and succeeding statement */
final PsiElement parent = reference.getParent();
PsiElement predecessor = null;
if (OpenapiTypesUtil.isStatementImpl(parent)) {
predecessor = ((Statement) parent).getPrevPsiSibling();
while (predecessor instanceof PhpDocComment) {
predecessor = ((PhpDocComment) predecessor).getPrevPsiSibling();
}
}
if (null != predecessor && predecessor.getFirstChild() instanceof AssignmentExpression) {
/* predecessor needs to be an assignment */
final AssignmentExpression assignment = (AssignmentExpression) predecessor.getFirstChild();
if (!(assignment.getValue() instanceof MethodReference)) {
return;
}
final MethodReference precedingReference = (MethodReference) assignment.getValue();
if (MethodIdentityUtil.isReferencingMethod(precedingReference, "\\PDO", "prepare")) {
final PsiElement variableAssigned = assignment.getVariable();
final PsiElement variableUsed = reference.getClassReference();
if (variableAssigned != null && variableUsed != null && OpeanapiEquivalenceUtil.areEqual(variableAssigned, variableUsed)) {
holder.registerProblem(reference, message, new UseQueryFix(precedingReference));
}
}
}
}
use of com.jetbrains.php.lang.psi.elements.AssignmentExpression in project phpinspectionsea by kalessil.
the class SlowArrayOperationsInLoopInspector 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 || !functionsSet.contains(functionName)) {
return;
}
PsiElement parent = reference.getParent();
if (!(parent instanceof AssignmentExpression)) {
/* let's focus on assignment expressions */
return;
}
while (parent != null && !(parent instanceof PhpFile)) {
/* terminate if reached callable */
if (parent instanceof Function) {
return;
}
if (OpenapiTypesUtil.isLoop(parent)) {
/* loop test is positive, check pattern */
final PhpPsiElement objContainer = ((AssignmentExpression) reference.getParent()).getVariable();
if (null == objContainer) {
return;
}
/* pattern itself: container overridden */
for (final PsiElement objParameter : reference.getParameters()) {
if (OpeanapiEquivalenceUtil.areEqual(objContainer, objParameter)) {
final String message = messagePattern.replace("%s%", functionName);
holder.registerProblem(reference, message);
return;
}
}
}
parent = parent.getParent();
}
}
};
}
Aggregations