| Total Complexity | 7 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class Header |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $field; |
||
| 13 | /** |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | private $value; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $field |
||
| 20 | * @param string $value |
||
| 21 | */ |
||
| 22 | 2 | public function __construct(string $field, string $value) |
|
| 23 | { |
||
| 24 | 2 | $this->field = $field; |
|
| 25 | 2 | $this->value = $value; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $header |
||
| 30 | * |
||
| 31 | * @return Header |
||
| 32 | */ |
||
| 33 | 1 | public static function fromRfc2822(string $header): Header |
|
| 34 | { |
||
| 35 | 1 | $parts = explode(':', $header, 2); |
|
| 36 | |||
| 37 | 1 | return new static($parts[0], trim($parts[1])); |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $header |
||
| 42 | * |
||
| 43 | * @return Header |
||
| 44 | */ |
||
| 45 | 1 | public static function fromString(string $header): Header |
|
| 46 | { |
||
| 47 | 1 | return self::fromRfc2822($header); |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 2 | public function getField(): string |
|
| 54 | { |
||
| 55 | 2 | return $this->field; |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | 2 | public function getValue(): string |
|
| 62 | { |
||
| 63 | 2 | return $this->value; |
|
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 1 | public function toRfc2822(): string |
|
| 70 | { |
||
| 71 | 1 | return sprintf('%s: %s', $this->field, $this->value); |
|
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | 1 | public function __toString(): string |
|
| 80 | } |
||
| 81 | } |
||
| 82 |