private static function mergeMethodPair()

in src/api-gen/DataMerger.php [467:544]


  private static function mergeMethodPair(
    ScannedMethod $a,
    ScannedDefinition $b,
  ): ScannedMethod {
    $b = $b as ScannedMethod;

    if ($a->isPrivate() || $b->isPrivate()) {
      $visibility = VisibilityToken::T_PRIVATE;
    } else if ($a->isProtected() || $b->isProtected()) {
      $visibility = VisibilityToken::T_PROTECTED;
    } else {
      $visibility = VisibilityToken::T_PUBLIC;
    }
    $a_attributes = $a->getAttributes();

    // Can't give reasonable documentation for this, so mark it as nodoc
    if ($a->isStatic() !== $b->isStatic()) {
      \fprintf(
        \STDERR,
        "\n Warning: Method %s has both a static and non-static ".
        "definition:\n- %s:%d\n- %s:%d\n- NOT DOCUMENTING THIS FUNCTION\n",
        $a->getName(),
        $a->getFileName(),
        $a->getPosition()['line'] ?? 0,
        $b->getFileName(),
        $b->getPosition()['line'] ?? 0,
      );
      $a_attributes['NoDoc'] = Vec\concat(
        $a_attributes['NoDoc'] ?? vec[],
        vec[self::class, 'static and non static definitions'],
      );
    }

    if ($a->isAbstract() !== $b->isAbstract()) {
      \fprintf(
        \STDERR,
        "\nWarning: Method %s has both an abstract and non-abstract ".
        "definition:\n- %s:%d\n- %s:%d\n",
        $a->getName(),
        $a->getFileName(),
        $a->getPosition()['line'] ?? 0,
        $b->getFileName(),
        $b->getPosition()['line'] ?? 0,
      );
    }

    if ($a->isFinal() !== $b->isFinal()) {
      \fprintf(
        \STDERR,
        "\nWarning: Method %s has both a final and non-final definition:\n".
        "- %s:%d\n- %s:%d\n",
        $a->getName(),
        $a->getFileName(),
        $a->getPosition()['line'] ?? 0,
        $b->getFileName(),
        $b->getPosition()['line'] ?? 0,
      );
    }

    return new ScannedMethod(
      $a->getASTx(),
      self::mergeNames($a->getName(), $b->getName()),
      $a->getContext(),
      self::mergeAttributes($a_attributes, $b->getAttributes()),
      self::mergeDocComments($a->getDocComment(), $b->getDocComment()),
      self::mergeGenerics($a->getGenericTypes(), $b->getGenericTypes()),
      self::mergeTypehintPair($a->getReturnType(), $b->getReturnType()),
      self::mergeParameterLists($a->getParameters(), $b->getParameters()),
      $visibility,
      $a->isStatic() ? StaticityToken::IS_STATIC : StaticityToken::NOT_STATIC,
      ($a->isAbstract() || $b->isAbstract())
        ? AbstractnessToken::IS_ABSTRACT
        : AbstractnessToken::NOT_ABSTRACT,
      ($a->isFinal() || $b->isFinal())
        ? FinalityToken::IS_FINAL
        : FinalityToken::NOT_FINAL,
    );
  }