Use JSON_THROW_ON_ERROR for json_encode() and json_decode()

This commit is contained in:
Dylan K. Taylor
2021-12-08 19:14:07 +00:00
parent c6466a6da9
commit 8b73549355
9 changed files with 20 additions and 51 deletions

View File

@ -27,7 +27,6 @@ use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\player\Player;
use pocketmine\scheduler\AsyncTask;
use pocketmine\Server;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Internet;
use pocketmine\utils\Process;
use pocketmine\utils\Utils;
@ -37,11 +36,11 @@ use function array_map;
use function array_values;
use function count;
use function json_encode;
use function json_last_error_msg;
use function md5;
use function microtime;
use function php_uname;
use function strlen;
use const JSON_THROW_ON_ERROR;
use const PHP_VERSION;
class SendUsageTask extends AsyncTask{
@ -150,9 +149,7 @@ class SendUsageTask extends AsyncTask{
}
$this->endpoint = $endpoint . "api/post";
$data = json_encode($data/*, JSON_PRETTY_PRINT*/);
if($data === false) throw new AssumptionFailedError("Statistics JSON should never fail to encode: " . json_last_error_msg());
$this->data = $data;
$this->data = json_encode($data, /*JSON_PRETTY_PRINT |*/ JSON_THROW_ON_ERROR);
}
public function onRun() : void{