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