Skip to content

Instantly share code, notes, and snippets.

@brzuchal
Created December 12, 2016 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brzuchal/fafc96c4ccfe4e40c5994d9c539c86a1 to your computer and use it in GitHub Desktop.
Save brzuchal/fafc96c4ccfe4e40c5994d9c539c86a1 to your computer and use it in GitHub Desktop.
<?php
namespace Plumbok\Test;
/**
* @Value
*/
class Email
{
private $email = '';
private function setEmail(string $email)
{
if (!valid($email)) {
throw new InvalidArgumentException("Email address is invalid, given: {$email}");
}
$this->email = $email;
}
}
<?php
namespace Plumbok\Test;
/**
* @Value
*/
class Email
{
private $email = '';
private function setEmail(string $email)
{
if (!valid($email)) {
throw new InvalidArgumentException("Email address is invalid, given: {$email}");
}
$this->email = $email;
}
// generated code
/**
* Email constructor.
*
* @param string $email
*/
public function __construct(string $email)
{
$this->setEmail($email);
}
/**
* Retrieves email
*
* @return string
*/
public function getEmail() : string
{
return $this->email;
}
/**
* Compares two emails
*
* @return boolean
*/
public function equal(Email $other) : bool
{
return get_class($this) === get_class($other) && $this->email == $other->email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment