Skip to content

Commit db49000

Browse files
committed
Added a whole bunch of missing @throws
1 parent 67a82c0 commit db49000

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/Binary.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ public static function writeByte(int $c) : string{
148148

149149
/**
150150
* Reads a 16-bit unsigned big-endian number
151+
*
152+
* @throws BinaryDataException
151153
*/
152154
public static function readShort(string $str) : int{
153155
return self::safeUnpack("n", $str, self::SIZEOF_SHORT)[1];
154156
}
155157

156158
/**
157159
* Reads a 16-bit signed big-endian number
160+
*
161+
* @throws BinaryDataException
158162
*/
159163
public static function readSignedShort(string $str) : int{
160164
return self::signShort(self::safeUnpack("n", $str, self::SIZEOF_SHORT)[1]);
@@ -169,13 +173,17 @@ public static function writeShort(int $value) : string{
169173

170174
/**
171175
* Reads a 16-bit unsigned little-endian number
176+
*
177+
* @throws BinaryDataException
172178
*/
173179
public static function readLShort(string $str) : int{
174180
return self::safeUnpack("v", $str, self::SIZEOF_SHORT)[1];
175181
}
176182

177183
/**
178184
* Reads a 16-bit signed little-endian number
185+
*
186+
* @throws BinaryDataException
179187
*/
180188
public static function readSignedLShort(string $str) : int{
181189
return self::signShort(self::safeUnpack("v", $str, self::SIZEOF_SHORT)[1]);
@@ -190,6 +198,8 @@ public static function writeLShort(int $value) : string{
190198

191199
/**
192200
* Reads a 3-byte big-endian number
201+
*
202+
* @throws BinaryDataException
193203
*/
194204
public static function readTriad(string $str) : int{
195205
return self::safeUnpack("N", "\x00" . $str, self::SIZEOF_INT)[1];
@@ -204,6 +214,8 @@ public static function writeTriad(int $value) : string{
204214

205215
/**
206216
* Reads a 3-byte little-endian number
217+
*
218+
* @throws BinaryDataException
207219
*/
208220
public static function readLTriad(string $str) : int{
209221
return self::safeUnpack("V", $str . "\x00", self::SIZEOF_INT)[1];
@@ -218,6 +230,8 @@ public static function writeLTriad(int $value) : string{
218230

219231
/**
220232
* Reads a 4-byte signed integer
233+
*
234+
* @throws BinaryDataException
221235
*/
222236
public static function readInt(string $str) : int{
223237
return self::signInt(self::safeUnpack("N", $str, self::SIZEOF_INT)[1]);
@@ -232,6 +246,8 @@ public static function writeInt(int $value) : string{
232246

233247
/**
234248
* Reads a 4-byte signed little-endian integer
249+
*
250+
* @throws BinaryDataException
235251
*/
236252
public static function readLInt(string $str) : int{
237253
return self::signInt(self::safeUnpack("V", $str, self::SIZEOF_INT)[1]);
@@ -246,13 +262,17 @@ public static function writeLInt(int $value) : string{
246262

247263
/**
248264
* Reads a 4-byte floating-point number
265+
*
266+
* @throws BinaryDataException
249267
*/
250268
public static function readFloat(string $str) : float{
251269
return self::safeUnpack("G", $str, self::SIZEOF_FLOAT)[1];
252270
}
253271

254272
/**
255273
* Reads a 4-byte floating-point number, rounded to the specified number of decimal places.
274+
*
275+
* @throws BinaryDataException
256276
*/
257277
public static function readRoundedFloat(string $str, int $accuracy) : float{
258278
return round(self::readFloat($str), $accuracy);
@@ -267,13 +287,17 @@ public static function writeFloat(float $value) : string{
267287

268288
/**
269289
* Reads a 4-byte little-endian floating-point number.
290+
*
291+
* @throws BinaryDataException
270292
*/
271293
public static function readLFloat(string $str) : float{
272294
return self::safeUnpack("g", $str, self::SIZEOF_FLOAT)[1];
273295
}
274296

275297
/**
276298
* Reads a 4-byte little-endian floating-point number rounded to the specified number of decimal places.
299+
*
300+
* @throws BinaryDataException
277301
*/
278302
public static function readRoundedLFloat(string $str, int $accuracy) : float{
279303
return round(self::readLFloat($str), $accuracy);
@@ -295,6 +319,8 @@ public static function printFloat(float $value) : string{
295319

296320
/**
297321
* Reads an 8-byte floating-point number.
322+
*
323+
* @throws BinaryDataException
298324
*/
299325
public static function readDouble(string $str) : float{
300326
return self::safeUnpack("E", $str, self::SIZEOF_DOUBLE)[1];
@@ -309,6 +335,8 @@ public static function writeDouble(float $value) : string{
309335

310336
/**
311337
* Reads an 8-byte little-endian floating-point number.
338+
*
339+
* @throws BinaryDataException
312340
*/
313341
public static function readLDouble(string $str) : float{
314342
return self::safeUnpack("e", $str, self::SIZEOF_DOUBLE)[1];
@@ -323,6 +351,8 @@ public static function writeLDouble(float $value) : string{
323351

324352
/**
325353
* Reads an 8-byte integer.
354+
*
355+
* @throws BinaryDataException
326356
*/
327357
public static function readLong(string $str) : int{
328358
return self::safeUnpack("J", $str, self::SIZEOF_LONG)[1];
@@ -337,6 +367,8 @@ public static function writeLong(int $value) : string{
337367

338368
/**
339369
* Reads an 8-byte little-endian integer.
370+
*
371+
* @throws BinaryDataException
340372
*/
341373
public static function readLLong(string $str) : int{
342374
return self::safeUnpack("P", $str, self::SIZEOF_LONG)[1];
@@ -353,6 +385,8 @@ public static function writeLLong(int $value) : string{
353385
* Reads a 32-bit zigzag-encoded variable-length integer.
354386
*
355387
* @param int $offset reference parameter
388+
*
389+
* @throws BinaryDataException
356390
*/
357391
public static function readVarInt(string $buffer, int &$offset) : int{
358392
$raw = self::readUnsignedVarInt($buffer, $offset);
@@ -418,6 +452,8 @@ public static function writeUnsignedVarInt(int $value) : string{
418452
* Reads a 64-bit zigzag-encoded variable-length integer.
419453
*
420454
* @param int $offset reference parameter
455+
*
456+
* @throws BinaryDataException
421457
*/
422458
public static function readVarLong(string $buffer, int &$offset) : int{
423459
$raw = self::readUnsignedVarLong($buffer, $offset);

src/BinaryStream.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function put(string $str) : void{
102102

103103
/**
104104
* @phpstan-impure
105+
* @throws BinaryDataException
105106
*/
106107
public function getBool() : bool{
107108
return $this->get(1) !== "\x00";
@@ -113,6 +114,7 @@ public function putBool(bool $v) : void{
113114

114115
/**
115116
* @phpstan-impure
117+
* @throws BinaryDataException
116118
*/
117119
public function getByte() : int{
118120
return ord($this->get(1));
@@ -124,13 +126,15 @@ public function putByte(int $v) : void{
124126

125127
/**
126128
* @phpstan-impure
129+
* @throws BinaryDataException
127130
*/
128131
public function getShort() : int{
129132
return Binary::readShort($this->get(2));
130133
}
131134

132135
/**
133136
* @phpstan-impure
137+
* @throws BinaryDataException
134138
*/
135139
public function getSignedShort() : int{
136140
return Binary::readSignedShort($this->get(2));
@@ -142,13 +146,15 @@ public function putShort(int $v) : void{
142146

143147
/**
144148
* @phpstan-impure
149+
* @throws BinaryDataException
145150
*/
146151
public function getLShort() : int{
147152
return Binary::readLShort($this->get(2));
148153
}
149154

150155
/**
151156
* @phpstan-impure
157+
* @throws BinaryDataException
152158
*/
153159
public function getSignedLShort() : int{
154160
return Binary::readSignedLShort($this->get(2));
@@ -160,6 +166,7 @@ public function putLShort(int $v) : void{
160166

161167
/**
162168
* @phpstan-impure
169+
* @throws BinaryDataException
163170
*/
164171
public function getTriad() : int{
165172
return Binary::readTriad($this->get(3));
@@ -171,6 +178,7 @@ public function putTriad(int $v) : void{
171178

172179
/**
173180
* @phpstan-impure
181+
* @throws BinaryDataException
174182
*/
175183
public function getLTriad() : int{
176184
return Binary::readLTriad($this->get(3));
@@ -182,6 +190,7 @@ public function putLTriad(int $v) : void{
182190

183191
/**
184192
* @phpstan-impure
193+
* @throws BinaryDataException
185194
*/
186195
public function getInt() : int{
187196
return Binary::readInt($this->get(4));
@@ -193,6 +202,7 @@ public function putInt(int $v) : void{
193202

194203
/**
195204
* @phpstan-impure
205+
* @throws BinaryDataException
196206
*/
197207
public function getLInt() : int{
198208
return Binary::readLInt($this->get(4));
@@ -204,13 +214,15 @@ public function putLInt(int $v) : void{
204214

205215
/**
206216
* @phpstan-impure
217+
* @throws BinaryDataException
207218
*/
208219
public function getFloat() : float{
209220
return Binary::readFloat($this->get(4));
210221
}
211222

212223
/**
213224
* @phpstan-impure
225+
* @throws BinaryDataException
214226
*/
215227
public function getRoundedFloat(int $accuracy) : float{
216228
return Binary::readRoundedFloat($this->get(4), $accuracy);
@@ -222,13 +234,15 @@ public function putFloat(float $v) : void{
222234

223235
/**
224236
* @phpstan-impure
237+
* @throws BinaryDataException
225238
*/
226239
public function getLFloat() : float{
227240
return Binary::readLFloat($this->get(4));
228241
}
229242

230243
/**
231244
* @phpstan-impure
245+
* @throws BinaryDataException
232246
*/
233247
public function getRoundedLFloat(int $accuracy) : float{
234248
return Binary::readRoundedLFloat($this->get(4), $accuracy);
@@ -240,6 +254,7 @@ public function putLFloat(float $v) : void{
240254

241255
/**
242256
* @phpstan-impure
257+
* @throws BinaryDataException
243258
*/
244259
public function getDouble() : float{
245260
return Binary::readDouble($this->get(8));
@@ -251,6 +266,7 @@ public function putDouble(float $v) : void{
251266

252267
/**
253268
* @phpstan-impure
269+
* @throws BinaryDataException
254270
*/
255271
public function getLDouble() : float{
256272
return Binary::readLDouble($this->get(8));
@@ -262,6 +278,7 @@ public function putLDouble(float $v) : void{
262278

263279
/**
264280
* @phpstan-impure
281+
* @throws BinaryDataException
265282
*/
266283
public function getLong() : int{
267284
return Binary::readLong($this->get(8));
@@ -273,6 +290,7 @@ public function putLong(int $v) : void{
273290

274291
/**
275292
* @phpstan-impure
293+
* @throws BinaryDataException
276294
*/
277295
public function getLLong() : int{
278296
return Binary::readLLong($this->get(8));
@@ -286,6 +304,7 @@ public function putLLong(int $v) : void{
286304
* Reads a 32-bit variable-length unsigned integer from the buffer and returns it.
287305
*
288306
* @phpstan-impure
307+
* @throws BinaryDataException
289308
*/
290309
public function getUnsignedVarInt() : int{
291310
return Binary::readUnsignedVarInt($this->buffer, $this->offset);
@@ -302,6 +321,7 @@ public function putUnsignedVarInt(int $v) : void{
302321
* Reads a 32-bit zigzag-encoded variable-length integer from the buffer and returns it.
303322
*
304323
* @phpstan-impure
324+
* @throws BinaryDataException
305325
*/
306326
public function getVarInt() : int{
307327
return Binary::readVarInt($this->buffer, $this->offset);
@@ -318,6 +338,7 @@ public function putVarInt(int $v) : void{
318338
* Reads a 64-bit variable-length integer from the buffer and returns it.
319339
*
320340
* @phpstan-impure
341+
* @throws BinaryDataException
321342
*/
322343
public function getUnsignedVarLong() : int{
323344
return Binary::readUnsignedVarLong($this->buffer, $this->offset);
@@ -334,6 +355,7 @@ public function putUnsignedVarLong(int $v) : void{
334355
* Reads a 64-bit zigzag-encoded variable-length integer from the buffer and returns it.
335356
*
336357
* @phpstan-impure
358+
* @throws BinaryDataException
337359
*/
338360
public function getVarLong() : int{
339361
return Binary::readVarLong($this->buffer, $this->offset);

0 commit comments

Comments
 (0)