name = $name; if (!$this->validateEmail($email)) { throw new \Exception('Invalid email address found: '.$email); } $this->email = $email; } /** * get name. * * @return string name */ public function getName(): string { return $this->name; } /** * get email. * * @return string email */ public function getEmail(): string { return $this->email; } /** * check wheter string is email. * * @param string $text email * * @return bool false if not email string */ public function validateEmail(string $email): bool { return false !== preg_match('/^'.self::EMAIL_REGEX.'$/', $email); } }