mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Make use of Utils::assumeNotFalse() in a bunch of places
I've stuck to only doing this in the places where I'm sure we should never get false back. Other places I'm less sure of (and I found more bugs along the way).
This commit is contained in:
@@ -79,8 +79,7 @@ final class Filesystem{
|
||||
|
||||
public static function recursiveUnlink(string $dir) : void{
|
||||
if(is_dir($dir)){
|
||||
$objects = scandir($dir, SCANDIR_SORT_NONE);
|
||||
if($objects === false) throw new AssumptionFailedError("scandir() shouldn't return false when is_dir() returns true");
|
||||
$objects = Utils::assumeNotFalse(scandir($dir, SCANDIR_SORT_NONE), "scandir() shouldn't return false when is_dir() returns true");
|
||||
foreach($objects as $object){
|
||||
if($object !== "." and $object !== ".."){
|
||||
$fullObject = Path::join($dir, $object);
|
||||
@@ -127,8 +126,7 @@ final class Filesystem{
|
||||
}
|
||||
mkdir($destination); //TODO: access permissions?
|
||||
}
|
||||
$objects = scandir($origin, SCANDIR_SORT_NONE);
|
||||
if($objects === false) throw new AssumptionFailedError("scandir() shouldn't return false when is_dir() returns true");
|
||||
$objects = Utils::assumeNotFalse(scandir($origin, SCANDIR_SORT_NONE));
|
||||
foreach($objects as $object){
|
||||
if($object === "." || $object === ".."){
|
||||
continue;
|
||||
@@ -193,7 +191,7 @@ final class Filesystem{
|
||||
//wait for a shared lock to avoid race conditions if two servers started at the same time - this makes sure the
|
||||
//other server wrote its PID and released exclusive lock before we get our lock
|
||||
flock($resource, LOCK_SH);
|
||||
$pid = stream_get_contents($resource);
|
||||
$pid = Utils::assumeNotFalse(stream_get_contents($resource), "This is a known valid file resource, at worst we should receive an empty string");
|
||||
if(preg_match('/^\d+$/', $pid) === 1){
|
||||
return (int) $pid;
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ abstract class Timezone{
|
||||
}
|
||||
|
||||
public static function init() : void{
|
||||
$timezone = ini_get("date.timezone");
|
||||
$timezone = Utils::assumeNotFalse(ini_get("date.timezone"), "date.timezone should always be set in ini");
|
||||
if($timezone !== ""){
|
||||
/*
|
||||
* This is here so that people don't come to us complaining and fill up the issue tracker when they put
|
||||
|
Reference in New Issue
Block a user