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