drop a few more useless static variables

phpstan is better able to understand constant literals, since it knows their types will never change.
This commit is contained in:
Dylan K. Taylor 2020-09-05 18:43:22 +01:00
parent b96565faa4
commit 6054104ecb
2 changed files with 23 additions and 24 deletions

View File

@ -36,33 +36,33 @@ final class BlockDataSerializer{
* @throws InvalidBlockStateException
*/
public static function readFacing(int $raw) : int{
static $map = [ //this is for redundancy, for when/if the FACING constant values change
$result = [ //this is for redundancy, for when/if the FACING constant values change
0 => Facing::DOWN,
1 => Facing::UP,
2 => Facing::NORTH,
3 => Facing::SOUTH,
4 => Facing::WEST,
5 => Facing::EAST
];
if(!isset($map[$raw])){
][$raw] ?? null;
if($result === null){
throw new InvalidBlockStateException("Invalid facing $raw");
}
return $map[$raw];
return $result;
}
public static function writeFacing(int $facing) : int{
static $map = [ //again, for redundancy
$result = [ //again, for redundancy
Facing::DOWN => 0,
Facing::UP => 1,
Facing::NORTH => 2,
Facing::SOUTH => 3,
Facing::WEST => 4,
Facing::EAST => 5
];
if(!isset($map[$facing])){
][$facing] ?? null;
if($result === null){
throw new \InvalidArgumentException("Invalid facing $facing");
}
return $map[$facing];
return $result;
}
/**
@ -87,29 +87,29 @@ final class BlockDataSerializer{
* @throws InvalidBlockStateException
*/
public static function readLegacyHorizontalFacing(int $raw) : int{
static $map = [ //again, for redundancy
$result = [ //again, for redundancy
0 => Facing::SOUTH,
1 => Facing::WEST,
2 => Facing::NORTH,
3 => Facing::EAST
];
if(!isset($map[$raw])){
][$raw] ?? null;
if($result === null){
throw new InvalidBlockStateException("Invalid legacy facing $raw");
}
return $map[$raw];
return $result;
}
public static function writeLegacyHorizontalFacing(int $facing) : int{
static $map = [
$result = [
Facing::SOUTH => 0,
Facing::WEST => 1,
Facing::NORTH => 2,
Facing::EAST => 3
];
if(!isset($map[$facing])){
][$facing] ?? null;
if($result === null){
throw new \InvalidArgumentException("Invalid Y-axis facing");
}
return $map[$facing];
return $result;
}
/**

View File

@ -62,25 +62,24 @@ trait PillarRotationTrait{
}
protected function readAxisFromMeta(int $meta) : void{
static $map = [
$axis = $meta >> $this->getAxisMetaShift();
$mapped = [
0 => Axis::Y,
1 => Axis::X,
2 => Axis::Z
];
$axis = $meta >> $this->getAxisMetaShift();
if(!isset($map[$axis])){
][$axis] ?? null;
if($mapped === null){
throw new InvalidBlockStateException("Invalid axis meta $axis");
}
$this->axis = $map[$axis];
$this->axis = $mapped;
}
protected function writeAxisToMeta() : int{
static $bits = [
return [
Axis::Y => 0,
Axis::Z => 2,
Axis::X => 1
];
return $bits[$this->axis] << $this->getAxisMetaShift();
][$this->axis] << $this->getAxisMetaShift();
}
/**