final protected function addvf()

in src/BaseCodeBuilder.hack [127:161]


  final protected function addvf(string $code, varray<mixed> $args): this {
    if ($code === null) {
      return $this;
    }
    $code = \vsprintf($code, $args);

    // break into lines and add one by one to handle indentation
    $lines = Str\split($code, "\n");
    $last_line = \array_pop(inout $lines);
    foreach ($lines as $line) {
      $this->addLine($line);
    }

    if (\trim($last_line) === '') {
      return $this;
    }

    // if we're in a new line, insert indentation
    if ($this->isNewLine) {
      if ($this->indentationLevel !== 0) {
        if ($this->config->shouldUseTabs()) {
          $this->code->append(Str\repeat("\t", $this->indentationLevel));
        } else {
          $n =
            $this->config->getSpacesPerIndentation() * $this->indentationLevel;
          $this->code->append(Str\repeat(' ', $n));
        }
      }
      $this->isNewLine = false;
    }

    $this->code->append($last_line);

    return $this;
  }