| Conditions | 4 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 22 | public static function fromString(string $header): Header |
|
| 23 | { |
||
| 24 | 22 | $regEx = '{^' . Rfc7230::HEADER_FIELD_CAPTURE . '$}'; |
|
| 25 | 22 | $plainHeader = mb_convert_encoding($header, 'ISO-8859-1', 'UTF-8'); |
|
| 26 | 22 | if ($plainHeader !== $header || preg_match($regEx, $header, $matches) !== 1) { |
|
| 27 | 3 | throw new InvalidHeader('Invalid header field: ' . $header); |
|
| 28 | } |
||
| 29 | |||
| 30 | 19 | switch (strtolower($matches['FIELD_NAME'])) { |
|
| 31 | 19 | case 'content-type': |
|
| 32 | 3 | return ContentType::fromValue($matches['FIELD_VALUE']); |
|
| 33 | default: |
||
| 34 | 16 | return new ArbitraryHeader($matches['FIELD_NAME'], $matches['FIELD_VALUE']); |
|
| 35 | } |
||
| 38 |