implement SearchUsers use case
This commit is contained in:
parent
31a807f0ae
commit
d917e76f1b
5 changed files with 93 additions and 0 deletions
|
|
@ -63,6 +63,36 @@ class FakeUserRepository implements UserRepository
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User[]
|
||||
*/
|
||||
public function search(string $query): array
|
||||
{
|
||||
$needle = strtolower($query);
|
||||
$results = [];
|
||||
foreach ($this->existingUsers as $user) {
|
||||
$displayName = strtolower($user->getDisplayName());
|
||||
$email = strtolower($user->getEmail()->value());
|
||||
if (
|
||||
str_starts_with($displayName, $needle)
|
||||
|| str_starts_with($email, $needle)
|
||||
) {
|
||||
$results[] = $this->copy($user);
|
||||
}
|
||||
}
|
||||
usort(
|
||||
$results,
|
||||
function (User $left, User $right) {
|
||||
return strcmp(
|
||||
$left->getDisplayName(),
|
||||
$right->getDisplayName(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue