use of com.jetbrains.php.lang.psi.elements.PhpUnset in project phpinspectionsea by kalessil.
the class UselessUnsetInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
/* foreach is also a case, but there is no way to get flow entry point in actual JB platform API */
return new BasePhpElementVisitor() {
@Override
public void visitPhpMethod(@NotNull Method method) {
this.inspectUsages(method.getParameters(), method);
}
@Override
public void visitPhpFunction(@NotNull Function function) {
this.inspectUsages(function.getParameters(), function);
}
private void inspectUsages(@NotNull Parameter[] parameters, @NotNull PhpScopeHolder scope) {
if (parameters.length > 0) {
final PhpEntryPointInstruction entry = scope.getControlFlow().getEntryPoint();
for (final Parameter parameter : parameters) {
final String parameterName = parameter.getName();
if (!parameterName.isEmpty()) {
for (final PhpAccessVariableInstruction usage : OpenapiControlFlowUtil.getFollowingVariableAccessInstructions(entry, parameterName)) {
final PsiElement expression = usage.getAnchor();
final PsiElement parent = expression.getParent();
if (parent instanceof PhpUnset) {
int unsetParametersCount = ((PhpUnset) parent).getArguments().length;
final PsiElement target = (unsetParametersCount == 1 ? parent : expression);
holder.registerProblem(target, MessagesPresentationUtil.prefixWithEa(message), ProblemHighlightType.LIKE_UNUSED_SYMBOL);
}
}
}
}
}
}
};
}
Aggregations