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.

Authorised   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
eloc 36
c 3
b 0
f 0
dl 0
loc 80
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configurationCheck() 0 6 2
A databaseConnectionCheck() 0 17 2
A handle() 0 31 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Protoqol\Prequel\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Support\Facades\DB;
9
10
/**
11
 * Class Authorised
12
 *
13
 * @package Protoqol\Prequel\Http\Middleware
14
 */
15
class Authorised
16
{
17
18
    /**
19
     * Handle an incoming request.
20
     * Checks if Prequel is enabled and has a valid database connection.
21
     *
22
     * @param  \Illuminate\Http\Request  $request
23
     * @param  \Closure  $next
24
     *
25
     * @return mixed
26
     */
27
    public function handle($request, Closure $next)
28
    {
29
        if (!$this->configurationCheck()->enabled) {
30
            return view('Prequel::error', [
31
                'error_detailed' => $this->configurationCheck()->detailed,
32
                'http_code'      => 403,
33
                'env'            => [
34
                    'connection' => 'protected',
35
                    'database'   => 'protected',
36
                    'host'       => 'protected',
37
                    'port'       => 'protected',
38
                    'user'       => 'protected',
39
                ],
40
            ]);
41
        }
42
43
        if (!$this->databaseConnectionCheck()->connected) {
44
            return view('Prequel::error', [
45
                'error_detailed' => $this->databaseConnectionCheck()->detailed,
46
                'http_code'      => 503,
47
                'env'            => [
48
                    'connection' => config('app.default'),
49
                    'database'   => config('app.mysql.database'),
50
                    'host'       => config('app.mysql.host'),
51
                    'port'       => config('app.mysql.port'),
52
                    'user'       => config('app.mysql.user'),
53
                ],
54
            ]);
55
        }
56
57
        return $next($request);
58
    }
59
60
    /**
61
     * Check connection with database
62
     *
63
     * @return object
64
     */
65
    private function databaseConnectionCheck()
66
    {
67
        $connection = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $connection is dead and can be removed.
Loading history...
68
69
        try {
70
            $connection = [
71
                'connected' => (bool) DB::connection()->getPdo(),
72
                'detailed'  => DB::connection()->getPdo(),
73
            ];
74
        } catch (\Exception $exception) {
75
            $connection = [
76
                'connected' => false,
77
                'detailed'  => 'No valid database connection',
78
            ];
79
        }
80
81
        return (object) $connection;
82
    }
83
84
    /**
85
     * Check if Prequel is enabled and/or in development
86
     *
87
     * @return object
88
     */
89
    private function configurationCheck()
90
    {
91
        return (object) [
92
            'enabled'  => (config('prequel.enabled')
93
                && config('app.env') !== 'production'),
94
            'detailed' => 'Prequel has been disabled.',
95
        ];
96
    }
97
}
98