Skip to content

Commit

Permalink
ObjectMixin: added getSuggestion for forward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 3, 2015
1 parent bdb77b3 commit 6f48d69
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Utils/ObjectMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,27 @@ public static function getExtensionMethod($class, $name)
return $cache = FALSE;
}


/**
* Finds the best suggestion (for 8-bit encoding).
* @return string|NULL
* @internal
*/
public static function getSuggestion(array $items, $value)
{
$norm = preg_replace($re = '#^(get|set|has|is|add)(?=[A-Z])#', '', $value);
$best = NULL;
$min = (strlen($value) / 4 + 1) * 10 + .1;
foreach (array_unique($items) as $item) {
if ($item !== $value && (
($len = levenshtein($item, $value, 10, 11, 10)) < $min
|| ($len = levenshtein(preg_replace($re, '', $item), $norm, 10, 11, 10) + 20) < $min
)) {
$min = $len;
$best = $item;
}
}
return $best;
}

}

0 comments on commit 6f48d69

Please sign in to comment.