@@ -15,23 +15,23 @@ discard block |
||
| 15 | 15 | class Decoder |
| 16 | 16 | { |
| 17 | 17 | /** |
| 18 | - * @var string Bencoded string being decoded |
|
| 19 | - */ |
|
| 18 | + * @var string Bencoded string being decoded |
|
| 19 | + */ |
|
| 20 | 20 | protected string $bencoded; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * @var int Length of the bencoded string |
|
| 24 | - */ |
|
| 23 | + * @var int Length of the bencoded string |
|
| 24 | + */ |
|
| 25 | 25 | protected int $len; |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * @var int Safe rightmost boundary |
|
| 29 | - */ |
|
| 28 | + * @var int Safe rightmost boundary |
|
| 29 | + */ |
|
| 30 | 30 | protected int $max; |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | - * @var int Position of the cursor while decoding |
|
| 34 | - */ |
|
| 33 | + * @var int Position of the cursor while decoding |
|
| 34 | + */ |
|
| 35 | 35 | protected int $offset = 0; |
| 36 | 36 | |
| 37 | 37 | public static function decode(string $bencoded): ArrayObject|array|int|string |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Check the cursor's position after decoding is done |
|
| 73 | - */ |
|
| 72 | + * Check the cursor's position after decoding is done |
|
| 73 | + */ |
|
| 74 | 74 | protected function checkCursorPosition(): void |
| 75 | 75 | { |
| 76 | 76 | if ($this->offset !== $this->len) |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | - * Adjust the rightmost boundary to the last safe character that can start a value |
|
| 104 | - * |
|
| 105 | - * Will rewind the boundary to skip the rightmost digits, optionally preceded by "i" or "i-" |
|
| 106 | - */ |
|
| 103 | + * Adjust the rightmost boundary to the last safe character that can start a value |
|
| 104 | + * |
|
| 105 | + * Will rewind the boundary to skip the rightmost digits, optionally preceded by "i" or "i-" |
|
| 106 | + */ |
|
| 107 | 107 | protected function computeSafeBoundary(): void |
| 108 | 108 | { |
| 109 | 109 | $boundary = $this->len - 1; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | protected int $offset = 0; |
| 36 | 36 | |
| 37 | - public static function decode(string $bencoded): ArrayObject|array|int|string |
|
| 37 | + public static function decode(string $bencoded): ArrayObject | array | int | string |
|
| 38 | 38 | { |
| 39 | 39 | $decoder = new static($bencoded); |
| 40 | 40 | $value = $decoder->decodeAnything(); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | if ($this->max < 1) |
| 62 | 62 | { |
| 63 | - throw match ($this->bencoded[0]) |
|
| 63 | + throw match($this->bencoded[0]) |
|
| 64 | 64 | { |
| 65 | 65 | '-', 'e' => new DecodingException('Illegal character', 0), |
| 66 | 66 | default => new DecodingException('Premature end of data', $this->len - 1) |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | while (str_contains('0123456789', $c) && --$boundary >= 0); |
| 115 | 115 | |
| 116 | - $this->max = match ($c) |
|
| 116 | + $this->max = match($c) |
|
| 117 | 117 | { |
| 118 | 118 | '-' => $boundary - 2, |
| 119 | 119 | 'i' => $boundary - 1, |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | $this->checkBoundary(); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - protected function decodeAnything(): ArrayObject|array|int|string |
|
| 125 | + protected function decodeAnything(): ArrayObject | array | int | string |
|
| 126 | 126 | { |
| 127 | - return match ($this->bencoded[$this->offset]) |
|
| 127 | + return match($this->bencoded[$this->offset]) |
|
| 128 | 128 | { |
| 129 | 129 | 'd' => $this->decodeDictionary(), |
| 130 | 130 | 'i' => $this->decodeInteger(), |