Replace disallowed operators in src/world/

This commit is contained in:
Dylan K. Taylor
2022-01-20 19:05:23 +00:00
parent 282b430b1f
commit aae5962f6a
30 changed files with 102 additions and 102 deletions

View File

@ -48,7 +48,7 @@ final class BiomeArray{
}
private static function idx(int $x, int $z) : int{
if($x < 0 or $x >= 16 or $z < 0 or $z >= 16){
if($x < 0 || $x >= 16 || $z < 0 || $z >= 16){
throw new \InvalidArgumentException("x and z must be in the range 0-15");
}
return ($z << 4) | $x;
@ -59,7 +59,7 @@ final class BiomeArray{
}
public function set(int $x, int $z, int $biomeId) : void{
if($biomeId < 0 or $biomeId >= 256){
if($biomeId < 0 || $biomeId >= 256){
throw new \InvalidArgumentException("Biome ID must be in the range 0-255");
}
$this->payload[self::idx($x, $z)] = chr($biomeId);

View File

@ -197,7 +197,7 @@ class Chunk{
}
$pos = $tile->getPosition();
if(isset($this->tiles[$index = Chunk::blockHash($pos->x, $pos->y, $pos->z)]) and $this->tiles[$index] !== $tile){
if(isset($this->tiles[$index = Chunk::blockHash($pos->x, $pos->y, $pos->z)]) && $this->tiles[$index] !== $tile){
throw new \InvalidArgumentException("Another tile is already at this location");
}
$this->tiles[$index] = $tile;
@ -292,7 +292,7 @@ class Chunk{
* Sets a subchunk in the chunk index
*/
public function setSubChunk(int $y, ?SubChunk $subChunk) : void{
if($y < self::MIN_SUBCHUNK_INDEX or $y > self::MAX_SUBCHUNK_INDEX){
if($y < self::MIN_SUBCHUNK_INDEX || $y > self::MAX_SUBCHUNK_INDEX){
throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");
}

View File

@ -50,7 +50,7 @@ final class HeightArray{
}
private static function idx(int $x, int $z) : int{
if($x < 0 or $x >= 16 or $z < 0 or $z >= 16){
if($x < 0 || $x >= 16 || $z < 0 || $z >= 16){
throw new \InvalidArgumentException("x and z must be in the range 0-15");
}
return ($z << 4) | $x;

View File

@ -63,7 +63,7 @@ final class WorldProviderManager{
public function addProvider(WorldProviderManagerEntry $providerEntry, string $name, bool $overwrite = false) : void{
$name = strtolower($name);
if(!$overwrite and isset($this->providers[$name])){
if(!$overwrite && isset($this->providers[$name])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
}

View File

@ -144,7 +144,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
}
public static function isValid(string $path) : bool{
return file_exists(Path::join($path, "level.dat")) and is_dir(Path::join($path, "db"));
return file_exists(Path::join($path, "level.dat")) && is_dir(Path::join($path, "db"));
}
public static function generate(string $path, string $name, WorldCreationOptions $options) : void{
@ -207,7 +207,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
* @return PalettedBlockArray[]
*/
protected function deserializeLegacyExtraData(string $index, int $chunkVersion) : array{
if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) === false or $extraRawData === ""){
if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) === false || $extraRawData === ""){
return [];
}
@ -391,7 +391,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
/** @var CompoundTag[] $entities */
$entities = [];
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false && $entityData !== ""){
try{
$entities = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($entityData));
}catch(NbtDataException $e){
@ -401,7 +401,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
/** @var CompoundTag[] $tiles */
$tiles = [];
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false && $tileData !== ""){
try{
$tiles = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($tileData));
}catch(NbtDataException $e){
@ -527,7 +527,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
public function getAllChunks(bool $skipCorrupted = false, ?\Logger $logger = null) : \Generator{
foreach($this->db->getIterator() as $key => $_){
if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){
if(strlen($key) === 9 && substr($key, -1) === self::TAG_VERSION){
$chunkX = Binary::readLInt(substr($key, 0, 4));
$chunkZ = Binary::readLInt(substr($key, 4, 4));
try{
@ -549,7 +549,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
public function calculateChunkCount() : int{
$count = 0;
foreach($this->db->getIterator() as $key => $_){
if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){
if(strlen($key) === 9 && substr($key, -1) === self::TAG_VERSION){
$count++;
}
}

View File

@ -95,7 +95,7 @@ final class RegionGarbageMap{
/** @var int|null $prevIndex */
$prevIndex = null;
foreach($this->entries as $k => $entry){
if($prevIndex !== null and $this->entries[$prevIndex]->getLastSector() + 1 === $entry->getFirstSector()){
if($prevIndex !== null && $this->entries[$prevIndex]->getLastSector() + 1 === $entry->getFirstSector()){
//this SHOULD overwrite the previous index and not appear at the end
$this->entries[$prevIndex] = new RegionLocationTableEntry(
$this->entries[$prevIndex]->getFirstSector(),

View File

@ -169,7 +169,7 @@ class RegionLoader{
}
$compression = $stream->getByte();
if($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){
if($compression !== self::COMPRESSION_ZLIB && $compression !== self::COMPRESSION_GZIP){
throw new CorruptedChunkException("Invalid compression type (got $compression, expected " . self::COMPRESSION_ZLIB . " or " . self::COMPRESSION_GZIP . ")");
}
@ -192,7 +192,7 @@ class RegionLoader{
$endGarbage = $this->garbageTable->end();
$nextSector = $this->nextSector;
for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){
for(; $endGarbage !== null && $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){
$nextSector = $endGarbage->getFirstSector();
$this->garbageTable->remove($endGarbage);
}
@ -267,7 +267,7 @@ class RegionLoader{
* @throws \InvalidArgumentException
*/
protected static function getChunkOffset(int $x, int $z) : int{
if($x < 0 or $x > 31 or $z < 0 or $z > 31){
if($x < 0 || $x > 31 || $z < 0 || $z > 31){
throw new \InvalidArgumentException("Invalid chunk position in region, expected x/z in range 0-31, got x=$x, z=$z");
}
return $x | ($z << 5);
@ -298,7 +298,7 @@ class RegionLoader{
fseek($this->filePointer, 0);
$headerRaw = fread($this->filePointer, self::REGION_HEADER_LENGTH);
if($headerRaw === false or strlen($headerRaw) !== self::REGION_HEADER_LENGTH){
if($headerRaw === false || strlen($headerRaw) !== self::REGION_HEADER_LENGTH){
throw new CorruptedRegionException("Corrupted region header (unexpected end of file)");
}
@ -311,7 +311,7 @@ class RegionLoader{
$sectorCount = $index & 0xff;
$timestamp = $data[$i + 1025];
if($offset === 0 or $sectorCount === 0){
if($offset === 0 || $sectorCount === 0){
$this->locationTable[$i] = null;
}elseif($offset >= self::FIRST_SECTOR){
$this->bumpNextFreeSector($this->locationTable[$i] = new RegionLocationTableEntry($offset, $sectorCount, $timestamp));

View File

@ -38,7 +38,7 @@ class RegionLocationTableEntry{
* @throws \InvalidArgumentException
*/
public function __construct(int $firstSector, int $sectorCount, int $timestamp){
if($firstSector < 0 or $firstSector >= 2 ** 24){
if($firstSector < 0 || $firstSector >= 2 ** 24){
throw new \InvalidArgumentException("Start sector must be positive, got $firstSector");
}
$this->firstSector = $firstSector;
@ -79,10 +79,10 @@ class RegionLocationTableEntry{
$entry2Last = $entry2->getLastSector();
return (
($entry2->firstSector >= $entry1->firstSector and $entry2->firstSector <= $entry1Last) or
($entry2Last >= $entry1->firstSector and $entry2Last <= $entry1Last)
($entry2->firstSector >= $entry1->firstSector && $entry2->firstSector <= $entry1Last) ||
($entry2Last >= $entry1->firstSector && $entry2Last <= $entry1Last)
);
};
return $overlapCheck($this, $other) or $overlapCheck($other, $this);
return $overlapCheck($this, $other) || $overlapCheck($other, $this);
}
}

View File

@ -59,7 +59,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
abstract protected static function getPcWorldFormatVersion() : int;
public static function isValid(string $path) : bool{
if(file_exists(Path::join($path, "level.dat")) and is_dir($regionPath = Path::join($path, "region"))){
if(file_exists(Path::join($path, "level.dat")) && is_dir($regionPath = Path::join($path, "region"))){
foreach(scandir($regionPath, SCANDIR_SORT_NONE) as $file){
$extPos = strrpos($file, ".");
if($extPos !== false && substr($file, $extPos + 1) === static::getRegionFileExtension()){
@ -191,7 +191,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
public function loadChunk(int $chunkX, int $chunkZ) : ?ChunkData{
$regionX = $regionZ = null;
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
assert(is_int($regionX) and is_int($regionZ));
assert(is_int($regionX) && is_int($regionZ));
if(!file_exists($this->pathToRegion($regionX, $regionZ))){
return null;