From 24d0b069d81e7f34a051e79fb7209bb75e986c7c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 14 Oct 2020 11:52:00 +0200 Subject: [PATCH] Helpers::getSuggestion(): support for reflection objects moved to Strict --- src/Dibi/Helpers.php | 3 +-- src/Dibi/Strict.php | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index c212d7f3..e23d7491 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -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; diff --git a/src/Dibi/Strict.php b/src/Dibi/Strict.php index 08855a37..a35360e6 100644 --- a/src/Dibi/Strict.php +++ b/src/Dibi/Strict.php @@ -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"); }