Passed
Push — 5.0.0 ( 9d1037...fbd7bb )
by Fèvre
05:16
created

TelescopeServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 50
rs 10
c 1
b 0
f 0
wmc 9

3 Methods

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