use of com.jetbrains.php.codeInsight.controlFlow.instructions.PhpExitPointInstruction in project phpinspectionsea by kalessil.
the class MultipleReturnStatementsInspector method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpMethod(@NotNull Method method) {
final PsiElement nameIdentifier = NamedElementUtil.getNameIdentifier(method);
if (nameIdentifier != null && !method.isAbstract()) {
final PhpExitPointInstruction exitPoint = method.getControlFlow().getExitPoint();
int returnsCount = 0;
for (final PhpInstruction instruction : OpenapiElementsUtil.getPredecessors(exitPoint)) {
if (instruction instanceof PhpReturnInstruction) {
++returnsCount;
}
}
if (returnsCount >= SCREAM_THRESHOLD) {
holder.registerProblem(nameIdentifier, String.format(MessagesPresentationUtil.prefixWithEa(messagePattern), returnsCount), ProblemHighlightType.GENERIC_ERROR);
} else if (returnsCount >= COMPLAIN_THRESHOLD) {
holder.registerProblem(nameIdentifier, String.format(MessagesPresentationUtil.prefixWithEa(messagePattern), returnsCount), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
}
};
}
Aggregations