for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Samurai\Project;
/**
* Class Author
* @package Samurai\Project
* @author Raphaël Lefebvre <[email protected]>
*/
class Author
{
* @var string
private $name;
private $email;
* $author must be formatted like an email of the RFC 822
* ex: name <[email protected]>
* @param string $author
public function __construct($author)
if (preg_match('/^(?P<name>[- \.,\p{L}\'’]+) <(?P<email>.+?)>$/u', $author, $match)) {
$this->setName($match['name']);
$this->setEmail($match['email']);
}else{
throw new \InvalidArgumentException(sprintf(
'Invalid author "%s". Must be in the format: "name <[email protected]>"',
$author
));
}
* Getter of $name
*
* @return string
public function getName()
return $this->name;
* Setter of $name
* @param string $name
public function setName($name)
$this->name = (string)$name;
* Getter of $email
public function getEmail()
return $this->email;
* Setter of $email
* @param string $email
public function setEmail($email)
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
throw new \InvalidArgumentException(sprintf('Invalid email "%s"', $email));
$this->email = (string)$email;
* @return array
public function toArray()
return[
'name' => $this->getName(),
'email' => $this->getEmail(),
];
public function __toString()
return $this->getName() . ' <' . $this->getEmail() . '>';