Completed
Push — master ( 87f5e0...117349 )
by Benjamin
05:50
created

AbTestingServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 43
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 23 2
A register() 0 10 1
1
<?php
2
3
namespace Ben182\AbTesting;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Blade;
7
use Illuminate\Support\ServiceProvider;
8
use Ben182\AbTesting\Commands\FlushCommand;
9
use Ben182\AbTesting\Commands\ReportCommand;
10
11
class AbTestingServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot()
17
    {
18
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__.'/../config/config.php' => config_path('ab-testing.php'),
23
            ], 'config');
24
25
            $this->commands([
26
                ReportCommand::class,
27
                FlushCommand::class,
28
            ]);
29
        }
30
31
        Request::macro('abExperiment', function () {
32
            return app(AbTesting::class)->getExperiment();
33
        });
34
35
        Blade::if('abExperiment', function ($experiment) {
36
            return app(AbTesting::class)->isExperiment($experiment);
37
        });
38
    }
39
40
    /**
41
     * Register the application services.
42
     */
43
    public function register()
44
    {
45
        // Automatically apply the package configuration
46
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'ab-testing');
47
48
        // Register the main class to use with the facade
49
        $this->app->singleton('ab-testing', function () {
50
            return new AbTesting;
51
        });
52
    }
53
}
54