private function getSuggestedUrl()

in src/site/controllers/HTTP404Controller.php [33:69]


  private function getSuggestedUrl(string $path): ?string {
    $url = idx(JumpIndexData::getIndex(), strtolower($path));
    if ($url !== null) {
      return $url;
    }

    $url = LegacyRedirects::getUrlForId($path);
    if ($url !== null) {
      return $url;
    }

    $candidates = darray[];
    foreach (APILegacyRedirectData::getIndex() as $id => $url) {
      if (stripos($id, $path) !== false) {
        $candidates[$url] = $url;
      }
    }

    if ($candidates) {
      uksort(
        inout $candidates,
        function(string $a, string $b): int {
          $a = strlen($a);
          $b = strlen($b);
          if ($a > $b) {
            return 1;
          } else if ($a < $b) {
            return -1;
          }
          return 0;
        },
      );
      return C\first_key($candidates);
    }

    return null;
  }