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.
Completed
Push — master ( 869845...9ac565 )
by James
08:24 queued 03:31
created

HomeController::displayDebug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * HomeController.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
22
declare(strict_types=1);
23
24
namespace FireflyIII\Http\Controllers;
25
26
use Artisan;
27
use Carbon\Carbon;
28
use DB;
29
use FireflyIII\Exceptions\FireflyException;
30
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
31
use FireflyIII\Models\AccountType;
32
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
33
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
34
use Illuminate\Http\Request;
35
use Illuminate\Routing\Route;
36
use Illuminate\Support\Collection;
37
use Log;
38
use Preferences;
39
use Route as RouteFacade;
40
use Session;
41
use View;
42
43
/**
44
 * Class HomeController
45
 *
46
 * @package FireflyIII\Http\Controllers
47
 */
48
class HomeController extends Controller
49
{
50
    /**
51
     * HomeController constructor.
52
     */
53
    public function __construct()
54
    {
55
        parent::__construct();
56
        View::share('title', 'Firefly III');
57
        View::share('mainTitleIcon', 'fa-fire');
58
    }
59
60
    /**
61
     * @param Request $request
62
     */
63
    public function dateRange(Request $request)
64
    {
65
66
        $start         = new Carbon($request->get('start'));
67
        $end           = new Carbon($request->get('end'));
68
        $label         = $request->get('label');
69
        $isCustomRange = false;
70
71
        Log::debug('Received dateRange', ['start' => $request->get('start'), 'end' => $request->get('end'), 'label' => $request->get('label')]);
72
73
        // check if the label is "everything" or "Custom range" which will betray
74
        // a possible problem with the budgets.
75
        if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
76
            $isCustomRange = true;
77
            Log::debug('Range is now marked as "custom".');
78
        }
79
80
        $diff = $start->diffInDays($end);
81
82
        if ($diff > 50) {
83
            Session::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));
84
        }
85
86
        Session::put('is_custom_range', $isCustomRange);
87
        Session::put('start', $start);
88
        Session::put('end', $end);
89
    }
90
91
    public function displayDebug()
92
    {
93
        $phpVersion = PHP_VERSION;
94
        $now        = Carbon::create()->format('Y-m-d H:i:s e');
95
        $extensions = join(', ', get_loaded_extensions());
96
        $drivers    = join(', ', DB::availableDrivers());
97
        $currentDriver = DB::getDriverName();
98
99
        return view('debug', compact('phpVersion', 'extensions', 'carbon', 'now', 'drivers','currentDriver'));
100
101
    }
102
103
    /**
104
     * @throws FireflyException
105
     */
106
    public function displayError()
107
    {
108
        Log::debug('This is a test message at the DEBUG level.');
109
        Log::info('This is a test message at the INFO level.');
110
        Log::notice('This is a test message at the NOTICE level.');
111
        Log::warning('This is a test message at the WARNING level.');
112
        Log::error('This is a test message at the ERROR level.');
113
        Log::critical('This is a test message at the CRITICAL level.');
114
        Log::alert('This is a test message at the ALERT level.');
115
        Log::emergency('This is a test message at the EMERGENCY level.');
116
        throw new FireflyException('A very simple test error.');
117
    }
118
119
    /**
120
     * @param Request $request
121
     *
122
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
123
     */
124
    public function flush(Request $request)
125
    {
126
        Preferences::mark();
127
        $request->session()->forget(['start', 'end', '_previous', 'viewRange', 'range', 'is_custom_range']);
128
        Artisan::call('cache:clear');
129
130
        return redirect(route('index'));
131
    }
132
133
    /**
134
     * @param AccountRepositoryInterface $repository
135
     *
136
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
137
     */
138
    public function index(AccountRepositoryInterface $repository)
139
    {
140
        $types = config('firefly.accountTypesByIdentifier.asset');
141
        $count = $repository->count($types);
142
143
        if ($count === 0) {
144
            return redirect(route('new-user.index'));
145
        }
146
147
        $subTitle     = trans('firefly.welcomeBack');
148
        $transactions = [];
149
        $frontPage    = Preferences::get(
150
            'frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()
151
        );
152
        /** @var Carbon $start */
153
        $start = session('start', Carbon::now()->startOfMonth());
154
        /** @var Carbon $end */
155
        $end      = session('end', Carbon::now()->endOfMonth());
156
        $accounts = $repository->getAccountsById($frontPage->data);
157
        $showDeps = Preferences::get('showDepositsFrontpage', false)->data;
158
159
        // zero bills? Hide some elements from view.
160
        /** @var BillRepositoryInterface $billRepository */
161
        $billRepository = app(BillRepositoryInterface::class);
162
        $billCount      = $billRepository->getBills()->count();
163
164
165
        foreach ($accounts as $account) {
166
            $collector = app(JournalCollectorInterface::class);
167
            $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1);
168
            $set            = $collector->getJournals();
169
            $transactions[] = [$set, $account];
170
        }
171
172
        return view(
173
            'index', compact('count', 'subTitle', 'transactions', 'showDeps', 'billCount')
174
        );
175
    }
176
177
    public function routes()
178
    {
179
        $set    = RouteFacade::getRoutes();
180
        $ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.', 'attachments.download', 'attachments.preview',
181
                   'bills.rescan', 'budgets.income', 'currencies.def', 'error', 'flush', 'help.show', 'import.file',
182
                   'login', 'logout', 'password.reset', 'profile.confirm-email-change', 'profile.undo-email-change',
183
                   'register', 'report.options', 'routes', 'rule-groups.down', 'rule-groups.up', 'rules.up', 'rules.down',
184
                   'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
185
                   'two-factor.lost', 'report.options',
186
187
        ];
188
189
        /** @var Route $route */
190
        foreach ($set as $route) {
191
            $name = $route->getName();
192
            if (!is_null($name) && in_array('GET', $route->methods()) && strlen($name) > 0) {
193
                $found = false;
194
                foreach ($ignore as $string) {
195
                    if (strpos($name, $string) !== false) {
196
                        $found = true;
197
                    }
198
                }
199
                if (!$found) {
200
                    echo 'touch ' . $route->getName() . '.md;';
201
                }
202
203
            }
204
        }
205
206
        return '&nbsp;';
207
    }
208
209
    /**
210
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
211
     */
212
    public function testFlash()
213
    {
214
        Session::flash('success', 'This is a success message.');
215
        Session::flash('info', 'This is an info message.');
216
        Session::flash('warning', 'This is a warning.');
217
        Session::flash('error', 'This is an error!');
218
219
        return redirect(route('home'));
220
    }
221
222
}
223