mmk2410
/
my-todo-list
Archived
1
0
Fork 0
This repository has been archived on 2021-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
my-todo-list/src/Email.php

34 lines
700 B
PHP

<?php declare(strict_types=1);
namespace MMK2410\MyTodoList;
final class Email
{
private $email;
private function __construct(string $email)
{
$this->ensureIsValidEmail($email);
$this->email = $email;
}
public static function fromString(string $email): self
{
return new self($email);
}
public function __toString(): string
{
return $this->email;
}
private function ensureIsValidEmail(string $email): void
{
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(
sprintf("%s is not a valid email address", $email)
);
}
}
}