| Total Complexity | 7 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class Address |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $email; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var string|null |
||
| 20 | */ |
||
| 21 | protected $name; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param string $email valid e-mail address |
||
| 25 | * @param string|null $name display name (optional) |
||
| 26 | * |
||
| 27 | * @throws InvalidArgumentException for invalid e-mail address |
||
| 28 | * @throws RuntimeException on attempted CRLF name injection |
||
| 29 | */ |
||
| 30 | 21 | public function __construct(string $email, ?string $name = null) |
|
| 31 | { |
||
| 32 | 21 | if (! self::isValidEmail($email)) { |
|
| 33 | 1 | throw new InvalidArgumentException("invalid e-mail address"); |
|
| 34 | } |
||
| 35 | |||
| 36 | 20 | if (! empty($name)) { |
|
| 37 | 12 | if (preg_match('/[\r\n]/', $name)) { |
|
| 38 | 1 | throw new RuntimeException("CR/LF injection detected"); |
|
| 39 | } |
||
| 40 | 11 | } |
|
| 41 | |||
| 42 | 19 | $this->email = $email; |
|
| 43 | 19 | $this->name = $name; |
|
| 44 | 19 | } |
|
| 45 | |||
| 46 | public static function isValidEmail(string $email): bool |
||
| 49 | } |
||
| 50 | |||
| 51 | 21 | public function getEmail(): string |
|
| 54 | } |
||
| 55 | |||
| 56 | public function getName(): ?string |
||
| 61 |