Skip to content

Commit f883e1c

Browse files
committed
BinaryStream: Explicitly mark get*() methods as impure
PHPStan will assume these are pure because they are called 'get' and have a non-void return type.
1 parent 48dfa50 commit f883e1c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/BinaryStream.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function getBuffer() : string{
6363
}
6464

6565
/**
66+
* @phpstan-impure
6667
* @throws BinaryDataException if there are not enough bytes left in the buffer
6768
*/
6869
public function get(int $len) : string{
@@ -82,6 +83,7 @@ public function get(int $len) : string{
8283
}
8384

8485
/**
86+
* @phpstan-impure
8587
* @throws BinaryDataException
8688
*/
8789
public function getRemaining() : string{
@@ -98,6 +100,9 @@ public function put(string $str) : void{
98100
$this->buffer .= $str;
99101
}
100102

103+
/**
104+
* @phpstan-impure
105+
*/
101106
public function getBool() : bool{
102107
return $this->get(1) !== "\x00";
103108
}
@@ -106,6 +111,9 @@ public function putBool(bool $v) : void{
106111
$this->buffer .= ($v ? "\x01" : "\x00");
107112
}
108113

114+
/**
115+
* @phpstan-impure
116+
*/
109117
public function getByte() : int{
110118
return ord($this->get(1));
111119
}
@@ -114,10 +122,16 @@ public function putByte(int $v) : void{
114122
$this->buffer .= chr($v);
115123
}
116124

125+
/**
126+
* @phpstan-impure
127+
*/
117128
public function getShort() : int{
118129
return Binary::readShort($this->get(2));
119130
}
120131

132+
/**
133+
* @phpstan-impure
134+
*/
121135
public function getSignedShort() : int{
122136
return Binary::readSignedShort($this->get(2));
123137
}
@@ -126,10 +140,16 @@ public function putShort(int $v) : void{
126140
$this->buffer .= Binary::writeShort($v);
127141
}
128142

143+
/**
144+
* @phpstan-impure
145+
*/
129146
public function getLShort() : int{
130147
return Binary::readLShort($this->get(2));
131148
}
132149

150+
/**
151+
* @phpstan-impure
152+
*/
133153
public function getSignedLShort() : int{
134154
return Binary::readSignedLShort($this->get(2));
135155
}
@@ -138,6 +158,9 @@ public function putLShort(int $v) : void{
138158
$this->buffer .= Binary::writeLShort($v);
139159
}
140160

161+
/**
162+
* @phpstan-impure
163+
*/
141164
public function getTriad() : int{
142165
return Binary::readTriad($this->get(3));
143166
}
@@ -146,6 +169,9 @@ public function putTriad(int $v) : void{
146169
$this->buffer .= Binary::writeTriad($v);
147170
}
148171

172+
/**
173+
* @phpstan-impure
174+
*/
149175
public function getLTriad() : int{
150176
return Binary::readLTriad($this->get(3));
151177
}
@@ -154,6 +180,9 @@ public function putLTriad(int $v) : void{
154180
$this->buffer .= Binary::writeLTriad($v);
155181
}
156182

183+
/**
184+
* @phpstan-impure
185+
*/
157186
public function getInt() : int{
158187
return Binary::readInt($this->get(4));
159188
}
@@ -162,6 +191,9 @@ public function putInt(int $v) : void{
162191
$this->buffer .= Binary::writeInt($v);
163192
}
164193

194+
/**
195+
* @phpstan-impure
196+
*/
165197
public function getLInt() : int{
166198
return Binary::readLInt($this->get(4));
167199
}
@@ -170,10 +202,16 @@ public function putLInt(int $v) : void{
170202
$this->buffer .= Binary::writeLInt($v);
171203
}
172204

205+
/**
206+
* @phpstan-impure
207+
*/
173208
public function getFloat() : float{
174209
return Binary::readFloat($this->get(4));
175210
}
176211

212+
/**
213+
* @phpstan-impure
214+
*/
177215
public function getRoundedFloat(int $accuracy) : float{
178216
return Binary::readRoundedFloat($this->get(4), $accuracy);
179217
}
@@ -182,10 +220,16 @@ public function putFloat(float $v) : void{
182220
$this->buffer .= Binary::writeFloat($v);
183221
}
184222

223+
/**
224+
* @phpstan-impure
225+
*/
185226
public function getLFloat() : float{
186227
return Binary::readLFloat($this->get(4));
187228
}
188229

230+
/**
231+
* @phpstan-impure
232+
*/
189233
public function getRoundedLFloat(int $accuracy) : float{
190234
return Binary::readRoundedLFloat($this->get(4), $accuracy);
191235
}
@@ -194,6 +238,9 @@ public function putLFloat(float $v) : void{
194238
$this->buffer .= Binary::writeLFloat($v);
195239
}
196240

241+
/**
242+
* @phpstan-impure
243+
*/
197244
public function getDouble() : float{
198245
return Binary::readDouble($this->get(8));
199246
}
@@ -202,6 +249,9 @@ public function putDouble(float $v) : void{
202249
$this->buffer .= Binary::writeDouble($v);
203250
}
204251

252+
/**
253+
* @phpstan-impure
254+
*/
205255
public function getLDouble() : float{
206256
return Binary::readLDouble($this->get(8));
207257
}
@@ -210,6 +260,9 @@ public function putLDouble(float $v) : void{
210260
$this->buffer .= Binary::writeLDouble($v);
211261
}
212262

263+
/**
264+
* @phpstan-impure
265+
*/
213266
public function getLong() : int{
214267
return Binary::readLong($this->get(8));
215268
}
@@ -218,6 +271,9 @@ public function putLong(int $v) : void{
218271
$this->buffer .= Binary::writeLong($v);
219272
}
220273

274+
/**
275+
* @phpstan-impure
276+
*/
221277
public function getLLong() : int{
222278
return Binary::readLLong($this->get(8));
223279
}
@@ -228,6 +284,8 @@ public function putLLong(int $v) : void{
228284

229285
/**
230286
* Reads a 32-bit variable-length unsigned integer from the buffer and returns it.
287+
*
288+
* @phpstan-impure
231289
*/
232290
public function getUnsignedVarInt() : int{
233291
return Binary::readUnsignedVarInt($this->buffer, $this->offset);
@@ -242,6 +300,8 @@ public function putUnsignedVarInt(int $v) : void{
242300

243301
/**
244302
* Reads a 32-bit zigzag-encoded variable-length integer from the buffer and returns it.
303+
*
304+
* @phpstan-impure
245305
*/
246306
public function getVarInt() : int{
247307
return Binary::readVarInt($this->buffer, $this->offset);
@@ -256,6 +316,8 @@ public function putVarInt(int $v) : void{
256316

257317
/**
258318
* Reads a 64-bit variable-length integer from the buffer and returns it.
319+
*
320+
* @phpstan-impure
259321
*/
260322
public function getUnsignedVarLong() : int{
261323
return Binary::readUnsignedVarLong($this->buffer, $this->offset);
@@ -270,6 +332,8 @@ public function putUnsignedVarLong(int $v) : void{
270332

271333
/**
272334
* Reads a 64-bit zigzag-encoded variable-length integer from the buffer and returns it.
335+
*
336+
* @phpstan-impure
273337
*/
274338
public function getVarLong() : int{
275339
return Binary::readVarLong($this->buffer, $this->offset);

0 commit comments

Comments
 (0)