| Conditions | 6 |
| Paths | 14 |
| Total Lines | 37 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 65 | 30 | public static function decodeName(string $string, int &$offset = 0): string |
|
| 66 | { |
||
| 67 | 30 | $len = ord($string[$offset]); |
|
| 68 | 30 | ++$offset; |
|
| 69 | |||
| 70 | 30 | $isCompressed = (bool) (0b11000000 & $len); |
|
| 71 | 30 | $_offset = 0; |
|
| 72 | |||
| 73 | 30 | if ($isCompressed) { |
|
| 74 | 7 | $_offset = $offset + 1; |
|
| 75 | 7 | $offset = (0b00111111 & $len) * 256 + ord($string[$offset]); |
|
| 76 | 7 | $len = ord($string[$offset]); |
|
| 77 | 7 | ++$offset; |
|
| 78 | } |
||
| 79 | |||
| 80 | 30 | if (0 === $len) { |
|
| 81 | 3 | return '.'; |
|
| 82 | } |
||
| 83 | |||
| 84 | 27 | $name = ''; |
|
| 85 | 27 | while (0 !== $len) { |
|
| 86 | 27 | $name .= substr($string, $offset, $len).'.'; |
|
| 87 | 27 | $offset += $len; |
|
| 88 | 27 | $len = ord($string[$offset]); |
|
| 89 | 27 | if ($len & 0b11000000) { |
|
| 90 | 7 | $name .= self::decodeName($string, $offset); |
|
| 91 | 7 | break; |
|
| 92 | } |
||
| 93 | |||
| 94 | 27 | ++$offset; |
|
| 95 | } |
||
| 96 | |||
| 97 | 27 | if ($isCompressed) { |
|
| 98 | 7 | $offset = $_offset; |
|
| 99 | } |
||
| 100 | |||
| 101 | 27 | return $name; |
|
| 102 | } |
||
| 104 |