original_string: protected function findClosestItem($needle, $haystack)
      {
          $bestGuess = null;
          foreach ($haystack as $item) {
              if (preg_match('/^' . $needle . '/', $item)) {
                  return $item;
              }
          }
  
          foreach ($haystack as $item) {
              if (preg_match('/' . $needle . '/', $item)) {
                  return $item;
              }
  
              $score = levenshtein($needle, $item);
  
              if (!isset($bestScore) || $score < $bestScore) {
                  $bestScore = $score;
                  $bestGuess = $item;
              }
          }
  
          return $bestGuess;
      }
code: protected function findClosestItem($needle, $haystack)
      {
          $bestGuess = null;
          foreach ($haystack as $item) {
              if (preg_match('/^' . $needle . '/', $item)) {
                  return $item;
              }
          }
  
          foreach ($haystack as $item) {
              if (preg_match('/' . $needle . '/', $item)) {
                  return $item;
              }
  
              $score = levenshtein($needle, $item);
  
              if (!isset($bestScore) || $score < $bestScore) {
                  $bestScore = $score;
                  $bestGuess = $item;
              }
          }
  
          return $bestGuess;
      }
code_tokens: protected function findClosestItem ( $ needle , $ haystack ) { $ bestGuess = null ; foreach ( $ haystack as $ item ) { if ( preg_match ( '/^' . $ needle . '/' , $ item ) ) { return $ item ; } } foreach ( $ haystack as $ item ) { if ( preg_match ( '/' . $ needle . '/' , $ item ) ) { return $ item ; } $ score = levenshtein ( $ needle , $ item ) ; if ( ! isset ( $ bestScore ) || $ score < $ bestScore ) { $ bestScore = $ score ; $ bestGuess = $ item ; } } return $ bestGuess ; }
docstring: Tries to guess the item name the user originally wanted using the some regex pattern and the levenshtein
  algorithm.
  
  @param string $needle Unknown item (either a subcommand name or an option for instance) trying to be used.
  @param string[] $haystack List of items available for the type $needle belongs to.
  @return string|null The closest name to the item submitted by the user.
docstring_tokens: Tries to guess the item name the user originally wanted using the some regex pattern and the levenshtein algorithm .