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 ( 37b02e...ebbbe1 )
by James
08:59
created

app/Http/Middleware/Range.php (1 issue)

Severity
1
<?php
2
/**
3
 * Range.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
declare(strict_types=1);
22
23
namespace FireflyIII\Http\Middleware;
24
25
use App;
26
use Carbon\Carbon;
27
use Closure;
28
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
29
use Illuminate\Http\Request;
30
use Preferences;
31
use Session;
32
use View;
33
34
/**
35
 * Class SessionFilter.
36
 */
37
class Range
38
{
39
    /**
40
     * Handle an incoming request.
41
     *
42
     * @param \Illuminate\Http\Request $request
43
     * @param Closure                  $next
44
     *
45
     * @return mixed
46
     */
47
    public function handle(Request $request, Closure $next)
48
    {
49
        if ($request->user()) {
50
            // set start, end and finish:
51
            $this->setRange();
52
53
            // set view variables.
54
            $this->configureView();
55
56
            // set more view variables:
57
            $this->configureList();
58
        }
59
60
        return $next($request);
61
    }
62
63
    /**
64
     *
65
     */
66
    private function configureList()
67
    {
68
        $pref = Preferences::get('list-length', config('firefly.list_length', 10))->data;
69
        View::share('listLength', $pref);
70
    }
71
72
    /**
73
     *
74
     */
75
    private function configureView()
76
    {
77
        $pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
78
        $lang = $pref->data;
79
        App::setLocale($lang);
80
        Carbon::setLocale(substr($lang, 0, 2));
81
        $locale = explode(',', trans('config.locale'));
82
        $locale = array_map('trim', $locale);
83
84
        setlocale(LC_TIME, $locale);
85
        $moneyResult = setlocale(LC_MONETARY, $locale);
86
87
        // send error to view if could not set money format
88
        if (false === $moneyResult) {
89
            View::share('invalidMonetaryLocale', true); // @codeCoverageIgnore
90
        }
91
92
        // save some formats:
93
        $monthAndDayFormat = (string)trans('config.month_and_day');
94
        $dateTimeFormat    = (string)trans('config.date_time');
95
        $defaultCurrency   = app('amount')->getDefaultCurrency();
96
97
        View::share('monthAndDayFormat', $monthAndDayFormat);
98
        View::share('dateTimeFormat', $dateTimeFormat);
99
        View::share('defaultCurrency', $defaultCurrency);
100
    }
101
102
    /**
103
     *
104
     */
105
    private function setRange()
106
    {
107
        // ignore preference. set the range to be the current month:
108
        if (!Session::has('start') && !Session::has('end')) {
109
            $viewRange = Preferences::get('viewRange', '1M')->data;
110
            $start     = new Carbon;
111
            $start     = app('navigation')->updateStartDate($viewRange, $start);
112
            $end       = app('navigation')->updateEndDate($viewRange, $start);
113
114
            Session::put('start', $start);
115
            Session::put('end', $end);
116
        }
117
        if (!Session::has('first')) {
118
            /** @var JournalRepositoryInterface $repository */
119
            $repository = app(JournalRepositoryInterface::class);
120
            $journal    = $repository->first();
0 ignored issues
show
Deprecated Code introduced by
The function FireflyIII\Repositories\...itoryInterface::first() has been deprecated. ( Ignorable by Annotation )

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

120
            $journal    = /** @scrutinizer ignore-deprecated */ $repository->first();
Loading history...
121
            $first      = Carbon::now()->startOfYear();
122
123
            if (null !== $journal->id) {
124
                $first = $journal->date;
125
            }
126
            Session::put('first', $first);
127
        }
128
    }
129
}
130