code: public static function findUniqueName($name, array $claimed)
      {
          $ext = pathinfo($name, \PATHINFO_EXTENSION);
          $basename = substr($name, 0, -strlen('.'.$ext));
  
          $i = 0;
          while (in_array($name, $claimed)) {
              $i++;
              $name = $basename.'-'.$i.'.'.$ext;
          }
  
          return $name;
      }
docs: @param string $name    The name to make unique
  @param array  $claimed Names already in use to avoid
  
  @return string A unique name