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 — master ( a70b7c...7d482a )
by James
21:49 queued 11:38
created

app/Handlers/Events/VersionCheckEventHandler.php (2 issues)

1
<?php
2
/**
3
 * VersionCheckEventHandler.php
4
 * Copyright (c) 2017 [email protected]
5
 *
6
 * This file is part of Firefly III.
7
 *
8
 * Firefly III is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Firefly III 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 General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
/** @noinspection MultipleReturnStatementsInspection */
22
/** @noinspection NullPointerExceptionInspection */
23
declare(strict_types=1);
24
25
namespace FireflyIII\Handlers\Events;
26
27
28
use FireflyConfig;
29
use FireflyIII\Events\RequestedVersionCheckStatus;
30
use FireflyIII\Helpers\Update\UpdateTrait;
31
use FireflyIII\Models\Configuration;
32
use FireflyIII\Repositories\User\UserRepositoryInterface;
33
use FireflyIII\User;
34
use Log;
35
36
37
/**
38
 * Class VersionCheckEventHandler
39
 */
40
class VersionCheckEventHandler
41
{
42
    use UpdateTrait;
43
44
    /**
45
     * Checks with GitHub to see if there is a new version.
46
     *
47
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
48
     * @SuppressWarnings(PHPMD.NPathComplexity)
49
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
50
     * @param RequestedVersionCheckStatus $event
51
     */
52
    public function checkForUpdates(RequestedVersionCheckStatus $event): void
53
    {
54
        Log::debug('Now in checkForUpdates()');
55
        // in Sandstorm, cannot check for updates:
56
        $sandstorm = 1 === (int)getenv('SANDSTORM');
57
        if (true === $sandstorm) {
58
            Log::debug('This is Sandstorm instance, done.');
59
60
            return;
61
        }
62
63
        /** @var UserRepositoryInterface $repository */
64
        $repository = app(UserRepositoryInterface::class);
65
        /** @var User $user */
66
        $user = $event->user;
67
        if (!$repository->hasRole($user, 'owner')) {
68
            Log::debug('User is not admin, done.');
69
70
            return;
71
        }
72
73
        /** @var Configuration $lastCheckTime */
74
        $lastCheckTime = FireflyConfig::get('last_update_check', time());
0 ignored issues
show
Bug Best Practice introduced by
The method FireflyIII\Support\Facades\FireflyConfig::get() is not static, but was called statically. ( Ignorable by Annotation )

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

74
        /** @scrutinizer ignore-call */ 
75
        $lastCheckTime = FireflyConfig::get('last_update_check', time());
Loading history...
75
        $now           = time();
76
        $diff          = $now - $lastCheckTime->data;
77
        Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
78
        if ($diff < 604800) {
79
            Log::debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));
80
81
            return;
82
        }
83
        // last check time was more than a week ago.
84
        Log::debug('Have not checked for a new version in a week!');
85
86
        $latestRelease = $this->getLatestRelease();
87
        $versionCheck  = $this->versionCheck($latestRelease);
88
        $resultString  = $this->parseResult($versionCheck, $latestRelease);
89
        if (0 !== $versionCheck && '' !== $resultString) {
90
            // flash info
91
            session()->flash('info', $resultString);
92
        }
93
        FireflyConfig::set('last_update_check', time());
0 ignored issues
show
Bug Best Practice introduced by
The method FireflyIII\Support\Facades\FireflyConfig::set() is not static, but was called statically. ( Ignorable by Annotation )

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

93
        FireflyConfig::/** @scrutinizer ignore-call */ 
94
                       set('last_update_check', time());
Loading history...
94
    }
95
}
96