GitHubService::latestTimeVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Juanber84\Services;
4
5
class GitHubService
6
{
7
    const URL = 'https://api.github.com/repos/juanber84/dep/releases/latest';
8
9
    public function latestRelease()
10
    {
11
        $ch = curl_init();
12
        $timeout = 5;
13
        curl_setopt($ch, CURLOPT_URL, self::URL);
14
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
15
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
16
        curl_setopt($ch,CURLOPT_USERAGENT,'Awesome-Octocat-App');
17
        $data = curl_exec($ch);
18
        curl_close($ch);
19
20
        $latestRelease = json_decode($data, true);
21
22
        return $latestRelease;
23
    }
24
25
    public function latestTimeVersion()
26
    {
27
        $latestRelease = $this->latestRelease();
28
        $latestVersion = strtotime($latestRelease['created_at']);
29
30
        return $latestVersion;
31
    }
32
33
    public function latestBrowserDownloadUrl()
34
    {
35
        $latestRelease = $this->latestRelease();
36
        $latestBrowserDownloadUrl = $latestRelease['assets'][0]['browser_download_url'];
37
38
        return $latestBrowserDownloadUrl;
39
    }
40
}