From be86a460e8dd70c7717f1a25c923b097fe348e15 Mon Sep 17 00:00:00 2001 From: sinbad Date: Fri, 2 Sep 2022 17:16:24 +0500 Subject: [PATCH] remove protected method first() --- src/Adapter/Memory.php | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/Adapter/Memory.php b/src/Adapter/Memory.php index 2da422e..26b4fa9 100644 --- a/src/Adapter/Memory.php +++ b/src/Adapter/Memory.php @@ -29,7 +29,22 @@ public function findFirstByCredentials(array $credentials): ?AuthenticatableInte { $providerStorage = $this->getProviderStorage(); - return $this->first($providerStorage, $credentials); + $field = array_key_first($credentials) ?? "email"; + $term = $credentials[$field]; + + $key = array_search($term, array_column($providerStorage, $field), true); + + if (empty($this->model)) { + throw new InvalidArgumentException("Сonfig with key 'model' is empty"); + } + + $userModel = $this->model; + + if ($key !== false) { + return new $userModel($providerStorage[$key] + ['id' => $key]); + } + + return null;; } /** @@ -65,31 +80,6 @@ public function validateCredentials(AuthenticatableInterface $user, array $crede ) : $credentials['password'] === $user->getAuthPassword(); } - /** - * @param array $providerStorage - * @param array $credentials - * @return AuthenticatableInterface|null - */ - public function first(array $providerStorage, array $credentials): ?AuthenticatableInterface - { - $field = array_key_first($credentials) ?? "email"; - $term = $credentials[$field]; - - $key = array_search($term, array_column($providerStorage, $field), true); - - if (empty($this->model)) { - throw new InvalidArgumentException("Сonfig with key 'model' is empty"); - } - - $userModel = $this->model; - - if ($key !== false) { - return new $userModel($providerStorage[$key] + ['id' => $key]); - } - - return null; - } - /** * @return mixed */