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 ( 49de82...9f1fc0 )
by James
35:45 queued 23:44
created

Range::loseItAll()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Range.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
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
31
/**
32
 * Class SessionFilter.
33
 */
34
class Range
35
{
36
    /**
37
     * Handle an incoming request.
38
     *
39
     * @param \Illuminate\Http\Request $request
40
     * @param Closure                  $next
41
     *
42
     * @return mixed
43
     */
44
    public function handle(Request $request, Closure $next)
45
    {
46
        if ($request->user()) {
47
            // set start, end and finish:
48
            $this->setRange();
49
50
            // set view variables.
51
            $this->configureView();
52
53
            // set more view variables:
54
            $this->configureList();
55
56
        }
57
58
        return $next($request);
59
    }
60
61
    /**
62
     * Configure the list length.
63
     */
64
    private function configureList(): void
65
    {
66
        $pref = app('preferences')->get('list-length', config('firefly.list_length', 10))->data;
67
        app('view')->share('listLength', $pref);
68
    }
69
70
    /**
71
     * Configure the user's view.
72
     */
73
    private function configureView(): void
74
    {
75
        $pref = app('preferences')->get('language', config('firefly.default_language', 'en_US'));
76
        /** @noinspection NullPointerExceptionInspection */
77
        $lang = $pref->data;
78
        App::setLocale($lang);
79
        Carbon::setLocale(substr($lang, 0, 2));
80
        $locale = explode(',', (string)trans('config.locale'));
81
        $locale = array_map('trim', $locale);
82
83
        setlocale(LC_TIME, $locale);
84
        $moneyResult = setlocale(LC_MONETARY, $locale);
85
86
        // send error to view if could not set money format
87
        if (false === $moneyResult) {
88
            app('view')->share('invalidMonetaryLocale', true); // @codeCoverageIgnore
89
        }
90
91
        // save some formats:
92
        $monthAndDayFormat = (string)trans('config.month_and_day');
93
        $dateTimeFormat    = (string)trans('config.date_time');
94
        $defaultCurrency   = app('amount')->getDefaultCurrency();
95
96
        // also format for moment JS:
97
        $madMomentJS = (string)trans('config.month_and_day_moment_js');
98
99
        app('view')->share('madMomentJS', $madMomentJS);
100
        app('view')->share('monthAndDayFormat', $monthAndDayFormat);
101
        app('view')->share('dateTimeFormat', $dateTimeFormat);
102
        app('view')->share('defaultCurrency', $defaultCurrency);
103
    }
104
105
    /**
106
     * Set the range for the current view.
107
     */
108
    private function setRange(): void
109
    {
110
        // ignore preference. set the range to be the current month:
111
        if (!app('session')->has('start') && !app('session')->has('end')) {
112
            $viewRange = app('preferences')->get('viewRange', '1M')->data;
113
            $start     = app('navigation')->updateStartDate($viewRange, new Carbon);
114
            $end       = app('navigation')->updateEndDate($viewRange, $start);
115
116
            app('session')->put('start', $start);
117
            app('session')->put('end', $end);
118
        }
119
        if (!app('session')->has('first')) {
120
            /** @var JournalRepositoryInterface $repository */
121
            $repository = app(JournalRepositoryInterface::class);
122
            $journal    = $repository->firstNull();
123
            $first      = Carbon::now()->startOfYear();
124
125
            if (null !== $journal) {
126
                $first = $journal->date ?? $first;
127
            }
128
            app('session')->put('first', $first);
129
        }
130
    }
131
}
132