Filesystem: added fileGetContents to reduce ErrorToExceptionHandler boilerplate code

This commit is contained in:
Dylan K. Taylor
2022-12-25 17:13:51 +00:00
parent b1c0eae1f6
commit 0d169b4e80
16 changed files with 53 additions and 51 deletions

View File

@@ -24,11 +24,10 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Filesystem;
use pocketmine\utils\SingletonTrait;
use pocketmine\utils\Utils;
use Symfony\Component\Filesystem\Path;
use function explode;
use function file_get_contents;
use function is_array;
use function is_int;
use function is_numeric;
@@ -53,7 +52,7 @@ final class LegacyStringToItemParser{
private static function make() : self{
$result = new self(ItemFactory::getInstance());
$mappingsRaw = Utils::assumeNotFalse(@file_get_contents(Path::join(\pocketmine\RESOURCE_PATH, 'item_from_string_bc_map.json')), "Missing required resource file");
$mappingsRaw = Filesystem::fileGetContents(Path::join(\pocketmine\RESOURCE_PATH, 'item_from_string_bc_map.json'));
$mappings = json_decode($mappingsRaw, true);
if(!is_array($mappings)) throw new AssumptionFailedError("Invalid mappings format, expected array");