Latte\Helpers::getSuggestion PHP Method

getSuggestion() public static method

Finds the best suggestion.
public static getSuggestion ( array $items, $value ) : string | null
$items array
return string | null
    public static function getSuggestion(array $items, $value)
    {
        $best = NULL;
        $min = (strlen($value) / 4 + 1) * 10 + 0.1;
        foreach (array_unique($items, SORT_REGULAR) as $item) {
            $item = is_object($item) ? $item->getName() : $item;
            if (($len = levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
                $min = $len;
                $best = $item;
            }
        }
        return $best;
    }

Usage Example

Beispiel #1
0
 /**
  * Access to undeclared property.
  * @throws LogicException
  */
 public function __set($name, $value)
 {
     $rc = new \ReflectionClass($this);
     $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
     $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean \${$t}?" : '.';
     throw new LogicException("Attempt to write to undeclared property {$rc->getName()}::\${$name}{$hint}");
 }
All Usage Examples Of Latte\Helpers::getSuggestion