Skip to content

Commit

Permalink
remove protected method first()
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbadxiii committed Sep 2, 2022
1 parent 7b9ec27 commit be86a46
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/Adapter/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;;
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit be86a46

Please sign in to comment.