| Total Complexity | 3 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class ValidatedUserId |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $userId; |
||
| 19 | |||
| 20 | public function asStr(): string |
||
| 21 | { |
||
| 22 | $countryCode = substr($this->userId, 0, 2); |
||
| 23 | if (preg_match('/^[A-Z]{2}$/', $countryCode) !== 1) { |
||
| 24 | throw new Exception( |
||
| 25 | sprintf( |
||
| 26 | 'Invalid country code prefix in userId. Must be two-letter ISO country code. Actual: %s', |
||
| 27 | $countryCode |
||
| 28 | ) |
||
| 29 | ); |
||
| 30 | } |
||
| 31 | |||
| 32 | return $this->userId; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function __construct(string $userId) |
||
| 38 | } |
||
| 39 | } |
||
| 40 |