TrackingServiceProvider::boot()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 38
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 21
c 3
b 0
f 0
nc 16
nop 0
dl 0
loc 38
rs 9.2728
1
<?php
2
3
namespace Sfneal\Tracking\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Sfneal\Tracking\Console\CleanDevTrackingCommand;
7
8
class TrackingServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap any Tracking services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        // Publish config file (before migrations in case config values are used in migrations)
18
        $this->publishes([
19
            __DIR__.'/../../config/tracking.php' => config_path('tracking.php'),
20
        ], 'config');
21
22
        // `TrackActivity` migration file
23
        if (! class_exists('CreateTrackActionTable')) {
24
            $this->publishes([
25
                __DIR__.'/../../database/migrations/create_track_action_table.php.stub' => database_path(
26
                    'migrations/'.date('Y_m_d_His', time()).'_create_track_action_table.php'
27
                ),
28
            ], 'migration');
29
        }
30
31
        // `TrackAction` migration file
32
        if (! class_exists('CreateTrackActivityTable')) {
33
            $this->publishes([
34
                __DIR__.'/../../database/migrations/create_track_activity_table.php.stub' => database_path(
35
                    'migrations/'.date('Y_m_d_His', time()).'_create_track_activity_table.php'
36
                ),
37
            ], 'migration');
38
        }
39
40
        // `TrackTraffic` migration file
41
        if (! class_exists('CreateTrackTrafficTable')) {
42
            $this->publishes([
43
                __DIR__.'/../../database/migrations/create_track_traffic_table.php.stub' => database_path(
44
                    'migrations/'.date('Y_m_d_His', time()).'_create_track_traffic_table.php'
45
                ),
46
            ], 'migration');
47
        }
48
49
        // Publish the `CleanDevTrackingCommand`
50
        if ($this->app->runningInConsole()) {
51
            $this->commands([
52
                CleanDevTrackingCommand::class,
53
            ]);
54
        }
55
    }
56
57
    /**
58
     * Register any Tracking services.
59
     *
60
     * @return void
61
     */
62
    public function register()
63
    {
64
        // Load config file
65
        $this->mergeConfigFrom(__DIR__.'/../../config/tracking.php', 'tracking');
66
67
        // Register Event ServiceProvider
68
        $this->app->register(TrackingEventServiceProvider::class);
69
    }
70
}
71