Skip to content

Commit

Permalink
BinaryStream: Explicitly mark get*() methods as impure
Browse files Browse the repository at this point in the history
PHPStan will assume these are pure because they are called 'get' and have a non-void return type.
  • Loading branch information
dktapps committed Oct 22, 2021
1 parent 48dfa50 commit f883e1c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/BinaryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getBuffer() : string{
}

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

/**
* @phpstan-impure
* @throws BinaryDataException
*/
public function getRemaining() : string{
Expand All @@ -98,6 +100,9 @@ public function put(string $str) : void{
$this->buffer .= $str;
}

/**
* @phpstan-impure
*/
public function getBool() : bool{
return $this->get(1) !== "\x00";
}
Expand All @@ -106,6 +111,9 @@ public function putBool(bool $v) : void{
$this->buffer .= ($v ? "\x01" : "\x00");
}

/**
* @phpstan-impure
*/
public function getByte() : int{
return ord($this->get(1));
}
Expand All @@ -114,10 +122,16 @@ public function putByte(int $v) : void{
$this->buffer .= chr($v);
}

/**
* @phpstan-impure
*/
public function getShort() : int{
return Binary::readShort($this->get(2));
}

/**
* @phpstan-impure
*/
public function getSignedShort() : int{
return Binary::readSignedShort($this->get(2));
}
Expand All @@ -126,10 +140,16 @@ public function putShort(int $v) : void{
$this->buffer .= Binary::writeShort($v);
}

/**
* @phpstan-impure
*/
public function getLShort() : int{
return Binary::readLShort($this->get(2));
}

/**
* @phpstan-impure
*/
public function getSignedLShort() : int{
return Binary::readSignedLShort($this->get(2));
}
Expand All @@ -138,6 +158,9 @@ public function putLShort(int $v) : void{
$this->buffer .= Binary::writeLShort($v);
}

/**
* @phpstan-impure
*/
public function getTriad() : int{
return Binary::readTriad($this->get(3));
}
Expand All @@ -146,6 +169,9 @@ public function putTriad(int $v) : void{
$this->buffer .= Binary::writeTriad($v);
}

/**
* @phpstan-impure
*/
public function getLTriad() : int{
return Binary::readLTriad($this->get(3));
}
Expand All @@ -154,6 +180,9 @@ public function putLTriad(int $v) : void{
$this->buffer .= Binary::writeLTriad($v);
}

/**
* @phpstan-impure
*/
public function getInt() : int{
return Binary::readInt($this->get(4));
}
Expand All @@ -162,6 +191,9 @@ public function putInt(int $v) : void{
$this->buffer .= Binary::writeInt($v);
}

/**
* @phpstan-impure
*/
public function getLInt() : int{
return Binary::readLInt($this->get(4));
}
Expand All @@ -170,10 +202,16 @@ public function putLInt(int $v) : void{
$this->buffer .= Binary::writeLInt($v);
}

/**
* @phpstan-impure
*/
public function getFloat() : float{
return Binary::readFloat($this->get(4));
}

/**
* @phpstan-impure
*/
public function getRoundedFloat(int $accuracy) : float{
return Binary::readRoundedFloat($this->get(4), $accuracy);
}
Expand All @@ -182,10 +220,16 @@ public function putFloat(float $v) : void{
$this->buffer .= Binary::writeFloat($v);
}

/**
* @phpstan-impure
*/
public function getLFloat() : float{
return Binary::readLFloat($this->get(4));
}

/**
* @phpstan-impure
*/
public function getRoundedLFloat(int $accuracy) : float{
return Binary::readRoundedLFloat($this->get(4), $accuracy);
}
Expand All @@ -194,6 +238,9 @@ public function putLFloat(float $v) : void{
$this->buffer .= Binary::writeLFloat($v);
}

/**
* @phpstan-impure
*/
public function getDouble() : float{
return Binary::readDouble($this->get(8));
}
Expand All @@ -202,6 +249,9 @@ public function putDouble(float $v) : void{
$this->buffer .= Binary::writeDouble($v);
}

/**
* @phpstan-impure
*/
public function getLDouble() : float{
return Binary::readLDouble($this->get(8));
}
Expand All @@ -210,6 +260,9 @@ public function putLDouble(float $v) : void{
$this->buffer .= Binary::writeLDouble($v);
}

/**
* @phpstan-impure
*/
public function getLong() : int{
return Binary::readLong($this->get(8));
}
Expand All @@ -218,6 +271,9 @@ public function putLong(int $v) : void{
$this->buffer .= Binary::writeLong($v);
}

/**
* @phpstan-impure
*/
public function getLLong() : int{
return Binary::readLLong($this->get(8));
}
Expand All @@ -228,6 +284,8 @@ public function putLLong(int $v) : void{

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

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

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

/**
* Reads a 64-bit zigzag-encoded variable-length integer from the buffer and returns it.
*
* @phpstan-impure
*/
public function getVarLong() : int{
return Binary::readVarLong($this->buffer, $this->offset);
Expand Down

0 comments on commit f883e1c

Please sign in to comment.