mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
tools: fix PHPStan 2.0 issues
This commit is contained in:
parent
b1c7fc017a
commit
47cb04f6a6
@ -523,10 +523,12 @@ function processRemappedStates(array $upgradeTable) : array{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$orderedUnchanged = [];
|
||||||
foreach(Utils::stringifyKeys($unchangedStatesByNewName) as $newName => $unchangedStates){
|
foreach(Utils::stringifyKeys($unchangedStatesByNewName) as $newName => $unchangedStates){
|
||||||
ksort($unchangedStates);
|
sort($unchangedStates);
|
||||||
$unchangedStatesByNewName[$newName] = $unchangedStates;
|
$orderedUnchanged[$newName] = $unchangedStates;
|
||||||
}
|
}
|
||||||
|
$unchangedStatesByNewName = $orderedUnchanged;
|
||||||
|
|
||||||
$notFlattenedProperties = [];
|
$notFlattenedProperties = [];
|
||||||
|
|
||||||
@ -656,7 +658,8 @@ function processRemappedStates(array $upgradeTable) : array{
|
|||||||
usort($list, function(BlockStateUpgradeSchemaBlockRemap $a, BlockStateUpgradeSchemaBlockRemap $b) : int{
|
usort($list, function(BlockStateUpgradeSchemaBlockRemap $a, BlockStateUpgradeSchemaBlockRemap $b) : int{
|
||||||
return count($b->oldState) <=> count($a->oldState);
|
return count($b->oldState) <=> count($a->oldState);
|
||||||
});
|
});
|
||||||
return array_values($list);
|
//usort discards keys, so this is already a list<BlockStateUpgradeSchemaBlockRemap>
|
||||||
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +76,12 @@ function find_regions_recursive(string $dir, array &$files) : void{
|
|||||||
in_array(pathinfo($fullPath, PATHINFO_EXTENSION), SUPPORTED_EXTENSIONS, true) &&
|
in_array(pathinfo($fullPath, PATHINFO_EXTENSION), SUPPORTED_EXTENSIONS, true) &&
|
||||||
is_file($fullPath)
|
is_file($fullPath)
|
||||||
){
|
){
|
||||||
$files[$fullPath] = filesize($fullPath);
|
$size = filesize($fullPath);
|
||||||
|
if($size === false){
|
||||||
|
//If we can't get the size of the file, we probably don't have perms to read it, so ignore it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$files[$fullPath] = $size;
|
||||||
}elseif(is_dir($fullPath)){
|
}elseif(is_dir($fullPath)){
|
||||||
find_regions_recursive($fullPath, $files);
|
find_regions_recursive($fullPath, $files);
|
||||||
}
|
}
|
||||||
@ -165,7 +170,8 @@ function main(array $argv) : int{
|
|||||||
clearstatcache();
|
clearstatcache();
|
||||||
$newSize = 0;
|
$newSize = 0;
|
||||||
foreach(Utils::stringifyKeys($files) as $file => $oldSize){
|
foreach(Utils::stringifyKeys($files) as $file => $oldSize){
|
||||||
$newSize += file_exists($file) ? filesize($file) : 0;
|
$size = file_exists($file) ? filesize($file) : 0;
|
||||||
|
$newSize += $size !== false ? $size : 0;
|
||||||
}
|
}
|
||||||
$diff = $currentSize - $newSize;
|
$diff = $currentSize - $newSize;
|
||||||
$logger->info("Finished compaction of " . count($files) . " files. Freed " . number_format($diff) . " bytes of space (" . round(($diff / $currentSize) * 100, 2) . "% reduction).");
|
$logger->info("Finished compaction of " . count($files) . " files. Freed " . number_format($diff) . " bytes of space (" . round(($diff / $currentSize) * 100, 2) . "% reduction).");
|
||||||
|
@ -454,7 +454,7 @@ class ParserPacketHandler extends PacketHandler{
|
|||||||
|
|
||||||
//this sorts the data into a canonical order to make diffs between versions reliable
|
//this sorts the data into a canonical order to make diffs between versions reliable
|
||||||
//how the data is ordered doesn't matter as long as it's reproducible
|
//how the data is ordered doesn't matter as long as it's reproducible
|
||||||
foreach($recipes as $_type => $entries){
|
foreach(Utils::promoteKeys($recipes) as $_type => $entries){
|
||||||
$_sortedRecipes = [];
|
$_sortedRecipes = [];
|
||||||
$_seen = [];
|
$_seen = [];
|
||||||
foreach($entries as $entry){
|
foreach($entries as $entry){
|
||||||
@ -475,10 +475,10 @@ class ParserPacketHandler extends PacketHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ksort($recipes, SORT_STRING);
|
ksort($recipes, SORT_STRING);
|
||||||
foreach($recipes as $type => $entries){
|
foreach(Utils::promoteKeys($recipes) as $type => $entries){
|
||||||
echo "$type: " . count($entries) . "\n";
|
echo "$type: " . count($entries) . "\n";
|
||||||
}
|
}
|
||||||
foreach($recipes as $type => $entries){
|
foreach(Utils::promoteKeys($recipes) as $type => $entries){
|
||||||
file_put_contents(Path::join($recipesPath, $type . '.json'), json_encode($entries, JSON_PRETTY_PRINT) . "\n");
|
file_put_contents(Path::join($recipesPath, $type . '.json'), json_encode($entries, JSON_PRETTY_PRINT) . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +31,12 @@ namespace pocketmine\tools\generate_item_upgrade_schema;
|
|||||||
|
|
||||||
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
||||||
use pocketmine\utils\Filesystem;
|
use pocketmine\utils\Filesystem;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
use function count;
|
use function count;
|
||||||
use function dirname;
|
use function dirname;
|
||||||
use function file_put_contents;
|
use function file_put_contents;
|
||||||
|
use function fwrite;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
use function json_encode;
|
use function json_encode;
|
||||||
@ -45,6 +47,7 @@ use const JSON_PRETTY_PRINT;
|
|||||||
use const JSON_THROW_ON_ERROR;
|
use const JSON_THROW_ON_ERROR;
|
||||||
use const SCANDIR_SORT_ASCENDING;
|
use const SCANDIR_SORT_ASCENDING;
|
||||||
use const SORT_STRING;
|
use const SORT_STRING;
|
||||||
|
use const STDERR;
|
||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ if(count($argv) !== 4){
|
|||||||
[, $mappingTableFile, $upgradeSchemasDir, $outputFile] = $argv;
|
[, $mappingTableFile, $upgradeSchemasDir, $outputFile] = $argv;
|
||||||
|
|
||||||
$target = json_decode(Filesystem::fileGetContents($mappingTableFile), true, JSON_THROW_ON_ERROR);
|
$target = json_decode(Filesystem::fileGetContents($mappingTableFile), true, JSON_THROW_ON_ERROR);
|
||||||
if(!is_array($target)){
|
if(!is_array($target) || !isset($target["simple"]) || !is_array($target["simple"]) || !isset($target["complex"]) || !is_array($target["complex"])){
|
||||||
\GlobalLogger::get()->error("Invalid mapping table file");
|
\GlobalLogger::get()->error("Invalid mapping table file");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -93,7 +96,7 @@ foreach($files as $file){
|
|||||||
|
|
||||||
$newDiff = [];
|
$newDiff = [];
|
||||||
|
|
||||||
foreach($target["simple"] as $oldId => $newId){
|
foreach(Utils::promoteKeys($target["simple"]) as $oldId => $newId){
|
||||||
$previousNewId = $merged["simple"][$oldId] ?? null;
|
$previousNewId = $merged["simple"][$oldId] ?? null;
|
||||||
if(
|
if(
|
||||||
$previousNewId === $newId || //if previous schemas already accounted for this
|
$previousNewId === $newId || //if previous schemas already accounted for this
|
||||||
@ -107,8 +110,12 @@ if(isset($newDiff["renamedIds"])){
|
|||||||
ksort($newDiff["renamedIds"], SORT_STRING);
|
ksort($newDiff["renamedIds"], SORT_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($target["complex"] as $oldId => $mappings){
|
foreach(Utils::promoteKeys($target["complex"]) as $oldId => $mappings){
|
||||||
foreach($mappings as $meta => $newId){
|
if(!is_array($mappings)){
|
||||||
|
fwrite(STDERR, "Complex mapping for $oldId is not an array\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
foreach(Utils::promoteKeys($mappings) as $meta => $newId){
|
||||||
if(($merged["complex"][$oldId][$meta] ?? null) !== $newId){
|
if(($merged["complex"][$oldId][$meta] ?? null) !== $newId){
|
||||||
if($oldId === "minecraft:spawn_egg" && $meta === 130 && ($newId === "minecraft:axolotl_bucket" || $newId === "minecraft:axolotl_spawn_egg")){
|
if($oldId === "minecraft:spawn_egg" && $meta === 130 && ($newId === "minecraft:axolotl_bucket" || $newId === "minecraft:axolotl_spawn_egg")){
|
||||||
//TODO: hack for vanilla bug workaround
|
//TODO: hack for vanilla bug workaround
|
||||||
|
@ -53,6 +53,10 @@ use const STR_PAD_LEFT;
|
|||||||
|
|
||||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-param positive-int $scale
|
||||||
|
* @phpstan-param positive-int $radius
|
||||||
|
*/
|
||||||
function newImage(int $scale, int $radius) : \GdImage{
|
function newImage(int $scale, int $radius) : \GdImage{
|
||||||
$image = Utils::assumeNotFalse(imagecreatetruecolor($scale * $radius * 2, $scale * $radius * 2));
|
$image = Utils::assumeNotFalse(imagecreatetruecolor($scale * $radius * 2, $scale * $radius * 2));
|
||||||
imagesavealpha($image, true);
|
imagesavealpha($image, true);
|
||||||
@ -149,6 +153,18 @@ if($radius === null){
|
|||||||
fwrite(STDERR, "Please specify a radius using --radius\n");
|
fwrite(STDERR, "Please specify a radius using --radius\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if($radius < 1){
|
||||||
|
fwrite(STDERR, "Radius cannot be less than 1\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if($scale < 1){
|
||||||
|
fwrite(STDERR, "Scale cannot be less than 1\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if($nChunksPerStep < 1){
|
||||||
|
fwrite(STDERR, "Chunks per step cannot be less than 1\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
$outputDirectory = null;
|
$outputDirectory = null;
|
||||||
if(isset($opts["output"])){
|
if(isset($opts["output"])){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user