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