| @@ 7-46 (lines=40) @@ | ||
| 4 | use DjThossi\Ensure\EnsureIsNotEmptyTrait; |
|
| 5 | use DjThossi\Ensure\EnsureIsStringTrait; |
|
| 6 | ||
| 7 | class ErrorMessage |
|
| 8 | { |
|
| 9 | use EnsureIsStringTrait; |
|
| 10 | use EnsureIsNotEmptyTrait; |
|
| 11 | ||
| 12 | const MESSAGE_IS_NOT_A_STRING = 1; |
|
| 13 | const MESSAGE_IS_EMPTY = 2; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | private $message; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @param string $message |
|
| 22 | */ |
|
| 23 | public function __construct($message) |
|
| 24 | { |
|
| 25 | $this->ensureMessage($message); |
|
| 26 | ||
| 27 | $this->message = $message; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @return string |
|
| 32 | */ |
|
| 33 | public function asString() |
|
| 34 | { |
|
| 35 | return $this->message; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @param mixed $message |
|
| 40 | */ |
|
| 41 | private function ensureMessage($message) |
|
| 42 | { |
|
| 43 | $this->ensureIsString('Message', $message, self::MESSAGE_IS_NOT_A_STRING); |
|
| 44 | $this->ensureIsNotEmpty('Message', $message, self::MESSAGE_IS_EMPTY); |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||
| @@ 7-46 (lines=40) @@ | ||
| 4 | use DjThossi\Ensure\EnsureIsNotEmptyTrait; |
|
| 5 | use DjThossi\Ensure\EnsureIsStringTrait; |
|
| 6 | ||
| 7 | class HeaderKey |
|
| 8 | { |
|
| 9 | use EnsureIsStringTrait; |
|
| 10 | use EnsureIsNotEmptyTrait; |
|
| 11 | ||
| 12 | const KEY_IS_NOT_A_STRING = 1; |
|
| 13 | const KEY_IS_EMPTY = 2; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | private $key; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @param string $key |
|
| 22 | */ |
|
| 23 | public function __construct($key) |
|
| 24 | { |
|
| 25 | $this->ensureKey($key); |
|
| 26 | ||
| 27 | $this->key = $key; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @return string |
|
| 32 | */ |
|
| 33 | public function asString() |
|
| 34 | { |
|
| 35 | return $this->key; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @param mixed $key |
|
| 40 | */ |
|
| 41 | private function ensureKey($key) |
|
| 42 | { |
|
| 43 | $this->ensureIsString('Key', $key, self::KEY_IS_NOT_A_STRING); |
|
| 44 | $this->ensureIsNotEmpty('Key', $key, self::KEY_IS_EMPTY); |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||