Created
April 10, 2020 19:01
-
-
Save vv12131415/3a07b15e1e021eb2a9440a27ddd326a3 to your computer and use it in GitHub Desktop.
VO with external service
This file contains hidden or 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 PostCode | |
| { | |
| /** @var string */ | |
| private $code; | |
| private function __construct() | |
| { | |
| } | |
| public static function create(string $code, Country $country, PostCodeValidatorInterface $postCodeValidator): PostCode | |
| { | |
| if (!$postCodeValidator->isValid($country, $code)) { | |
| throw new InvalidArgumentException('Post code is not valid for ' . $country->getName()); | |
| } | |
| $self = new self(); | |
| $self->code = $code; | |
| return $self; | |
| } | |
| public static function createWithClosure(string $code, Country $country, Closure $postCodeValidator): PostCode | |
| { | |
| if (!$postCodeValidator($country, $code)) { | |
| throw new InvalidArgumentException('Post code is not valid for ' . $country->getName()); | |
| } | |
| $self = new self(); | |
| $self->code = $code; | |
| return $self; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment