GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

VersionService::getDaemon()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace Pterodactyl\Services;
26
27
use Cache;
28
use GuzzleHttp\Client;
29
30
class VersionService
31
{
32
    /**
33
     * The cached CDN response.
34
     *
35
     * @var object
36
     */
37
    protected static $versions;
38
39
    /**
40
     * Version constructor.
41
     *
42
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
43
     */
44
    public function __construct()
45
    {
46
        self::$versions = Cache::remember('versions', config('pterodactyl.cdn.cache'), function () {
47
            $client = new Client();
48
49
            try {
50
                $response = $client->request('GET', config('pterodactyl.cdn.url'));
51
52
                if ($response->getStatusCode() === 200) {
53
                    return json_decode($response->getBody());
54
                } else {
55
                    throw new \Exception('Invalid response code.');
56
                }
57
            } catch (\Exception $ex) {
58
                // Failed request, just return errored version.
59
                return (object) [
60
                    'panel' => 'error',
61
                    'daemon' => 'error',
62
                    'discord' => 'https://pterodactyl.io/discord',
63
                ];
64
            }
65
        });
66
    }
67
68
    /**
69
     * Return current panel version from CDN.
70
     *
71
     * @return string
72
     */
73
    public static function getPanel()
74
    {
75
        return self::$versions->panel;
76
    }
77
78
    /**
79
     * Return current daemon version from CDN.
80
     *
81
     * @return string
82
     */
83
    public static function getDaemon()
84
    {
85
        return self::$versions->daemon;
86
    }
87
88
    /**
89
     * Return Discord link from CDN.
90
     *
91
     * @return string
92
     */
93
    public static function getDiscord()
94
    {
95
        return self::$versions->discord;
96
    }
97
98
    /**
99
     * Return current panel version.
100
     *
101
     * @return null|string
102
     */
103
    public function getCurrentPanel()
104
    {
105
        return config('app.version');
106
    }
107
108
    /**
109
     * Determine if panel is latest version.
110
     *
111
     * @return bool
112
     */
113
    public static function isLatestPanel()
114
    {
115
        if (config('app.version') === 'canary') {
116
            return true;
117
        }
118
119
        return version_compare(config('app.version'), self::$versions->panel) >= 0;
120
    }
121
122
    /**
123
     * Determine if daemon is latest version.
124
     *
125
     * @return bool
126
     */
127
    public static function isLatestDaemon($daemon)
128
    {
129
        if ($daemon === '0.0.0-canary') {
130
            return true;
131
        }
132
133
        return version_compare($daemon, self::$versions->daemon) >= 0;
134
    }
135
}
136