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.
Passed
Push — develop ( 778e0b...be0e2b )
by James
11:02
created

UpdateRequest::getVersion()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 26
rs 9.3888
c 1
b 0
f 0
cc 5
nc 6
nop 1
1
<?php
2
/**
3
 * UpdateRequest.php
4
 * Copyright (c) 2019 [email protected]
5
 *
6
 * This file is part of Firefly III (https://github.com/firefly-iii).
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace FireflyIII\Services\FireflyIIIOrg\Update;
23
24
use Exception;
25
use FireflyIII\Exceptions\FireflyException;
26
use GuzzleHttp\Client;
27
use GuzzleHttp\Exception\GuzzleException;
28
use JsonException;
29
use Log;
30
31
/**
32
 * Class UpdateRequest
33
 */
34
class UpdateRequest implements UpdateRequestInterface
35
{
36
37
    /**
38
     * @param string $channel
39
     *
40
     * @return array
41
     * @throws FireflyException
42
     */
43
    public function getVersion(string $channel): array
44
    {
45
        $uri = 'https://version.firefly-iii.org/index.json';
46
        Log::debug(sprintf('Going to call %s', $uri));
47
        try {
48
            $client = new Client();
49
            $res    = $client->request('GET', $uri);
50
        } catch (GuzzleException|Exception $e) {
51
            throw new FireflyException(sprintf('Response error from update check: %s', $e->getMessage()));
52
        }
53
54
        if (200 !== $res->getStatusCode()) {
55
            throw new FireflyException(sprintf('Returned error code %d from update check.', $res->getStatusCode()));
56
        }
57
        $body = (string)$res->getBody();
58
        try {
59
            $json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
60
        } catch (JsonException $e) {
61
            throw new FireflyException('Invalid JSON in server response.');
62
        }
63
64
        if (!isset($json[$channel])) {
65
            throw new FireflyException(sprintf('Unknown update channel "%s"', $channel));
66
        }
67
68
        return $json[$channel];
69
    }
70
}