Skip to content

Instantly share code, notes, and snippets.

@benatespina
Created January 7, 2017 13:21
Show Gist options
  • Select an option

  • Save benatespina/168a5de259c935e51c2982ebc7fe8702 to your computer and use it in GitHub Desktop.

Select an option

Save benatespina/168a5de259c935e51c2982ebc7fe8702 to your computer and use it in GitHub Desktop.
class Validator
{
public function validateEmail($email)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \Exception('Given email is not valid format email.');
}
}
public function validatePasswordLength($password)
{
if (count($password) < 6) {
throw new \Exception('The given password is too short');
}
if (count($password) > 20) {
throw new \Exception('The given password is too long');
}
}
}
class User
{
private $id;
private $email;
private $password;
public function getId()
{
return $this->id;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
return $this;
}
}
$user = new User();
$userValidator = new Validator();
$userValidator->validateEmail($email);
$userValidator->validatePasswordLength($password);
$user->setEmail($email);
$user->setPassword($password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment