Simplify mail sync

This commit is contained in:
philipp lang 2023-07-10 11:28:47 +02:00
parent 1038f26171
commit 139c7623ab
2 changed files with 8 additions and 2 deletions

View File

@ -10,4 +10,9 @@ class MailEntry extends Data
{ {
$this->email = strtolower($email); $this->email = strtolower($email);
} }
public function is(self $mailEntry): bool
{
return $this->email === $mailEntry->email;
}
} }

View File

@ -79,8 +79,9 @@ abstract class Type
*/ */
public function sync(string $name, string $domain, Collection $results): void public function sync(string $name, string $domain, Collection $results): void
{ {
$members = $this->list($name, $domain);
foreach ($results as $result) { foreach ($results as $result) {
if ($this->search($name, $domain, $result->email)) { if ($members->first(fn ($member) => $member->is($result))) {
continue; continue;
} }
@ -88,7 +89,7 @@ abstract class Type
} }
$this->list($name, $domain) $this->list($name, $domain)
->filter(fn ($listEntry) => null === $results->first(fn ($r) => $r->email === $listEntry->email)) ->filter(fn ($listEntry) => $results->doesntContain(fn ($r) => $r->is($listEntry)))
->each(fn ($listEntry) => $this->remove($name, $domain, $listEntry->email)); ->each(fn ($listEntry) => $this->remove($name, $domain, $listEntry->email));
} }