Use Utils::assumeNotFalse() in tools/

This commit is contained in:
Dylan K. Taylor 2021-12-08 20:01:19 +00:00
parent 77a74d84e2
commit 2254f31bec
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 11 additions and 30 deletions

View File

@ -25,7 +25,6 @@ namespace pocketmine\generate_permission_doc;
use pocketmine\permission\DefaultPermissions;
use pocketmine\permission\PermissionManager;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use pocketmine\VersionInfo;
use Webmozart\PathUtil\Path;
@ -48,10 +47,7 @@ function markdownify(string $name) : string{
}
DefaultPermissions::registerCorePermissions();
$cwd = getcwd();
if($cwd === false){
throw new AssumptionFailedError("getcwd() returned false");
}
$cwd = Utils::assumeNotFalse(getcwd());
$output = Path::join($cwd, "core-permissions.md");
echo "Writing output to $output\n";
$doc = fopen($output, "wb");

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\tools\ping_server;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use raklib\protocol\MessageIdentifiers;
use raklib\protocol\PacketSerializer;
use raklib\protocol\UnconnectedPing;
@ -137,8 +137,7 @@ if(count($argv) > 2){
$port = $portRaw === "" ? 19132 : (int) $portRaw;
}
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if($sock === false) throw new AssumptionFailedError();
$sock = Utils::assumeNotFalse(socket_create(AF_INET, SOCK_DGRAM, SOL_UDP));
socket_bind($sock, "0.0.0.0");
socket_getsockname($sock, $bindAddr, $bindPort);

View File

@ -37,16 +37,10 @@ use const STR_PAD_LEFT;
require dirname(__DIR__) . '/vendor/autoload.php';
function newImage(int $scale, int $radius) : \GdImage{
$image = imagecreatetruecolor($scale * $radius * 2, $scale * $radius * 2);
if($image === false){
throw new AssumptionFailedError();
}
$image = Utils::assumeNotFalse(imagecreatetruecolor($scale * $radius * 2, $scale * $radius * 2));
imagesavealpha($image, true);
$black = imagecolorallocate($image, 0, 0, 0);
if($black === false){
throw new AssumptionFailedError();
}
$black = Utils::assumeNotFalse(imagecolorallocate($image, 0, 0, 0));
imagefill($image, 0, 0, $black);
return $image;
}
@ -58,10 +52,9 @@ function render(int $radius, int $baseX, int $baseZ, int $chunksPerStep, int $sc
$middleOffsetX = $scale * ($radius + $offsetX);
$middleOffsetZ = $scale * ($radius + $offsetZ);
$black = imagecolorallocate($image, 0, 0, 0);
$yellow = imagecolorallocate($image, 255, 255, 51);
$red = imagecolorallocate($image, 255, 0, 0);
if($black === false || $yellow === false || $red === false) throw new AssumptionFailedError();
$black = Utils::assumeNotFalse(imagecolorallocate($image, 0, 0, 0));
$yellow = Utils::assumeNotFalse(imagecolorallocate($image, 255, 255, 51));
$red = Utils::assumeNotFalse(imagecolorallocate($image, 255, 0, 0));
$frame = 0;
$seen = [];
@ -152,11 +145,7 @@ foreach(Utils::stringifyKeys(getopt("", ["output:"])) as $name => $value){
fwrite(STDERR, "Output directory $value is not empty\n");
exit(1);
}
$realPath = realpath($value);
if($realPath === false){
throw new AssumptionFailedError();
}
$outputDirectory = $realPath;
$outputDirectory = Utils::assumeNotFalse(realpath($value), "We just created this directory, we should be able to get its realpath");
}
if($outputDirectory === null){
fwrite(STDERR, "Please specify an output directory using --output\n");
@ -164,9 +153,6 @@ if($outputDirectory === null){
}
$image = newImage($scale, $radius);
$black = imagecolorallocate($image, 0, 0, 0);
$green = imagecolorallocate($image, 0, 220, 0);
if($black === false || $green === false){
throw new AssumptionFailedError();
}
$black = Utils::assumeNotFalse(imagecolorallocate($image, 0, 0, 0));
$green = Utils::assumeNotFalse(imagecolorallocate($image, 0, 220, 0));
render($radius, $baseX, $baseZ, $nChunksPerStep, $scale, $image, $green, 0, 0, $outputDirectory);