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 ( 9a028d...cbc92d )
by James
21:36 queued 11:23
created

UpdateTrait::parseResult()   B

Complexity

Conditions 7
Paths 40

Size

Total Lines 48
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 48
rs 8.4906
c 0
b 0
f 0
cc 7
nc 40
nop 2
1
<?php
2
/**
3
 * UpdateTrait.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
declare(strict_types=1);
23
24
namespace FireflyIII\Helpers\Update;
25
26
use Carbon\Carbon;
27
use FireflyIII\Exceptions\FireflyException;
28
use FireflyIII\Services\FireflyIIIOrg\Update\UpdateRequestInterface;
29
use Log;
30
31
/**
32
 * Trait UpdateTrait
33
 *
34
 */
35
trait UpdateTrait
36
{
37
    /**
38
     * Get object for the latest release from GitHub.
39
     *
40
     * @return array
41
     * @throws FireflyException
42
     */
43
    public function getLatestRelease(): array
44
    {
45
        Log::debug('Now in getLatestRelease()');
46
        /** @var UpdateRequestInterface $checker */
47
        $checker = app(UpdateRequestInterface::class);
48
        $channel = app('fireflyconfig')->get('update_channel', 'stable')->data;
49
50
        return $checker->getVersion($channel);
51
    }
52
53
    /**
54
     * Parses the version check result in a human readable sentence.
55
     *
56
     * @param int   $versionCheck
57
     * @param array $information
58
     *
59
     * @return string
60
     */
61
    public function parseResult(int $versionCheck, array $information): string
62
    {
63
        Log::debug(sprintf('Now in parseResult(%d)', $versionCheck));
64
        $current   = (string)config('firefly.version');
65
        $return    = '';
66
        $triggered = false;
67
        if (-1 === $versionCheck) {
68
            $triggered         = true;
69
            $monthAndDayFormat = (string)trans('config.month_and_day');
70
            $carbon            = Carbon::createFromFormat('Y-m-d', $information['date']);
71
            $return            = (string)trans(
72
                'firefly.update_new_version_alert',
73
                [
74
                    'your_version' => $current,
75
                    'new_version'  => $information['version'],
76
                    'date'         => $carbon->formatLocalized($monthAndDayFormat),
77
                ]
78
            );
79
            // append warning if beta or alpha.
80
            $isBeta = $information['is_beta'] ?? false;
81
            if (true === $isBeta) {
82
                $return = sprintf('%s %s', $return, trans('firefly.update_version_beta'));
0 ignored issues
show
Bug introduced by
It seems like trans('firefly.update_version_beta') can also be of type array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
                $return = sprintf('%s %s', $return, /** @scrutinizer ignore-type */ trans('firefly.update_version_beta'));
Loading history...
83
            }
84
85
            $isAlpha = $information['is_alpha'] ?? false;
86
            if (true === $isAlpha) {
87
                $return = sprintf('%s %s', $return, trans('firefly.update_version_alpha'));
88
            }
89
        }
90
91
        if (0 === $versionCheck) {
92
            $triggered = true;
93
            Log::debug('User is running current version.');
94
            // you are running the current version!
95
            $return = (string)trans('firefly.update_current_version_alert', ['version' => $current]);
96
        }
97
        if (1 === $versionCheck) {
98
            $triggered = true;
99
            Log::debug('User is running NEWER version.');
100
            // you are running a newer version!
101
            $return = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $information['version']]);
102
        }
103
        if (false === $triggered) {
104
            Log::debug('No option was triggered.');
105
            $return = (string)trans('firefly.update_check_error');
106
        }
107
108
        return $return;
109
    }
110
111
    /**
112
     * Compare version and store result.
113
     *
114
     * @param array $information
115
     *
116
     * @return int
117
     */
118
    public function versionCheck(array $information): int
119
    {
120
        Log::debug('Now in versionCheck()');
121
        $current = (string)config('firefly.version');
122
        $check   = version_compare($current, $information['version']);
123
        Log::debug(sprintf('Comparing %s with %s, result is %s', $current, $information['version'], $check), $information);
124
125
        return $check;
126
    }
127
}
128