ServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 44
c 0
b 0
f 0
rs 10
ccs 22
cts 22
cp 1
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A listenMailHooks() 0 4 1
A registerRoutes() 0 4 2
A boot() 0 14 2
A registerMigrations() 0 4 2
1
<?php
2
3
namespace NotificationTracker;
4
5
use Illuminate\Mail\Events\MessageSending;
6
use Illuminate\Mail\Events\MessageSent;
7
use Illuminate\Support\Facades\Event;
8
use NotificationTracker\Mail\MailTracker;
9
10
class ServiceProvider extends \Illuminate\Support\ServiceProvider
11
{
12 14
    public function boot()
13
    {
14 14
        $this->registerRoutes();
15 14
        $this->listenMailHooks();
16
17 14
        if ($this->app->runningInConsole()) {
18 14
            $this->registerMigrations();
19
20 14
            $this->publishes([
21 14
                __DIR__.'/../config/notification-tracker.php' => config_path('notification-tracker.php'),
22 14
            ], 'config');
23
24
25 14
            $this->commands([
26 14
                // TODO: add truncate
27 14
            ]);
28
        }
29
    }
30
31 14
    public function register()
32
    {
33 14
        $this->mergeConfigFrom(__DIR__.'/../config/notification-tracker.php', 'notification-tracker');
34
    }
35
36 14
    protected function registerMigrations()
37
    {
38 14
        if (NotificationTracker::$runsMigrations) {
39 14
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
40
        }
41
    }
42
43 14
    protected function registerRoutes()
44
    {
45 14
        if (NotificationTracker::$registersRoutes) {
46 14
            $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
47
        }
48
    }
49
50 14
    protected function listenMailHooks()
51
    {
52 14
        Event::listen(MessageSending::class, fn (MessageSending $event) => MailTracker::make()->onSending($event));
53 14
        Event::listen(MessageSent::class, fn (MessageSent $event) => MailTracker::make()->onSent($event));
54
    }
55
}
56