mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 06:07:39 +02:00
Helpers::getSuggestion(): support for reflection objects moved to Strict
This commit is contained in:
@@ -143,8 +143,7 @@ class Helpers
|
||||
{
|
||||
$best = null;
|
||||
$min = (strlen($value) / 4 + 1) * 10 + .1;
|
||||
foreach (array_unique($items, SORT_REGULAR) as $item) {
|
||||
$item = is_object($item) ? $item->getName() : $item;
|
||||
foreach (array_unique($items) as $item) {
|
||||
if (($len = levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
|
||||
$min = $len;
|
||||
$best = $item;
|
||||
|
@@ -31,6 +31,7 @@ trait Strict
|
||||
{
|
||||
$class = method_exists($this, $name) ? 'parent' : get_class($this);
|
||||
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
$items = array_map(function ($item) { return $item->getName(); }, $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $t()?" : '.';
|
||||
throw new \LogicException("Call to undefined method $class::$name()$hint");
|
||||
}
|
||||
@@ -44,6 +45,7 @@ trait Strict
|
||||
{
|
||||
$rc = new ReflectionClass(get_called_class());
|
||||
$items = array_intersect($rc->getMethods(ReflectionMethod::IS_PUBLIC), $rc->getMethods(ReflectionMethod::IS_STATIC));
|
||||
$items = array_map(function ($item) { return $item->getName(); }, $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $t()?" : '.';
|
||||
throw new \LogicException("Call to undefined static method {$rc->getName()}::$name()$hint");
|
||||
}
|
||||
@@ -63,6 +65,7 @@ trait Strict
|
||||
}
|
||||
$rc = new ReflectionClass($this);
|
||||
$items = array_diff($rc->getProperties(ReflectionProperty::IS_PUBLIC), $rc->getProperties(ReflectionProperty::IS_STATIC));
|
||||
$items = array_map(function ($item) { return $item->getName(); }, $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $$t?" : '.';
|
||||
throw new \LogicException("Attempt to read undeclared property {$rc->getName()}::$$name$hint");
|
||||
}
|
||||
@@ -76,6 +79,7 @@ trait Strict
|
||||
{
|
||||
$rc = new ReflectionClass($this);
|
||||
$items = array_diff($rc->getProperties(ReflectionProperty::IS_PUBLIC), $rc->getProperties(ReflectionProperty::IS_STATIC));
|
||||
$items = array_map(function ($item) { return $item->getName(); }, $items);
|
||||
$hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean $$t?" : '.';
|
||||
throw new \LogicException("Attempt to write to undeclared property {$rc->getName()}::$$name$hint");
|
||||
}
|
||||
|
Reference in New Issue
Block a user