avoid type juggling in conditions, always use explicit boolean conditions

This commit is contained in:
Dylan K. Taylor
2020-02-05 15:44:06 +00:00
parent b96bb7d824
commit e5a2cfb65f
17 changed files with 43 additions and 43 deletions

View File

@ -94,7 +94,7 @@ class AdventureSettingsPacket extends DataPacket{
}
public function getFlag(int $flag) : bool{
if($flag & self::BITFLAG_SECOND_SET){
if(($flag & self::BITFLAG_SECOND_SET) !== 0){
return ($this->flags2 & $flag) !== 0;
}
@ -105,7 +105,7 @@ class AdventureSettingsPacket extends DataPacket{
* @return void
*/
public function setFlag(int $flag, bool $value){
if($flag & self::BITFLAG_SECOND_SET){
if(($flag & self::BITFLAG_SECOND_SET) !== 0){
$flagSet =& $this->flags2;
}else{
$flagSet =& $this->flags;

View File

@ -47,7 +47,7 @@ class AnimatePacket extends DataPacket{
protected function decodePayload(){
$this->action = $this->getVarInt();
$this->entityRuntimeId = $this->getEntityRuntimeId();
if($this->action & 0x80){
if(($this->action & 0x80) !== 0){
$this->float = $this->getLFloat();
}
}
@ -55,7 +55,7 @@ class AnimatePacket extends DataPacket{
protected function encodePayload(){
$this->putVarInt($this->action);
$this->putEntityRuntimeId($this->entityRuntimeId);
if($this->action & 0x80){
if(($this->action & 0x80) !== 0){
$this->putLFloat($this->float);
}
}

View File

@ -295,13 +295,13 @@ class AvailableCommandsPacket extends DataPacket{
$parameter->isOptional = $this->getBool();
$parameter->flags = $this->getByte();
if($parameter->paramType & self::ARG_FLAG_ENUM){
if(($parameter->paramType & self::ARG_FLAG_ENUM) !== 0){
$index = ($parameter->paramType & 0xffff);
$parameter->enum = $enums[$index] ?? null;
if($parameter->enum === null){
throw new \UnexpectedValueException("deserializing $retval->commandName parameter $parameter->paramName: expected enum at $index, but got none");
}
}elseif($parameter->paramType & self::ARG_FLAG_POSTFIX){
}elseif(($parameter->paramType & self::ARG_FLAG_POSTFIX) !== 0){
$index = ($parameter->paramType & 0xffff);
$parameter->postfix = $postfixes[$index] ?? null;
if($parameter->postfix === null){
@ -365,8 +365,8 @@ class AvailableCommandsPacket extends DataPacket{
* @phpstan-param array<int, string> $postfixes
*/
private function argTypeToString(int $argtype, array $postfixes) : string{
if($argtype & self::ARG_FLAG_VALID){
if($argtype & self::ARG_FLAG_ENUM){
if(($argtype & self::ARG_FLAG_VALID) !== 0){
if(($argtype & self::ARG_FLAG_ENUM) !== 0){
return "stringenum (" . ($argtype & 0xffff) . ")";
}
@ -392,7 +392,7 @@ class AvailableCommandsPacket extends DataPacket{
case self::ARG_TYPE_COMMAND:
return "command";
}
}elseif($argtype & self::ARG_FLAG_POSTFIX){
}elseif(($argtype & self::ARG_FLAG_POSTFIX) !== 0){
$postfix = $postfixes[$argtype & 0xffff];
return "int (postfix $postfix)";

View File

@ -55,14 +55,14 @@ class MoveActorDeltaPacket extends DataPacket{
public $zRot = 0.0;
private function maybeReadCoord(int $flag) : int{
if($this->flags & $flag){
if(($this->flags & $flag) !== 0){
return $this->getVarInt();
}
return 0;
}
private function maybeReadRotation(int $flag) : float{
if($this->flags & $flag){
if(($this->flags & $flag) !== 0){
return $this->getByteRotation();
}
return 0.0;
@ -80,13 +80,13 @@ class MoveActorDeltaPacket extends DataPacket{
}
private function maybeWriteCoord(int $flag, int $val) : void{
if($this->flags & $flag){
if(($this->flags & $flag) !== 0){
$this->putVarInt($val);
}
}
private function maybeWriteRotation(int $flag, float $val) : void{
if($this->flags & $flag){
if(($this->flags & $flag) !== 0){
$this->putByteRotation($val);
}
}