Created
April 2, 2021 14:16
-
-
Save vanbrabantf/95325930aa1dd79d144224692a87c06c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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