TelescopeServiceProvider::gate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Modules\Telescope\Providers;
4
5
use Foundation\Contracts\ConditionalAutoRegistration;
6
use Illuminate\Support\Facades\Gate;
7
use Laravel\Telescope\EntryType;
8
use Laravel\Telescope\IncomingEntry;
9
use Laravel\Telescope\Telescope;
10
use Laravel\Telescope\TelescopeApplicationServiceProvider;
11
12
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider implements ConditionalAutoRegistration
13
{
14
    /**
15
     * Register any application services.
16
     *
17
     * @return void
18
     */
19
    public function register()
20
    {
21
        $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
22
23
        //Telescope::night();
24
25
        Telescope::filter(function (IncomingEntry $entry) {
26
            if (is_bool($filter = $this->filterHorizonEntries($entry))) {
27
                return $filter;
28
            }
29
30
            if (is_bool($filter = $this->filterCorsRequests($entry))) {
31
                return $filter;
32
            }
33
34
            if ($this->app->environment('local')) {
35
                return true;
36
            }
37
38
            return $entry->isReportableException() ||
39
                $entry->isFailedJob() ||
40
                $entry->isScheduledTask() ||
41
                $entry->hasMonitoredTag();
42
        });
43
    }
44
45
    protected function filterHorizonEntries(IncomingEntry $entry)
46
    {
47
        if ($entry->type === EntryType::REQUEST
48
            && isset($entry->content['uri'])
49
            && str_contains($entry->content['uri'], 'horizon')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated: Str::contains() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
            && /** @scrutinizer ignore-deprecated */ str_contains($entry->content['uri'], 'horizon')) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
50
            return false;
51
        }
52
53
        if ($entry->type === EntryType::EVENT
54
            && isset($entry->content['name'])
55
            && str_contains($entry->content['name'], 'Horizon')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated: Str::contains() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

55
            && /** @scrutinizer ignore-deprecated */ str_contains($entry->content['name'], 'Horizon')) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
56
            return false;
57
        }
58
    }
59
60
    protected function filterCorsRequests(IncomingEntry $entry)
61
    {
62
        if ($entry->type === EntryType::REQUEST
63
            && isset($entry->content['method'])
64
            && $entry->content['method'] === 'OPTIONS') {
65
            return false;
66
        }
67
    }
68
69
    /**
70
     * Register the Telescope gate.
71
     *
72
     * This gate determines who can access Telescope in non-local environments.
73
     *
74
     * @return void
75
     */
76
    protected function gate()
77
    {
78
        Gate::define('viewTelescope', function ($user) {
79
            return in_array($user->email, [
80
                //
81
            ]);
82
        });
83
    }
84
85 43
    public function registrationCondition(): bool
86
    {
87 43
        return app()->environment('local');
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
        return app()->/** @scrutinizer ignore-call */ environment('local');
Loading history...
88
    }
89
}
90