Skip to content

Commit

Permalink
cleaner version check
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Oct 27, 2017
1 parent 7638cea commit d92887e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/Utilities/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,25 @@ public static function latest($modules = array())

public static function getLatestVersion($url)
{
$latest = '0.0.0';

$response = static::getRemote($url, ['timeout' => 30, 'referer' => true]);

if ($response->getStatusCode() == 200) {
$version = json_decode($response->getBody())->data;
// Bad response
if ($response->getStatusCode() != 200) {
return $latest;
}

if (is_object($version)) {
$latest = $version->latest;
} else {
$latest = '0.0.0';
}
} else {
$latest = '0.0.0';
$content = json_decode($response->getBody());

// Empty response
if (!is_object($content) || !is_object($content->data)) {
return $latest;
}

// Get the latest version
$latest = $content->data->latest;

return $latest;
}
}

0 comments on commit d92887e

Please sign in to comment.