CookieConsentServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 24 2
A register() 0 11 2
1
<?php
2
3
namespace DigiFactory\CookieConsent;
4
5
use DigiFactory\CookieConsent\Contracts\ConsentProvider;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\Facades\Blade;
8
use Illuminate\Support\ServiceProvider;
9
10
class CookieConsentServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15
    public function boot()
16
    {
17
        Blade::if('cookieConsentNecessary', function () {
18
            return app('cookie-consent')->forNecessary();
19
        });
20
21
        Blade::if('cookieConsentPreferences', function () {
22
            return app('cookie-consent')->forPreferences();
23
        });
24
25
        Blade::if('cookieConsentStatistics', function () {
26
            return app('cookie-consent')->forStatistics();
27
        });
28
29
        Blade::if('cookieConsentMarketing', function () {
30
            return app('cookie-consent')->forMarketing();
31
        });
32
33
        if ($this->app->runningInConsole()) {
34
            $this->publishes([
35
                __DIR__.'/../config/config.php' => config_path('cookie-consent.php'),
36
            ], 'config');
37
        }
38
    }
39
40
    /**
41
     * Register the application services.
42
     */
43
    public function register()
44
    {
45
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'cookie-consent');
46
47
        if ($this->app instanceof Application) {
48
            $config = $this->app->config['cookie-consent'];
49
50
            $this->app->singleton(ConsentProvider::class, $config['provider']);
51
            $this->app->bind('cookie-consent', CookieConsent::class);
52
        }
53
    }
54
}
55