Avoid usage of for-loop vars outside of for-loop context

these problems were reported by PHPStan strict rules. They aren't actually bugs, but they could become bugs in the future.
This commit is contained in:
Dylan K. Taylor 2020-02-05 13:16:09 +00:00
parent 88afedd1e8
commit 99038c752c
5 changed files with 14 additions and 12 deletions

View File

@ -411,8 +411,8 @@ class Chunk{
* @return int New calculated heightmap value (0-256 inclusive)
*/
public function recalculateHeightMapColumn(int $x, int $z) : int{
$max = $this->getHighestBlockAt($x, $z);
for($y = $max; $y >= 0; --$y){
$y = $this->getHighestBlockAt($x, $z);
for(; $y >= 0; --$y){
if(BlockFactory::$lightFilter[$id = $this->getBlockId($x, $y, $z)] > 1 or BlockFactory::$diffusesSkyLight[$id]){
break;
}
@ -438,9 +438,9 @@ class Chunk{
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$y = $maxY;
$heightMap = $this->getHeightMap($x, $z);
for($y = $maxY; $y >= $heightMap; --$y){
for(; $y >= $heightMap; --$y){
$this->setBlockSkyLight($x, $y, $z, 15);
}
@ -805,10 +805,10 @@ class Chunk{
//No need to thoroughly prune empties at runtime, this will just reduce performance.
continue;
}
break;
return $y;
}
return $y;
return -1;
}
/**

View File

@ -47,7 +47,8 @@ class GroundCover extends Populator{
}
$column = $chunk->getBlockIdColumn($x, $z);
for($y = 127; $y > 0; --$y){
$y = 127;
for(; $y > 0; --$y){
if($column[$y] !== "\x00" and !BlockFactory::get(ord($column[$y]))->isTransparent()){
break;
}

View File

@ -77,10 +77,10 @@ class TallGrass extends Populator{
for($y = 127; $y >= 0; --$y){
$b = $this->level->getBlockIdAt($x, $y, $z);
if($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2 and $b !== Block::SNOW_LAYER){
break;
return $y + 1;
}
}
return $y === 0 ? -1 : ++$y;
return -1;
}
}

View File

@ -83,12 +83,12 @@ class Tree extends Populator{
for($y = 127; $y > 0; --$y){
$b = $this->level->getBlockIdAt($x, $y, $z);
if($b === Block::DIRT or $b === Block::GRASS){
break;
return $y + 1;
}elseif($b !== Block::AIR and $b !== Block::SNOW_LAYER){
return -1;
}
}
return ++$y;
return -1;
}
}

View File

@ -287,7 +287,8 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
if($quoteType === null){
$quoteType = $raw[$i];
}elseif($raw[$i] === $quoteType){
for($backslashes = 0; $backslashes < $i && $raw[$i - $backslashes - 1] === "\\"; ++$backslashes){}
$backslashes = 0;
for(; $backslashes < $i && $raw[$i - $backslashes - 1] === "\\"; ++$backslashes){}
if(($backslashes % 2) === 0){ //unescaped quote
$quoteType = null;
}