| Conditions | 5 |
| Paths | 6 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | 40 | public static function parseMessage(string $message): array |
|
| 28 | { |
||
| 29 | 40 | $startLine = null; |
|
| 30 | 40 | $headers = []; |
|
| 31 | 40 | [$headerLines, $body] = explode(self::BODY_SEPARATOR, $message, 2); |
|
| 32 | 40 | $headerLines = explode("\n", $headerLines); |
|
| 33 | |||
| 34 | 40 | foreach ($headerLines as $header) { |
|
| 35 | // Parse message headers |
||
| 36 | 40 | if ($startLine === null) { |
|
| 37 | 40 | $startLine = explode(' ', $header, 3); |
|
| 38 | 40 | continue; |
|
| 39 | } |
||
| 40 | 40 | $parts = explode(':', $header, 2); |
|
| 41 | 40 | $key = trim($parts[0]); |
|
| 42 | 40 | $value = isset($parts[1]) ? trim($parts[1]) : ''; |
|
| 43 | |||
| 44 | 40 | if (! isset($headers[$key])) { |
|
| 45 | 40 | $headers[$key] = []; |
|
| 46 | } |
||
| 47 | 40 | $headers[$key][] = $value; |
|
| 48 | } |
||
| 49 | |||
| 50 | return [ |
||
| 51 | 40 | (int) ($startLine[1] ?? 0), |
|
| 52 | 40 | $headers, |
|
| 53 | 40 | $body, |
|
| 54 | ]; |
||
| 57 |