Server: harden response handling for crash report submission

this eliminates some checkImplicitMixed errors in phpstan.
This commit is contained in:
Dylan K. Taylor 2022-09-02 19:13:54 +01:00
parent 033dac3d16
commit 770cca2efa
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1651,12 +1651,14 @@ class Server{
], 10, [], $postUrlError);
if($reply !== null && is_object($data = json_decode($reply->getBody()))){
if(isset($data->crashId) && isset($data->crashUrl)){
if(isset($data->crashId) && is_int($data->crashId) && isset($data->crashUrl) && is_string($data->crashUrl)){
$reportId = $data->crashId;
$reportUrl = $data->crashUrl;
$this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_archive($reportUrl, (string) $reportId)));
}elseif(isset($data->error)){
}elseif(isset($data->error) && is_string($data->error)){
$this->logger->emergency("Automatic crash report submission failed: $data->error");
}else{
$this->logger->emergency("Invalid JSON response received from crash archive: " . $reply->getBody());
}
}else{
$this->logger->emergency("Failed to communicate with crash archive: $postUrlError");