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