@Nullable
  public static MethodReferenceBag getMethodParameterReferenceBag(
      PsiElement psiElement, int wantIndex) {

    PsiElement variableContext = psiElement.getContext();
    if (!(variableContext instanceof ParameterList)) {
      return null;
    }

    ParameterList parameterList = (ParameterList) variableContext;
    if (!(parameterList.getContext() instanceof MethodReference)) {
      return null;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if (currentIndex == null) {
      return null;
    }

    if (wantIndex >= 0 && currentIndex.getIndex() != wantIndex) {
      return null;
    }

    return new MethodReferenceBag(
        parameterList, (MethodReference) parameterList.getContext(), currentIndex);
  }
  public static boolean isFunctionReference(
      PsiElement psiElement, int wantIndex, String... funcName) {

    PsiElement variableContext = psiElement.getContext();
    if (!(variableContext instanceof ParameterList)) {
      return false;
    }

    ParameterList parameterList = (ParameterList) variableContext;
    PsiElement context = parameterList.getContext();
    if (!(context instanceof FunctionReference)) {
      return false;
    }

    FunctionReference methodReference = (FunctionReference) context;
    String name = methodReference.getName();

    if (name == null || !Arrays.asList(funcName).contains(name)) {
      return false;
    }

    ParameterBag currentIndex = getCurrentParameterIndex(psiElement);
    if (currentIndex == null) {
      return false;
    }

    return !(wantIndex >= 0 && currentIndex.getIndex() != wantIndex);
  }
  @Nullable
  public static ParameterBag getCurrentParameterIndex(PsiElement psiElement) {

    if (!(psiElement.getContext() instanceof ParameterList)) {
      return null;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();
    if (!(parameterList.getContext() instanceof ParameterListOwner)) {
      return null;
    }

    return getCurrentParameterIndex(parameterList.getParameters(), psiElement);
  }
  @Nullable
  public static String getMethodParameterAt(@NotNull ParameterList parameterList, int index) {
    PsiElement[] parameters = parameterList.getParameters();

    if (parameters.length < index + 1) {
      return null;
    }

    return getMethodParameter(parameters[index]);
  }
  @Nullable
  public static MethodReference getMethodReferenceWithFirstStringParameter(PsiElement psiElement) {
    if (!PlatformPatterns.psiElement()
        .withParent(StringLiteralExpression.class)
        .inside(ParameterList.class)
        .withLanguage(PhpLanguage.INSTANCE)
        .accepts(psiElement)) {

      return null;
    }

    ParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, ParameterList.class);
    if (parameterList == null) {
      return null;
    }

    if (!(parameterList.getContext() instanceof MethodReference)) {
      return null;
    }

    return (MethodReference) parameterList.getContext();
  }
  /**
   * Extract type hint from method parameter
   *
   * <p>function foo(\FooClass $class)
   */
  @Nullable
  public static String getMethodParameterTypeHint(@NotNull Method method) {
    ParameterList childOfType = PsiTreeUtil.getChildOfType(method, ParameterList.class);
    if (childOfType == null) {
      return null;
    }

    PsiElement[] parameters = childOfType.getParameters();
    if (parameters.length == 0) {
      return null;
    }

    ClassReference classReference = PsiTreeUtil.getChildOfType(parameters[0], ClassReference.class);
    if (classReference == null) {
      return null;
    }

    String fqn = classReference.getFQN();
    if (fqn == null) {
      return null;
    }

    return fqn;
  }
  public static boolean isCallToWithParameter(
      PsiElement psiElement, String className, String methodName, int parameterIndex) {
    if (!(psiElement.getContext() instanceof ParameterList)) {
      return false;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();
    if (parameterList == null || !(parameterList.getContext() instanceof MethodReference)) {
      return false;
    }

    MethodReference method = (MethodReference) parameterList.getContext();
    Symfony2InterfacesUtil interfacesUtil = new Symfony2InterfacesUtil();
    if (!interfacesUtil.isCallTo(method, className, methodName)) {
      return false;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if (currentIndex == null || currentIndex.getIndex() != parameterIndex) {
      return false;
    }

    return true;
  }
  @Nullable
  public static PsiElement getMethodParameterPsiElementAt(
      @Nullable ParameterList parameterList, int index) {

    if (parameterList == null) {
      return null;
    }

    PsiElement[] parameters = parameterList.getParameters();

    if (parameters.length < index + 1) {
      return null;
    }

    return parameters[index];
  }