function stringify_parameter()

in src/PageSections/_Private/stringify_parameter.hack [17:51]


function stringify_parameter(
  string $ns,
  ScannedParameter $parameter,
  ?DocBlock\ParameterInfo $docs,
): string {
  $s = '';

  if ($parameter->isInOut()) {
    $s .= 'inout ';
  }

  $types = $docs['types'] ?? vec[];
  $typehint = $parameter->getTypehint();
  if ($types) {
    $s .= Str\join($types, '|').' ';
  } else if ($typehint) {
    $s .= stringify_typehint($ns, $typehint).' ';
  }

  if ($parameter->isVariadic()) {
    $s .= '...';
  }
  $s .= '$'.$parameter->getName();

  if ($parameter->isOptional()) {
    $default = TypeAssert\not_null($parameter->getDefault());
    if ($default->hasStaticValue()) {
      $s .= ' = '.\var_export($default->getStaticValue(), true);
    } else {
      $s .= ' = '.Str\trim($default->getAST()->getCode());
    }
  }

  return $s;
}