Passed
Push — develop ( 11996c...22f379 )
by Nikita
05:04
created

InfoService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A latestRelease() 0 29 4
1
<?php
2
3
namespace Gameap\Services;
4
5
use \Illuminate\Http\Response;
6
use GuzzleHttp\Client;
7
8
class InfoService
9
{
10
    /**
11
     * Get GameAP Latest Release
12
     * 
13
     * @return string
14
     */
15
    static public function latestRelease()
16
    {
17
        $client = new Client();
18
        
19
        // TODO: Remove before beta
20
        $res = $client->get('http://www.gameap.ru/gameap_version.txt');
21
22
        if ($res->getStatusCode() == Response::HTTP_OK) {
23
             $lines = explode("\n", $res->getBody()->getContents());
24
             $parts = explode(': ', $lines[0]);
25
             $latest = $parts[1];
26
             
27
             return $latest;
28
        }
29
        
30
        // GitHub
31
        // TODO: Replace before beta
32
        $res = $client->get('https://api.github.com/repos/et-nik/gameap/releases/latest');
33
34
        if ($res->getStatusCode() == Response::HTTP_OK) {
35
            $result = json_decode($res->getBody()->getContents());
36
37
            if (!empty($result->tag_name)) {
38
                return $result->tag_name;
39
            } else {
40
                return '';
41
            }
42
        } else {
43
            return '';
44
        }
45
    }
46
47
    /**
48
     * @param $report
49
     */
50
//    static public function sendBugReport($report)
51
//    {
52
//        
53
//    }
54
}