for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Gameap\Services;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Http\Response;
class InfoService
{
private const GAMEAP_LATEST_VERSION_URI = 'http://www.gameap.ru/gameap_version.txt';
private const GITHUB_LATEST_VERSION_URI = 'https://api.github.com/repos/et-nik/gameap/releases/latest';
/** @var Client */
private $client;
public function __construct(Client $client)
$this->client = $client;
}
public function latestRelease(): string
$version = $this->loadVersionFromGameap();
if ($version === '') {
$version = $this->loadVersionFromGithub();
return $version;
private function loadVersionFromGameap(): string
try {
$res = $this->client->get(self::GAMEAP_LATEST_VERSION_URI);
} catch (RequestException $e) {
return '';
if ($res->getStatusCode() === Response::HTTP_OK) {
$lines = explode("\n", $res->getBody()->getContents());
$parts = explode(': ', $lines[0]);
return $parts[1];
private function loadVersionFromGithub(): string
$res = $this->client->get(self::GITHUB_LATEST_VERSION_URI);
$result = json_decode($res->getBody()->getContents());
if (!empty($result->tag_name)) {
return $result->tag_name;