Skip to content

Instantly share code, notes, and snippets.

@vanbrabantf
Created April 2, 2021 14:16
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 vanbrabantf/95325930aa1dd79d144224692a87c06c to your computer and use it in GitHub Desktop.
Save vanbrabantf/95325930aa1dd79d144224692a87c06c to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
final class CustomerName
{
private $firstName;
private $lastName;
public function __construct(string $firstName, string $lastName)
{
Assert::stringNotEmpty($firstName);
Assert::stringNotEmpty($lastName);
Assert::alpha($firstName);
Assert::alpha($lastName);
$this->firstName = $firstName;
$this->lastName = $lastName;
}
public static function fromFullName(string $fullname): self
{
$pieces = explode(' ', $fullname);
return new CustomerName($pieces[0], $pieces[1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment