TelescopeServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 72
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 19 5
A hideSensitiveRequestDetails() 0 16 2
A gate() 0 15 1
1
<?php
2
3
namespace Audit\Providers;
4
5
use Laravel\Telescope\Telescope;
6
use Illuminate\Support\Facades\Gate;
7
use Laravel\Telescope\IncomingEntry;
8
use Laravel\Telescope\TelescopeApplicationServiceProvider;
9
10
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
11
{
12
    /**
13
     * Register any application services.
14
     *
15
     * @return void
16
     */
17
    public function register()
18
    {
19
        // Telescope::night();
20
21
        $this->hideSensitiveRequestDetails();
22
23
        Telescope::filter(
24
            function (IncomingEntry $entry) {
25
                if ($this->app->isLocal()) {
26
                    return true;
27
                }
28
29
                return $entry->isReportableException() ||
30
                   $entry->isFailedJob() ||
31
                   $entry->isScheduledTask() ||
32
                   $entry->hasMonitoredTag();
33
            }
34
        );
35
    }
36
37
    /**
38
     * Prevent sensitive request details from being logged by Telescope.
39
     *
40
     * @return void
41
     */
42
    protected function hideSensitiveRequestDetails()
43
    {
44
        if ($this->app->isLocal()) {
45
            return;
46
        }
47
48
        Telescope::hideRequestParameters(['_token']);
49
50
        Telescope::hideRequestHeaders(
51
            [
52
            'cookie',
53
            'x-csrf-token',
54
            'x-xsrf-token',
55
            ]
56
        );
57
    }
58
59
    /**
60
     * Register the Telescope gate.
61
     *
62
     * This gate determines who can access Telescope in non-local environments.
63
     *
64
     * @return void
65
     */
66
    protected function gate()
67
    {
68
        Gate::define(
69
            'viewTelescope', function ($user) {
70
                return in_array(
71
                    $user->email, [
72
                    '[email protected]',
73
                    '[email protected]',
74
                    '[email protected]',
75
                    '[email protected]',
76
                    ]
77
                );
78
            }
79
        );
80
    }
81
}
82