TrackingServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 65
rs 10
c 2
b 1
f 0
ccs 29
cts 29
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerFactory() 0 13 1
A registerTrackers() 0 10 1
A boot() 0 14 1
1
<?php
2
3
namespace BoxedCode\Tracking;
4
5
use BoxedCode\Tracking\Trackers\PixelTracker;
6
use BoxedCode\Tracking\Trackers\RedirectTracker;
7
use Illuminate\Routing\Router;
8
use Illuminate\Support\ServiceProvider;
9
10
class TrackingServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register the service provider.
14
     *
15
     * @return void
16
     */
17 38
    public function register()
18
    {
19 38
        $this->registerTrackers();
20
21 38
        $this->registerFactory();
22 38
    }
23
24
    /**
25
     * Register the factory.
26
     */
27 38
    protected function registerFactory()
28
    {
29
        $this->app->singleton(TrackerFactory::class, function ($app) {
30
            $trackers = [
31 2
                PixelTracker::class,
32 2
                RedirectTracker::class,
33 2
            ];
34
35 2
            return new TrackerFactory($app, $trackers);
36 38
        });
37
38 38
        $this->app->alias(TrackerFactory::class, 'tracking');
39 38
    }
40
41
    /**
42
     * Register the trackers.
43
     */
44 38
    protected function registerTrackers()
45
    {
46
        $this->app->bind(PixelTracker::class, function ($app) {
47 38
            return new PixelTracker($app, $app['events'], $app['config']);
48 38
        });
49
50 38
        $this->app->bind(RedirectTracker::class, function ($app) {
51 38
            return new RedirectTracker($app, $app['events'], $app['config']);
52 38
        });
53 38
    }
54
55
    /**
56
     * Register the trackers routes and published package assets.
57
     *
58
     * @param \Illuminate\Routing\Router $router
59
     */
60 38
    public function boot(Router $router)
61
    {
62 38
        $this->app[PixelTracker::class]->registerRoute($router);
63
64 38
        $this->app[RedirectTracker::class]->registerRoute($router);
65
66 38
        $this->publishes([
67 38
            realpath(__DIR__.'/../../../migrations/') => database_path('migrations'),
68 38
        ], 'migrations');
69
70 38
        $this->publishes([
71 38
            realpath(__DIR__.'/../../../config/') => config_path(),
72 38
        ], 'config');
73 38
    }
74
}
75