From 4f6ac876ce6a35efd2bd47f82ecf27dc7ba5e25b Mon Sep 17 00:00:00 2001 From: yisroel Date: Wed, 6 May 2026 14:52:45 +0300 Subject: [PATCH] implement EmailAddress value object immutable readonly. trims whitespace, splits on @, lowercases the domain (local-part case preserved per RFC 5321), validates with FILTER_VALIDATE_EMAIL after normalization. throws InvalidArgumentException on empty / missing-@ / malformed input. exposes value(), getDomain(), equals(), __toString(). all 7 EmailAddressTest cases green; 9 tests total pass. --- .../app/Shared/ValueObject/EmailAddress.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 backend/app/Shared/ValueObject/EmailAddress.php diff --git a/backend/app/Shared/ValueObject/EmailAddress.php b/backend/app/Shared/ValueObject/EmailAddress.php new file mode 100644 index 0000000..0756a5f --- /dev/null +++ b/backend/app/Shared/ValueObject/EmailAddress.php @@ -0,0 +1,53 @@ +domain = mb_strtolower($domain); + $normalized = $local.'@'.$this->domain; + + if (filter_var($normalized, FILTER_VALIDATE_EMAIL) === false) { + throw new InvalidArgumentException(self::ERROR_MESSAGE." $email"); + } + + $this->normalized = $normalized; + } + + public function value(): string + { + return $this->normalized; + } + + public function equals(self $other): bool + { + return $this->normalized === $other->normalized; + } + + public function getDomain(): string + { + return $this->domain; + } + + public function __toString(): string + { + return $this->normalized; + } +}