TelescopePruningServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
eloc 17
c 5
b 0
f 1
dl 0
loc 54
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 3
A registerCommands() 0 3 1
A register() 0 5 1
A registerPublishing() 0 5 1
1
<?php
2
3
namespace Insense\LaravelTelescopePruning;
4
5
use Illuminate\Support\ServiceProvider;
6
use Laravel\Telescope\Telescope;
7
use Insense\LaravelTelescopePruning\Commands\TrimCommand;
8
9
class TelescopePruningServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap any application services.
13
     */
14
    public function boot()
15
    {
16
        if ($this->app->runningInConsole()) {
17
            $this->registerPublishing();
18
            $this->registerCommands();
19
            return;
20
        }
21
        
22
        if($this->app->config->get('telescope-pruning.every_request_pruning', true)) {
23
            $this->app->terminating(function () {
24
                Telescope::withoutRecording(function() {
25
                    (new PruneEntries($this->app))->prune();
26
                });
27
            });            
28
        }
29
    }
30
31
    /**
32
     * Register any application services.
33
     */
34
    public function register()
35
    {
36
        $this->mergeConfigFrom(
37
            __DIR__.'/../config/telescope-pruning.php',
38
            'telescope-pruning'
39
        );
40
    
41
    }
42
43
    /**
44
     * Register the package's publishable resources.
45
     *
46
     * @return void
47
     */
48
    protected function registerPublishing()
49
    {
50
        $this->publishes([
51
            __DIR__ . '/../config/telescope-pruning.php' => config_path('telescope-pruning.php'),
52
        ], 'telescope-pruning-config');
53
    }
54
    
55
    /**
56
     * Register the package's commands.
57
     *
58
     * @return void
59
     */
60
    protected function registerCommands() {
61
        $this->commands([
62
            TrimCommand::class,
63
        ]); 
64
    }
65
}
66