| Conditions | 9 |
| Paths | 96 |
| Total Lines | 36 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 9 |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | 432 | public static function parse($header) |
|
| 27 | { |
||
| 28 | 432 | if (strpos($header, '=') === false) { |
|
| 29 | 72 | $header = '='.$header; |
|
| 30 | 56 | } |
|
| 31 | |||
| 32 | 432 | list($name, $header) = explode('=', $header, 2); |
|
| 33 | |||
| 34 | 432 | if (strpos($header, ';') === false) { |
|
| 35 | 144 | $value = $header; |
|
| 36 | 144 | $header = null; |
|
| 37 | 112 | } else { |
|
| 38 | 288 | list($value, $header) = explode(';', $header, 2); |
|
| 39 | } |
||
| 40 | |||
| 41 | 432 | $attributes = []; |
|
| 42 | 432 | foreach (array_map('trim', explode(';', $header)) as $pair) { |
|
| 43 | 432 | if (empty($pair)) { |
|
| 44 | 216 | continue; |
|
| 45 | } |
||
| 46 | |||
| 47 | 216 | if (strpos($pair, '=') === false) { |
|
| 48 | 72 | $attributeName = $pair; |
|
| 49 | 72 | $attributeValue = null; |
|
| 50 | 56 | } else { |
|
| 51 | 180 | list($attributeName, $attributeValue) = explode('=', $pair); |
|
| 52 | } |
||
| 53 | |||
| 54 | 216 | $attributes[trim($attributeName)] = $attributeValue ? trim($attributeValue) : true; |
|
| 55 | 336 | } |
|
| 56 | |||
| 57 | 432 | $name = trim($name); |
|
| 58 | 432 | $value = trim($value); |
|
| 59 | |||
| 60 | 432 | return [!empty($name) ? $name : null, !empty($value) ? $value : null, $attributes]; |
|
| 61 | } |
||
| 62 | } |
||
| 63 |