private function generateOldHackDocsData()

in src/build/APILegacyRedirectsBuildStep.php [61:115]


  private function generateOldHackDocsData(): dict<string, string> {
    Log::v("\nProcessing old site index");
    $reader = new PHPDocsIndexReader(\file_get_contents(self::LEGACY_INDEX));
    $old_classes = $reader->getClasses();
    $old_methods = $reader->getMethods();
    $old_functions = $reader->getFunctions();

    Log::v("\nCross-referencing with current site index");

    $old_ids_to_new_urls = dict[];

    $index = APIIndex::get(APIProduct::HACK);

    $classes = (Map {})
      ->setAll($index->getClassIndex(APIDefinitionType::CLASS_DEF))
      ->setAll($index->getClassIndex(APIDefinitionType::INTERFACE_DEF))
      ->setAll($index->getClassIndex(APIDefinitionType::TRAIT_DEF));

    foreach ($classes as $class) {
      Log::v('.');
      $raw_name = $class['name'];
      $old_class_name = $raw_name;
      $old_id = idx($old_classes, $raw_name);

      if ($old_id === null) {
        $name_parts = \explode("\\", $raw_name);
        $no_ns_name = $name_parts[\count($name_parts) - 1];
        $old_class_name = $no_ns_name;
        $old_id = idx($old_classes, $no_ns_name);
      }

      if ($old_id === null) {
        continue;
      }

      $old_ids_to_new_urls[$old_id] = $class['urlPath'];

      foreach ($class['methods'] as $method) {
        $old_id = idx($old_methods, $old_class_name.'::'.$method['name']);
        if ($old_id !== null) {
          $old_ids_to_new_urls[$old_id] = $method['urlPath'];
        }
      }
    }

    foreach ($index->getFunctionIndex() as $function) {
      Log::v('.');
      $old_id = idx($old_functions, $function['name']);
      if ($old_id !== null) {
        $old_ids_to_new_urls[$old_id] = $function['urlPath'];
      }
    }

    return $old_ids_to_new_urls;
  }